[SOLVED] How to read the ID number?. REG [UID]

FRANCISCOGIMENO
Wed Nov 29, 2017 3:56 pm
Hi, who knows how to read the fixed serial number of the chip?

a greeting


mrburnette
Wed Nov 29, 2017 4:54 pm
OK …. good members use Google first. Like this:
UID site:stm32duino.com

The above results in: viewtopic.php?t=245

Ray


FRANCISCOGIMENO
Wed Nov 29, 2017 5:01 pm
Thank you and sorry,

I had searched by putting the name of the record and nothing appeared with direct relationship.

Thank you


dannyf
Wed Nov 29, 2017 6:33 pm
Very simple.

1. Read the datasheet – this is always going to be your first step.

2. Find out where the uid is located, as their location is family specific.

3. Fix a data type of your choice to that address.

4. Done.


HutTheNut
Wed Mar 28, 2018 10:42 pm
Hi everyone,

I’ve done some of the work for the Nucleo boards – Feel free to update the example below based upon Roger’s input from:
viewtopic.php?t=245

Best regards,
Frank

// STM32L476
// http://www.st.com/content/ccc/resource/technical/document/reference_manual/02/35/09/0c/4f/f7/40/03/DM00083560.pdf/files/DM00083560.pdf/jcr:content/translations/en.DM00083560.pdf
// STM32L432
// http://www.st.com/content/ccc/resource/technical/document/reference_manual/group0/b0/ac/3e/8f/6d/21/47/af/DM00151940/files/DM00151940.pdf/jcr:content/translations/en.DM00151940.pdf
// STM32F446
// http://www.st.com/content/ccc/resource/technical/document/reference_manual/4d/ed/bc/89/b5/70/40/dc/DM00135183.pdf/files/DM00135183.pdf/jcr:content/translations/en.DM00135183.pdf
// STM32F303
// http://www.st.com/content/ccc/resource/technical/document/reference_manual/4a/19/6e/18/9d/92/43/32/DM00043574.pdf/files/DM00043574.pdf/jcr:content/translations/en.DM00043574.pdf

uint16_t flashsize;
uint32_t UnitID_Part_1;
uint32_t UnitID_Part_2;
uint32_t UnitID_Part_3;

void setup() {

Serial.begin(115200);

#if defined(ARDUINO_NUCLEO_F303K8)

// UID for F3 devices in general as I google the info
flashSize = *(uint16_t *)(0x1FFFF7CC);
UnitID_Part_1 = *(uint32_t*)(0x1FFFF7AC);
UnitID_Part_2 = *(uint32_t*)(0x1FFFF7AC+0x04);
UnitID_Part_3 = *(uint32_t*)(0x1FFFF7AC+0x08);

#elif defined(ARDUINO_NUCLEO_F446RE)

// UID for F4 devices in general as I google the info
flashSize = *(uint16_t *)(0x1FFF7A22);
UnitID_Part_1 = *(uint32_t*)(0x1FFF7A10);
UnitID_Part_2 = *(uint32_t*)(0x1FFF7A10+0x04);
UnitID_Part_3 = *(uint32_t*)(0x1FFF7A10+0x08);

#elif defined(ARDUINO_NUCLEO_L432KC) || defined(ARDUINO_NUCLEO_L476RG)

// UID for L4 devices in general as I google the info
flashsize = *(uint16_t *)(0x1FFF75E0);
UnitID_Part_1 = *(uint32_t*)(0x1FFF7590);
UnitID_Part_2 = *(uint32_t*)(0x1FFF7590+0x04);
UnitID_Part_3 = *(uint32_t*)(0x1FFF7590+0x08);

#else
#error "No board recognized"

#endif;

}

void loop() {

Serial.print("Flash size is ");
Serial.print(flashsize );
Serial.println(" kB");
Serial.print("UID [HEX] : ");
Serial.print(UnitID_Part_1, HEX);
Serial.print(" ");
Serial.print(UnitID_Part_2, HEX);
Serial.print(" ");
Serial.println(UnitID_Part_3, HEX);

delay(1000);
}


fpiSTM
Thu Mar 29, 2018 6:21 pm
Just a tips about STM core, you can uses CMSIS definitions to be more generic and avoid usage of switch for each board:

ex for STM32F103:
https://github.com/stm32duino/Arduino_C … 3xb.h#L674
#define FLASHSIZE_BASE 0x1FFFF7E0U /*!< FLASH Size register base address */
#define UID_BASE 0x1FFFF7E8U /*!< Unique device ID register base address */


HutTheNut
Fri Mar 30, 2018 5:44 pm
As I read the link, the addresses are not generic and for the STM32F1xx only…

/Frank


