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 4060cc14c8..ad088d5b61 100644 --- a/core/embed/io/rgb_led/stm32u5/rgb_led_lp.c +++ b/core/embed/io/rgb_led/stm32u5/rgb_led_lp.c @@ -25,6 +25,8 @@ #include +#include "sys/systick.h" + #define LED_SWITCHING_FREQUENCY_HZ 20000 #define TIMER_PERIOD (16000000 / LED_SWITCHING_FREQUENCY_HZ) @@ -64,12 +66,16 @@ void rgb_led_init(void) { rgb_led_set_default_pin_state(); - // enable LSE clock - RCC_OscInitTypeDef RCC_OscInitStruct = {0}; - RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; - RCC_OscInitStruct.HSIState = RCC_HSI_ON; - RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; - HAL_RCC_OscConfig(&RCC_OscInitStruct); + 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 LSE as LPTIM clock source RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0}; diff --git a/core/embed/sec/secure_aes/stm32u5/secure_aes.c b/core/embed/sec/secure_aes/stm32u5/secure_aes.c index 313a795f80..0074c62521 100644 --- a/core/embed/sec/secure_aes/stm32u5/secure_aes.c +++ b/core/embed/sec/secure_aes/stm32u5/secure_aes.c @@ -26,6 +26,7 @@ #include #include +#include #if NORCOW_MIN_VERSION <= 5 #include "secure_aes_unpriv.h" @@ -221,13 +222,16 @@ secbool secure_aes_ecb_decrypt_hw(const uint8_t* input, size_t size, } secbool secure_aes_init(void) { - RCC_OscInitTypeDef osc_init_def = {0}; - osc_init_def.OscillatorType = RCC_OSCILLATORTYPE_SHSI; - osc_init_def.SHSIState = RCC_SHSI_ON; - // Enable SHSI clock - if (HAL_RCC_OscConfig(&osc_init_def) != HAL_OK) { - goto cleanup; + __HAL_RCC_SHSI_ENABLE(); + + uint32_t deadline = ticks_timeout(HSI_TIMEOUT_VALUE); + + // Wait till SHSI is ready + while (READ_BIT(RCC->CR, RCC_CR_SHSIRDY) == 0U) { + if (ticks_expired(deadline)) { + goto cleanup; + } } // Enable SAES peripheral clock @@ -247,12 +251,17 @@ void secure_aes_deinit(void) { __HAL_RCC_SAES_FORCE_RESET(); __HAL_RCC_SAES_RELEASE_RESET(); - RCC_OscInitTypeDef osc_init_def = {0}; - osc_init_def.OscillatorType = RCC_OSCILLATORTYPE_SHSI; - osc_init_def.SHSIState = RCC_SHSI_OFF; + // Disable the Secure Internal High Speed oscillator (SHSI) + __HAL_RCC_SHSI_DISABLE(); - // Disable SHSI clock - HAL_RCC_OscConfig(&osc_init_def); + uint32_t deadline = ticks_timeout(2); + + // Wait till SHSI is off + while (READ_BIT(RCC->CR, RCC_CR_SHSIRDY) != 0U) { + if (ticks_expired(deadline)) { + return; + } + } } #endif // SECURE_MODE