Skip to content

Commit cc4c5ca

Browse files
committed
STM32 MCUs
Add support to STM32 microcontroller based on the Arduino Core STM32 board manager.
1 parent 951495c commit cc4c5ca

File tree

4 files changed

+33
-6
lines changed

4 files changed

+33
-6
lines changed

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# ArduinoUniqueID
22

3-
This Library gets the Unique ID / Manufacture Serial Number from the Atmel AVR, SAM, SAMD, and ESP Microcontroller.
3+
This Library gets the Unique ID / Manufacture Serial Number from the Atmel AVR, SAM, SAMD, STM32, and ESP Microcontroller.
44

55
# Atmel AVR Microcontroller
66

@@ -61,6 +61,17 @@ The uniqueness of the serial number is guaranteed only when using all 128 bits.
6161

6262
* Atmel SAMD21 ARM Cortex-M0 - 16 bytes
6363

64+
# STM32 Microcontroller
65+
66+
STM32 32-bit Arm Cortex MCUs has a unique 96-bit serial number which is a concatenation of three 32-bit words, the address is different depending on the microcontroller.
67+
68+
The [Arduino Core STM32](https://github.com/stm32duino/Arduino_Core_STM32) has the variable UID_BASE whos contain the first 32-bit word of the serial number.
69+
70+
## Tested Microcontroller
71+
72+
* STM32F103C8 (BluePill Board) - 12 bytes
73+
* STM32L073RZ (Nucleo L073RZ) - 12 bytes
74+
6475
# Espressif ESP Microcontroller
6576

6677
ESP microcontroller has basically two versions, ESP8266 and ESP32, each one has a specific function to request the chip id. <br/>

library.properties

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
name=ArduinoUniqueID
2-
version=1.0.7
2+
version=1.0.8
33
author=Luiz Henrique Cassettari
44
maintainer=Luiz Henrique Cassettari <ricaun@gmail.com>
5-
sentence=Arduino Library to gets the Manufacture Serial Number from the Atmel AVR, SAM, SAMD, and ESP Microcontroller.
6-
paragraph=The ArduinoUniqueID Library use the buildin feature to select the manufacture serial number from the microcontroler. Suported microcontroler: Atmega328pb, Atmega328p, Atmega2560, Attiny85, SAM3X8E, SAMD21, ESP8266 & ESP32.
5+
sentence=Arduino Library to gets the Manufacture Serial Number from the Atmel AVR, SAM, SAMD, STM32, and ESP Microcontroller.
6+
paragraph=The ArduinoUniqueID Library use the buildin feature to select the manufacture serial number from the microcontroler. Suported microcontroler: Atmega328pb, Atmega328p, Atmega2560, Attiny85, SAM3X8E, SAMD21, STM32, ESP8266 & ESP32.
77
category=Other
88
url=https://github.com/ricaun/ArduinoUniqueID
9-
architectures=avr, esp8266, esp32, sam, samd
9+
architectures=avr, esp8266, esp32, sam, samd, stm32
1010
includes=ArduinoUniqueID.h

src/ArduinoUniqueID.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,18 @@ ArduinoUniqueID::ArduinoUniqueID()
8888
id[i*4+3] = (uint8_t)(pdwUniqueID[i] >> 0);
8989
}
9090

91+
#elif defined(ARDUINO_ARCH_STM32)
92+
uint32_t pdwUniqueID[3];
93+
pdwUniqueID[2] = *(uint32_t *)(UID_BASE + 0);
94+
pdwUniqueID[1] = *(uint32_t *)(UID_BASE + 4);
95+
pdwUniqueID[0] = *(uint32_t *)(UID_BASE + 8);
96+
for (int i = 0; i < 3; i++)
97+
{
98+
id[i*4+3] = (uint8_t)(pdwUniqueID[i] >> 24);
99+
id[i*4+2] = (uint8_t)(pdwUniqueID[i] >> 16);
100+
id[i*4+1] = (uint8_t)(pdwUniqueID[i] >> 8);
101+
id[i*4+0] = (uint8_t)(pdwUniqueID[i] >> 0);
102+
}
91103
#endif
92104
}
93105

src/ArduinoUniqueID.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
#elif defined(ARDUINO_ARCH_ESP32)
1616
#elif defined(ARDUINO_ARCH_SAM)
1717
#elif defined(ARDUINO_ARCH_SAMD)
18+
#elif defined(ARDUINO_ARCH_STM32)
1819
#else
19-
#error "ArduinoUniqueID only works on AVR, SAM, SAMD and ESP Architecture"
20+
#error "ArduinoUniqueID only works on AVR, SAM, SAMD, STM32 and ESP Architecture"
2021
#endif
2122

2223
#if defined(ARDUINO_ARCH_AVR)
@@ -41,6 +42,9 @@
4142
#elif defined(ARDUINO_ARCH_SAMD)
4243
#define UniqueIDsize 16
4344
#define UniqueIDbuffer 16
45+
#elif defined(ARDUINO_ARCH_STM32)
46+
#define UniqueIDsize 12
47+
#define UniqueIDbuffer 12
4448
#endif
4549

4650
#define UniqueID8 (_UniqueID.id + UniqueIDbuffer - 8)

0 commit comments

Comments
 (0)