fpiSTM
Fri Mar 30, 2018 6:31 pm
[HutTheNut – Fri Mar 30, 2018 5:44 pm] –
As I read the link, the addresses are not generic and for the STM32F1xx only…

/Frank

Those defines are generic not its value and for all STM32YYxx families.


HutTheNut
Fri Mar 30, 2018 10:47 pm
Exactly..

But coming from my lack of knowledge.. In order to avoid usage of switch for each board.
How do I access these #defines through compilation assuming I don’t know where to look in the register as the following example does in my search for a generic piece of code..?

#if defined(ARDUINO_NUCLEO_F103CB) || defined(ARDUINO_NUCLEO_F103C8) // Add more F1-board if necessary

// UID for F1 devices in general as I google the info
#define FLASHSIZE_BASE 0x1FFFF7E0U // FLASH Size register base address
#define UID_BASE 0x1FFFF7E8U // Unique device ID register base address

#endif;


fpiSTM
Sat Mar 31, 2018 6:39 am
With STM Core, no specific include to do, only use the definition in the sketch. CMSIS headers are already included.

HutTheNut
Sat Mar 31, 2018 5:09 pm
Hi all,

There is the final code-contribution for now.. I hope it will come in handy for some – And feel free to improve it! :-)


// STM32L476
// http://www.st.com/content/ccc/resource/technical/document/reference_manual/02/35/09/0c/4f/f7/40/03/DM00083560.pdf/files/DM00083560.pdf/jcr:content/translations/en.DM00083560.pdf
// STM32L432
// http://www.st.com/content/ccc/resource/technical/document/reference_manual/group0/b0/ac/3e/8f/6d/21/47/af/DM00151940/files/DM00151940.pdf/jcr:content/translations/en.DM00151940.pdf
// STM32F446
// http://www.st.com/content/ccc/resource/technical/document/reference_manual/4d/ed/bc/89/b5/70/40/dc/DM00135183.pdf/files/DM00135183.pdf/jcr:content/translations/en.DM00135183.pdf
// STM32F303
// http://www.st.com/content/ccc/resource/technical/document/reference_manual/4a/19/6e/18/9d/92/43/32/DM00043574.pdf/files/DM00043574.pdf/jcr:content/translations/en.DM00043574.pdf
// STM32F1
// https://github.com/stm32duino/Arduino_Core_STM32/blob/af3d2e7fcd1ae9b5eaa56b22aca6e148e40fda69/system/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xb.h#L674

uint16_t flashsize;
uint32_t UnitID_Part_1;
uint32_t UnitID_Part_2;
uint32_t UnitID_Part_3;
String UnitName;

// System clock speed
extern uint32_t SystemCoreClock;

void setup() {

Serial.begin(115200);

Serial.println("");
Serial.println("Serial communication is running OK");
Serial.println("");
Serial.println("Compiled : " __DATE__ ", " __TIME__);
Serial.println("Version : " __VERSION__);
Serial.println("");

//Reading type of board
#if defined(ARDUINO_NUCLEO_F103C8)
UnitName = "NUCLEO_F103C8";

#elif defined(ARDUINO_NUCLEO_F103CB)
UnitName = "NUCLEO_F103CB";

#elif defined(ARDUINO_NUCLEO_F103CB)
UnitName = "NUCLEO_F103RB";

#elif defined(ARDUINO_NUCLEO_F303K8)
UnitName = "NUCLEO_F303K8";

#elif defined(ARDUINO_NUCLEO_L432KC)
UnitName = "NUCLEO_L432KC";

#elif defined(ARDUINO_NUCLEO_L476RG)
UnitName = "NUCLEO_L476RG";

#elif defined(ARDUINO_NUCLEO_F446RE)
UnitName = "NUCLEO_F446RE";

#else
#error "No board recognized"
UnitName = "No board recognized";
#endif

// Reading Flashsize and Unit ID
#if defined(ARDUINO_NUCLEO_F103CB) || defined(ARDUINO_NUCLEO_F103CB)

// UID for F1 devices in general as I google the info
#define FLASHSIZE_BASE 0x1FFFF7E0U // FLASH Size register base address
#define UID_BASE 0x1FFFF7E8U // Unique device ID register base address

#elif defined(ARDUINO_NUCLEO_F303K8) // Add more F3-board if necessary

// UID for F3 devices in general as I google the info
#define FLASHSIZE_BASE 0x1FFFF7CC // FLASH Size register base address
#define UID_BASE 0x1FFFF7AC // Unique device ID register base address

#elif defined(ARDUINO_NUCLEO_F446RE) // Add more F4-board if necessary

// UID for F4 devices in general as I google the info
#define FLASHSIZE_BASE 0x1FFF7A22 // FLASH Size register base address
#define UID_BASE 0x1FFF7A10 // Unique device ID register base address

#elif defined(ARDUINO_NUCLEO_L432KC) || defined(ARDUINO_NUCLEO_L476RG) // Add more L4-board if necessary

// UID for L4 devices in general as I google the info
#define FLASHSIZE_BASE 0x1FFF75E0 // FLASH Size register base address
#define UID_BASE 0x1FFF7590 // Unique device ID register base address

#endif;

flashsize = *(uint16_t *)(FLASHSIZE_BASE);
UnitID_Part_1 = *(uint32_t*)(UID_BASE);
UnitID_Part_2 = *(uint32_t*)(UID_BASE+0x04);
UnitID_Part_3 = *(uint32_t*)(UID_BASE+0x08);

// Board type, UnitID and flashsize
Serial.println("Board : "+UnitName);
Serial.println("CPU speed : "+String(SystemCoreClock/1000000)+" MHz");
Serial.println("Flash size : "+String(flashsize)+" kB");
Serial.println("UID [HEX] : "+String(UnitID_Part_1, HEX)+" "+String(UnitID_Part_2, HEX)+" "+String(UnitID_Part_3, HEX));
Serial.println("");

delay(2000);

Serial.println("Press A for Board type");
Serial.println("Press B for CPU speed");
Serial.println("Press C for flash size");
Serial.println("Press D for UID");
Serial.println("");
}

