Skip to main content
Explorer
November 27, 2023
Solved

RNG does not work after waking up from the stop mode

  • November 27, 2023
  • 1 reply
  • 1905 views

Hello,

My MCU is STM32L053R8

I use freeRTOS project generated by CubeMX.

The problem is happening only  when I enable tickless sleep. I get only one correct reading, which is probably generated right after MX_RNG_Init. Then after the sleep, I always get `LL_RNG_IsActiveFlag_CECS(RNG) == 1`

I call `LL_RNG_Enable(RNG)` and `LL_RNG_Disable(RNG)` before and after `LL_RNG_ReadRandData32()`

 

It looks like HSI does not start after the sleep. In the documentation I found that it is indeed deactivated if there is no periphery connected which can run in stop mode. But I did not find, how it should be started properly.

    This topic has been closed for replies.
    Best answer by TDK

    HSI can be enabled with:

    __HAL_RCC_HSI_ENABLE();

    1 reply

    TDKAnswer
    Super User
    November 27, 2023

    HSI can be enabled with:

    __HAL_RCC_HSI_ENABLE();
    Evgeny MAuthor
    Explorer
    November 28, 2023

    @TDK thanks for the hint. It was a bit more complicated. The configuration of PLL has to be also done again:

    	// make sure HSI is on
    	if (!LL_RCC_HSI_IsReady()) {
    		LL_RCC_HSI_Enable();
    
    		while(LL_RCC_HSI_IsReady() != 1)
    		{
    			
    		}
    		LL_RCC_HSI_SetCalibTrimming(16);
    	}
    
    	if (!LL_RCC_PLL_IsReady()) {
    		LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLL_MUL_3, LL_RCC_PLL_DIV_2);
    		LL_RCC_PLL_Enable();
    
    		while(LL_RCC_PLL_IsReady() != 1)
    		{
    			
    		}
    	}

    Now it works, thanks again!