Hi. I tried to get UID64 using the GetUniqueId Function from STM32WLXX code as mentioned below.
void GetUniqueId(uint8_t *id)
{
/* USER CODE BEGIN GetUniqueId_1 */
/* USER CODE END GetUniqueId_1 */
uint32_t val = 0;
val = LL_FLASH_GetUDN();
if (val == 0xFFFFFFFF) /* Normally this should not happen */
{
uint32_t ID_1_3_val = HAL_GetUIDw0() + HAL_GetUIDw2();
uint32_t ID_2_val = HAL_GetUIDw1();
id[7] = (ID_1_3_val) >> 24;
id[6] = (ID_1_3_val) >> 16;
id[5] = (ID_1_3_val) >> 8;
id[4] = (ID_1_3_val);
id[3] = (ID_2_val) >> 24;
id[2] = (ID_2_val) >> 16;
id[1] = (ID_2_val) >> 8;
id[0] = (ID_2_val);
}
else /* Typical use case */
{
id[7] = val & 0xFF;
id[6] = (val >> 8) & 0xFF;
id[5] = (val >> 16) & 0xFF;
id[4] = (val >> 24) & 0xFF;
val = LL_FLASH_GetDeviceID();
id[3] = val & 0xFF;
val = LL_FLASH_GetSTCompanyID();
id[2] = val & 0xFF;
id[1] = (val >> 8) & 0xFF;
id[0] = (val >> 16) & 0xFF;
}
}
But I still get the wrong DEVEUI. It seems, STM32 adds its own device ID and CompanyID to DEVEUI. as they mentioned in STM32WLxx reference manual (RM0461):
I am getting the same 0080E1 and device ID 15 in the DEVEUI as STM generates this code (hardcode). I am not getting what I get in the sticker. So I tried directly getting data without any hardcode of STM32 as below:
void GetUniqueId(uint8_t *id)
{
uint32_t ID_1_val = READ_REG(*((uint32_t *)UID64_BASE + 4U));
uint32_t ID_2_val = READ_REG(*((uint32_t *)UID64_BASE));
id[7] = (ID_1_val) >> 24;
id[6] = (ID_1_val) >> 16;
id[5] = (ID_1_val) >> 8;
id[4] = (ID_1_val);
id[3] = (ID_2_val) >> 24;
id[2] = (ID_2_val) >> 16;
id[1] = (ID_2_val) >> 8;
id[0] = (ID_2_val);
}
Still not getting it. Any advice? @carlrowan