cancel
Showing results for 
Search instead for 
Did you mean: 

When I get connected and paired to peer HAL RNG doesn' work

DS.4
Senior II

Having issues generating random numbers while being connected via BLE.

In general use, HAL RNG works fine, and I get a random number without timeouts.

BUT,

Upon finishing the connection flow,

connection mtu exchange pairing ,

I start to get timeouts when trying to generate a new random number.

Increasing the timeout , initializing,  did not resolve the issue.

I am currently trying to use HCI_RND command instead in the hopes it will get me my random number.

If it helps, 

I am on one of the latest BLE stacks 1.20 or 1.21


Cheers,

and let us all have random numbers when connected!

1 ACCEPTED SOLUTION

Accepted Solutions

The HCI_LE_RAND can be used to request the controller to generate eight octets of random data to send to the host. You may call it to generate random data. the Random_Number is generated according to [Vol 2] Part H, Section 2. To be able to use it, the LE feature (LL encryption) should be supported. More details are available on the Bluetooth spec. v.6.0 [Vol 4, Part E, 7.8.23].

Best Regards.

STTwo-32

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

View solution in original post

3 REPLIES 3
STTwo-32
ST Employee

Hello @DS.4 

As soon as the CPU2 uses the RNG, it will switch OFF the RNG source clock when
done.

You need to re enable the clock each time you want to use the RNG.
Moreover, when you are done with RNG, you need to restore RNGSEL to CLK48 so that it is ready for BLE.

You can review Section 4.3 Fig 8 of AN5289 Rev 18 for a description about this. I tried this procedure when the device is in connected mode, and it works and allows me to use the RNG from CPU1. You may try this snippet code that was tested before by a colleague on a similar case:

 

 

while( LL_HSEM_1StepLock( HSEM, CFG_HW_RNG_SEMID ) ); //Poll Sem0 until granted
MX_RNG_Init(); //Configure and switch on RNG clock

/* Generate eight 32-bit long random numbers */
for (counter = 0; counter < 8; counter++)
{
if (HAL_RNG_GenerateRandomNumber(&hrng, &aRandom32bit[counter]) != HAL_OK) //RNG process
{
/* Random number generation error */
Error_Handler();
}
}

HAL_RNG_DeInit(&hrng); //Switch off RNG IP
__HAL_RCC_RNG_CLK_DISABLE(); //Switch off RNG clock

LL_HSEM_ReleaseLock( HSEM, CFG_HW_RNG_SEMID, 0 ); //Release Sem0

 

 

Best Regards.

STTwo-32

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

DS.4
Senior II

Should HCI_RND work out of the box? I may even ask Always?

 

I find it could be an easier solution in my case.

 

Thanks again

The HCI_LE_RAND can be used to request the controller to generate eight octets of random data to send to the host. You may call it to generate random data. the Random_Number is generated according to [Vol 2] Part H, Section 2. To be able to use it, the LE feature (LL encryption) should be supported. More details are available on the Bluetooth spec. v.6.0 [Vol 4, Part E, 7.8.23].

Best Regards.

STTwo-32

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.