void loop() {

if(Serial.available()) {
char inChar = (char)Serial.read();
switch (inChar){
case 'A': Serial.println("Press A for Board type"); break;
case 'B': Serial.println("CPU speed : "+String(SystemCoreClock/1000000)+" MHz"); break;
case 'C': Serial.println("Flash size : "+String(flashsize)+" kB"); break;
case 'D': Serial.println("UID [HEX] : "+String(UnitID_Part_1, HEX)+" "+String(UnitID_Part_2, HEX)+" "+String(UnitID_Part_3, HEX)); break;
}//End_Switch
}//End_If

}//End loop


fpiSTM
Sat Mar 31, 2018 6:31 pm
Note that on core using CMSIS, like STM core, you redefined CMSIS define: UID_BASE and FLASHSIZE_BASE.

To be more generic with board name, I’ve added a define to recipe.cpp.o.pattern in platform.txt after -DARDUINO_{build.board}


HutTheNut
Sat Mar 31, 2018 9:35 pm
Now I see what you have been trying to tell me for the last couple of days. :-)

I thought that I had to make the #defines myself at the top of the script with the ecaxt same names : UID_BASE and FLASHSIZE_BASE.. And trying that, I’ve got errors. And that’s why I kept the “board-case”. But still, thanks for being patience with me.

However the board is not recognized – do you have any idea way that is..?

UID_almost_perfect.PNG
Almost perfect
UID_almost_perfect.PNG (84.66 KiB) Viewed 1164 times

fpiSTM
Sat Mar 31, 2018 10:16 pm
In fact, BOARDNAME is currently not defined in platform.txt. I’ve added it manually in platform.txt in order to have it directly. I think I will add it to platform.txt. This could be useful.
https://github.com/stm32duino/Arduino_C … m.txt#L101

HutTheNut
Sat Mar 31, 2018 10:52 pm
Line 101 has been updated – Thanks fpiSTM, it works! :-)

/Frank


HutTheNut
Sun Apr 01, 2018 3:56 pm
Btw.
Is there way of reading the usages of Flash and SRAM from sketch..?


Sketch uses 59564 bytes (5%) of program storage space. Maximum is 1048576 bytes.
Global variables use 2748 bytes (2%) of dynamic memory, leaving 95556 bytes for local variables. Maximum is 98304 bytes.
C: – paht removed by author
1 File(s) copied
Upload complete on DIS_L4IOT (E:)

Thanks in advance
Frank


fpiSTM
Mon Apr 02, 2018 6:51 am
You should open an other topic. This one is solved and this is a new question

HutTheNut
Sun Apr 08, 2018 5:33 pm
New topic generated:
viewtopic.php?f=29&t=3470

I’ve been searching through the site for a couple of days now, but I don’t seem to have luck.. Can you recall the link for this question..?


HutTheNut
Wed Oct 24, 2018 12:12 am
Hi everyone,

The “BOARDNAME” in this thread aka -DBOARDNAME=”{build.board}” in the platform.txt file has been changes to -DBOARD_NAME=”{build.board}”.
So in order for the code to work, just change the name : BOARDNAME to BOARD_NAME

Br.
HTN


fpiSTM
Wed Oct 24, 2018 5:56 am
Yes this is BOARD_NAME but it does not change:
https://github.com/stm32duino/Arduino_C … 9575fbe31d

Leave a Reply

Your email address will not be published. Required fields are marked *