2024-07-22 11:59 PM - edited 2024-07-23 12:00 AM
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.