Unique chip ID for RAK3172

Hello there…
It’s me again… Now I’m checking the possibility to develop my application in Arduino, with RUI3… but I got some trouble…
How can I get the uniqueID from the STM32WLE chip? like in cube IDE it’s done by GetUniqueID() function… I’ve tried the api.system.modelId.get() and api.system.chipId.get() but them return a string with module and chip PN…

RUI3 does not offer an API call to get the boards unique ID.

You can always use the HAL functions:

#include "stm32wlxx_hal.h"

void setup(void)
{
	// Start Serial
	Serial.begin(115200);

	// Delay for 5 seconds to give the chance for AT+BOOT
	delay(5000);

	uint32_t uid0, uid1, uid2;
	uid0 = HAL_GetUIDw0();
	uid1 = HAL_GetUIDw1();
	uid2 = HAL_GetUIDw2();
	Serial.printf("UID=%08x%08x%08x\r\n", uid2, uid1, uid0);
}
1 Like

Thanks bro, you rock!
You’ve opened my eyes, so I implemented the ST way to generate the UNIQUE ID…
follow the code to refer:

#include "stm32wlxx_hal.h"
#include "stm32wlxx_ll_system.h"

uint8_t uniqueId[8];

void setup(void) {
  // Start Serial
  Serial.begin(115200);

  // Delay for 5 seconds to give the chance for AT+BOOT
  delay(5000);
  
  GetUniqueId(uniqueId);

  Serial.printf("UID = :");
  for (int i = 0; i < 8; i++) Serial.printf("%02x\r", uniqueId[i]);
  Serial.printf("\n");
}

void loop() {}

void GetUniqueId(uint8_t *id) {
  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;
  }
}

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.