Skip to content

Commit

Permalink
STM32 MCUs
Browse files Browse the repository at this point in the history
Add support to STM32 microcontroller based on the Arduino Core STM32 board manager.
  • Loading branch information
ricaun committed Jul 18, 2019
1 parent 951495c commit cc4c5ca
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ArduinoUniqueID

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

# Atmel AVR Microcontroller

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

* Atmel SAMD21 ARM Cortex-M0 - 16 bytes

# STM32 Microcontroller

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.

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.

## Tested Microcontroller

* STM32F103C8 (BluePill Board) - 12 bytes
* STM32L073RZ (Nucleo L073RZ) - 12 bytes

# Espressif ESP Microcontroller

ESP microcontroller has basically two versions, ESP8266 and ESP32, each one has a specific function to request the chip id. <br/>
Expand Down
8 changes: 4 additions & 4 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name=ArduinoUniqueID
version=1.0.7
version=1.0.8
author=Luiz Henrique Cassettari
maintainer=Luiz Henrique Cassettari <[email protected]>
sentence=Arduino Library to gets the Manufacture Serial Number from the Atmel AVR, SAM, SAMD, and ESP Microcontroller.
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.
sentence=Arduino Library to gets the Manufacture Serial Number from the Atmel AVR, SAM, SAMD, STM32, and ESP Microcontroller.
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.
category=Other
url=https://github.com/ricaun/ArduinoUniqueID
architectures=avr, esp8266, esp32, sam, samd
architectures=avr, esp8266, esp32, sam, samd, stm32
includes=ArduinoUniqueID.h
12 changes: 12 additions & 0 deletions src/ArduinoUniqueID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ ArduinoUniqueID::ArduinoUniqueID()
id[i*4+3] = (uint8_t)(pdwUniqueID[i] >> 0);
}

#elif defined(ARDUINO_ARCH_STM32)
uint32_t pdwUniqueID[3];
pdwUniqueID[2] = *(uint32_t *)(UID_BASE + 0);
pdwUniqueID[1] = *(uint32_t *)(UID_BASE + 4);
pdwUniqueID[0] = *(uint32_t *)(UID_BASE + 8);
for (int i = 0; i < 3; i++)
{
id[i*4+3] = (uint8_t)(pdwUniqueID[i] >> 24);
id[i*4+2] = (uint8_t)(pdwUniqueID[i] >> 16);
id[i*4+1] = (uint8_t)(pdwUniqueID[i] >> 8);
id[i*4+0] = (uint8_t)(pdwUniqueID[i] >> 0);
}
#endif
}

Expand Down
6 changes: 5 additions & 1 deletion src/ArduinoUniqueID.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
#elif defined(ARDUINO_ARCH_ESP32)
#elif defined(ARDUINO_ARCH_SAM)
#elif defined(ARDUINO_ARCH_SAMD)
#elif defined(ARDUINO_ARCH_STM32)
#else
#error "ArduinoUniqueID only works on AVR, SAM, SAMD and ESP Architecture"
#error "ArduinoUniqueID only works on AVR, SAM, SAMD, STM32 and ESP Architecture"
#endif

#if defined(ARDUINO_ARCH_AVR)
Expand All @@ -41,6 +42,9 @@
#elif defined(ARDUINO_ARCH_SAMD)
#define UniqueIDsize 16
#define UniqueIDbuffer 16
#elif defined(ARDUINO_ARCH_STM32)
#define UniqueIDsize 12
#define UniqueIDbuffer 12
#endif

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

0 comments on commit cc4c5ca

Please sign in to comment.