Skip to main content
Associate II
July 23, 2024
Question

How to call Random Static Address in the past

  • July 23, 2024
  • 3 replies
  • 1452 views

Hello, 

I am developing a BLE HID device using the STM32WB55.

I am generating random static addresses using a program implemented in the STM32CubeWB. This is used to identify multiple peripherals with the same functionality.

 

#else
 /* Get RNG semaphore */
 while(LL_HSEM_1StepLock(HSEM, CFG_HW_RNG_SEMID));

 /* Enable RNG */
 __HAL_RNG_ENABLE(&hrng);

 /* Enable HSI48 oscillator */
 LL_RCC_HSI48_Enable();
 /* Wait until HSI48 is ready */
 while(! LL_RCC_HSI48_IsReady());

 if (HAL_RNG_GenerateRandomNumber(&hrng, &a_srd_bd_addr[1]) != HAL_OK)
 {
 /* Random number generation error */
 Error_Handler();
 }
 if (HAL_RNG_GenerateRandomNumber(&hrng, &a_srd_bd_addr[0]) != HAL_OK)
 {
 /* Random number generation error */
 Error_Handler();
 }
 a_srd_bd_addr[1] |= 0xC000; /* The two upper bits shall be set to 1 */

 /* Disable HSI48 oscillator */
 LL_RCC_HSI48_Disable();

 /* Disable RNG */
 __HAL_RNG_DISABLE(&hrng);

 /* Release RNG semaphore */
 LL_HSEM_ReleaseLock(HSEM, CFG_HW_RNG_SEMID, 0);
#endif /* CFG_STATIC_RANDOM_ADDRESS */


#if (CFG_BLE_ADDRESS_TYPE != GAP_PUBLIC_ADDR)
 ret = aci_hal_write_config_data(CONFIG_DATA_RANDOM_ADDRESS_OFFSET, CONFIG_DATA_RANDOM_ADDRESS_LEN, (uint8_t*)a_srd_bd_addr);
 if (ret != BLE_STATUS_SUCCESS)
 {
 APP_DBG_MSG(" Fail : aci_hal_write_config_data command - CONFIG_DATA_RANDOM_ADDRESS_OFFSET, result: 0x%x \n", ret);
 }
 else
 {
 APP_DBG_MSG(" Success: aci_hal_write_config_data command - CONFIG_DATA_RANDOM_ADDRESS_OFFSET\n");
 APP_DBG_MSG(" Random Bluetooth Address: %02x:%02x:%02x:%02x:%02x:%02x\n", (uint8_t)(a_srd_bd_addr[1] >> 8),
 (uint8_t)(a_srd_bd_addr[1]),
 (uint8_t)(a_srd_bd_addr[0] >> 24),
 (uint8_t)(a_srd_bd_addr[0] >> 16),
 (uint8_t)(a_srd_bd_addr[0] >> 8),
 (uint8_t)(a_srd_bd_addr[0]));
 }
#endif /* CFG_BLE_ADDRESS_TYPE != GAP_PUBLIC_ADDR */

 

 

Is there any way to restore the address generated here after a reset?

This is to perform a reconnection of the coupled device using ADV_DIRECT_IND with the restored random address.

I thought of saving it to NVM as a method, is it possible?

I would appreciate if you could answer me.

 

Best regards.

 

3 replies

TDK
Super User
July 23, 2024

If your intention is to generate a unique number to identify the device, I suggest using what's already onboard for that. The UID64 register value is guaranteed unique for each device.

TDK_0-1721738584615.png

 

Barring that, there certainly are ways to save information. Saving to a flash sector can work, as can saving to SRAM if power is not lost.

"If you feel a post has answered your question, please click ""Accept as Solution""."
ELEHMAuthor
Associate II
July 24, 2024

Hello. @TDK 

Thank you for your reply.

Thanks to you I have a better understanding of UID.

This time, however, I would like to add a process to change the random static address when a new connection is initiated after this (pressing the pairing button again during pairing).
Therefore, I don't think UID can be used only for identification (not sure if this is correct, sorry).

I'll think about how and when to save it to flash some more. Thanks.

Best regards.

 

 

 

 

STTwo-32
Technical Moderator
August 26, 2024

Hello @ELEHM 

Could you please give more details about your use case and what do you exactly want to change.

Best Regards.

STTwo-32

ELEHMAuthor
Associate II
September 24, 2024

Hello @STTwo-32 

Sorry for the late reply.
Here is what I would like to do

--------------------------------------------------------------------------------------------------------------------
1. save the address and key for encryption when connecting (even after power off).

2. after power is restored, try to connect to the original connection point with ADV_DIRECT_IND (if not possible, do nothing)

3. if the pairing button is pressed, a new address is generated and advertised with ADV_IND.

--------------------------------------------------------------------------------------------------------------------

Also, if you have multiple boards, you want to identify each board.

 

Best Regards.