cancel
Showing results for 
Search instead for 
Did you mean: 

Why am I getting an RNG failure on the STM32L4P5?

Rob.Riggs
Senior III

I have just updated a board design, replacing the STM32L433CC with an STM32L4P5RE. I have no problems using the RNG on the L433. However, with the L4P5, I get only one result from the RNG before it give a seed error.

RNG: CR = 00800004, DR = 9a4c8249, SR = 00000001

...

RNG: CR = 00800004, DR = 00000000, SR = 00000044

One thing I find odd is that I would expect the RNG to be able to provide 4 32-bit random values from DR if it worked once given that the RNG produces 128 bits of entropy at a time.

The clocking of the RNG is slightly different in the two boards. Both are clocked from PLLSAI1Q at 48MHz. The PLL is fed by the MSI on the 433 and from a HSE (TXCO) on the new board. The AHB is clocked at 80MHz on the L433 and 120MHz on the L4P5.

 PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_PLLSAI1;
 PeriphClkInit.RngClockSelection = RCC_RNGCLKSOURCE_PLLSAI1;
 PeriphClkInit.PLLSAI1.PLLSAI1Source = RCC_PLLSOURCE_HSE;

I tried changing the RNG clock source to the HSI48 and experienced the same problem,

I am only asking for 9600 bits of entropy per second.

I have routed SysClock out of MCO (/8) and verified that it is OK.

I am using STM32CubeIDE to generate the project, including the initialization code. I am not changing the configuration of the RNG from what the HAL has configured after calling MX_RNG_Init().

It should be noted that USB works perfectly fine and is clocked from the same source.

I have the same problem on two different boards, so this does not appear to be a random problem with a defective device.

Any suggestions on where to look?

1 ACCEPTED SOLUTION

Accepted Solutions
TZARDI
Associate III

​Hello Rob,

In  RM0432 page 1088 you can find the right configuration for the RNG registers. 0693W00000AMk8FQAT.jpg When writing the HTCR register the magic number 0x17590ABC must be written immediately before the indicated value.

This is an example of the RNG config with Config A:

#define RNG_MAGIC_NUMBER       0x17590ABC  /* Magic Number */ 
#define RNG_HTCR_VAL           0x0000AA74  /* HTCR Value */ 
__IO uint32_t  HTCR_VALUE=0; 
//put this after the RNG initializition and before the infinite loop
RNG->CR = 0x40F00D40; // config A 
HAL_Delay(20);
/* RNG HTCR value setting 0xAA74 */
/*!< magic number must be written immediately before to RNG_HTCRG */
 RNG->HTCR = RNG_MAGIC_NUMBER;
 RNG->HTCR = RNG_HTCR_VAL;
 HTCR_VALUE = 0 ; 
 RNG->HTCR = RNG_MAGIC_NUMBER;
 HTCR_VALUE = RNG->HTCR;
 RNG->HTCR = RNG_MAGIC_NUMBER;
 while ( HTCR_VALUE != RNG_HTCR_VAL); // check that HTCR value is correctly set
 RNG->CR = 0x00F00D4C; // config A + RNG EN =1, IE=1
 HAL_Delay(1); /* a delay to wait for CONDRST to take effect */
 

Best regards,

View solution in original post

3 REPLIES 3
TZARDI
Associate III

​Hello Rob,

In  RM0432 page 1088 you can find the right configuration for the RNG registers. 0693W00000AMk8FQAT.jpg When writing the HTCR register the magic number 0x17590ABC must be written immediately before the indicated value.

This is an example of the RNG config with Config A:

#define RNG_MAGIC_NUMBER       0x17590ABC  /* Magic Number */ 
#define RNG_HTCR_VAL           0x0000AA74  /* HTCR Value */ 
__IO uint32_t  HTCR_VALUE=0; 
//put this after the RNG initializition and before the infinite loop
RNG->CR = 0x40F00D40; // config A 
HAL_Delay(20);
/* RNG HTCR value setting 0xAA74 */
/*!< magic number must be written immediately before to RNG_HTCRG */
 RNG->HTCR = RNG_MAGIC_NUMBER;
 RNG->HTCR = RNG_HTCR_VAL;
 HTCR_VALUE = 0 ; 
 RNG->HTCR = RNG_MAGIC_NUMBER;
 HTCR_VALUE = RNG->HTCR;
 RNG->HTCR = RNG_MAGIC_NUMBER;
 while ( HTCR_VALUE != RNG_HTCR_VAL); // check that HTCR value is correctly set
 RNG->CR = 0x00F00D4C; // config A + RNG EN =1, IE=1
 HAL_Delay(1); /* a delay to wait for CONDRST to take effect */
 

Best regards,

Rob.Riggs
Senior III

I saw that in the reference manual. This indicates that there is a problem with the HAL. Can I expect that this will be addressed in a future release?

TZARDI
Associate III

​Hello,

Yes, it will be corrected in the future.

Br,