refactor(core): move HSI initialization to sysmon
What changed, and why it matters
This commit is a code cleanup: it moves the initialization of the HSI (High-Speed Internal) clock from the RGB LED driver into the system startup code. The change removes a duplicate HSI startup block and stops the system from turning HSI off after switching to the external HSE clock. There is no indication this is a security fix or introduces a security vulnerability.
No security action required. Treat as normal firmware maintenance/refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors STM32U5 clock setup. Previously rgb_led_init() enabled HSI and waited for it to be ready before selecting it as the LPTIM clock source. Now HSI is enabled once in SystemInit() before the HSE/PLL setup, and the #ifndef HSI_ONLY path no longer disables HSI after enabling CSS. The RGB LED driver now only configures LPTIM clock muxes assuming HSI is already on. The change also fixes a minor bug in the old HSI_ONLY wait loop which checked RCC_CR_HSION instead of RCC_CR_HSIRDY.
Changed components
core/embed/io/rgb_led/stm32u5/rgb_led_lp.ccore/embed/sys/startup/stm32u5/startup_init.cInspect captured patch +5 / −22
diff --git a/core/embed/io/rgb_led/stm32u5/rgb_led_lp.c b/core/embed/io/rgb_led/stm32u5/rgb_led_lp.c
index d4f1e755b..748324492 100644
--- a/core/embed/io/rgb_led/stm32u5/rgb_led_lp.c
+++ b/core/embed/io/rgb_led/stm32u5/rgb_led_lp.c
@@ -53,17 +53,6 @@ void rgb_led_init(void) {
rgb_led_set_default_pin_state();
- uint32_t deadline = ticks_timeout(HSI_TIMEOUT_VALUE);
-
- // enable HSI clock
- RCC->CR |= RCC_CR_HSION;
- // wait until the HSI is on
- while ((RCC->CR & RCC_CR_HSIRDY) != RCC_CR_HSIRDY) {
- if (ticks_expired(deadline)) {
- return;
- }
- }
-
// select HSI as LPTIM clock source
__HAL_RCC_LPTIM1_CONFIG(RCC_LPTIM1CLKSOURCE_HSI);
__HAL_RCC_LPTIM34_CONFIG(RCC_LPTIM34CLKSOURCE_HSI);
diff --git a/core/embed/sys/startup/stm32u5/startup_init.c b/core/embed/sys/startup/stm32u5/startup_init.c
index 232738ae3..6e94a2c93 100644
--- a/core/embed/sys/startup/stm32u5/startup_init.c
+++ b/core/embed/sys/startup/stm32u5/startup_init.c
@@ -203,6 +203,11 @@ void SystemInit(void) {
while (HAL_IS_BIT_CLR(PWR->SVMSR, PWR_SVMSR_ACTVOSRDY))
;
+ RCC->CR |= RCC_CR_HSION;
+ // wait until the HSI is on
+ while ((RCC->CR & RCC_CR_HSIRDY) != RCC_CR_HSIRDY)
+ ;
+
#ifndef HSI_ONLY
__HAL_RCC_HSE_CONFIG(RCC_HSE_ON);
while (READ_BIT(RCC->CR, RCC_CR_HSERDY) == 0U)
@@ -210,10 +215,6 @@ void SystemInit(void) {
__HAL_RCC_PLL_CONFIG(RCC_PLLSOURCE_HSE, RCC_PLLMBOOST_DIV1, DEFAULT_PLLM,
DEFAULT_PLLN, DEFAULT_PLLP, DEFAULT_PLLQ, DEFAULT_PLLR);
#else
- RCC->CR |= RCC_CR_HSION;
- // wait until the HSI is on
- while ((RCC->CR & RCC_CR_HSION) != RCC_CR_HSION)
- ;
__HAL_RCC_PLL_CONFIG(RCC_PLLSOURCE_HSI, RCC_PLLMBOOST_DIV1, DEFAULT_PLLM,
DEFAULT_PLLN, DEFAULT_PLLP, DEFAULT_PLLQ, DEFAULT_PLLR);
@@ -283,13 +284,6 @@ void SystemInit(void) {
#ifndef HSI_ONLY
// enable clock security system
RCC->CR |= RCC_CR_CSSON;
-
- // turn off the HSI as it is now unused (it will be turned on again
- // automatically if a clock security failure occurs)
- RCC->CR &= ~RCC_CR_HSION;
- // wait until the HSI is off
- while ((RCC->CR & RCC_CR_HSION) == RCC_CR_HSION)
- ;
#endif
// TODO turn off MSI?
Why this scored 12/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.