diff --git a/README.md b/README.md index 2ae59f4..0068ffe 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # ArduinoUniqueID -This Library gets the Unique Serial ID from the AVR Microcontroller and ESP Microcontroller. +This Library gets the Unique ID / Manufacture Serial Number from the Atmel AVR, SAM, SAMD, and ESP Microcontroller. # Atmel AVR Microcontroller @@ -33,13 +33,34 @@ Apparently, the chip Atmega328p have a hidden serial number with 9 bytes, and ot * Attiny85 - 9 bytes # Atmel SAM ARM Microcontroller -Atmel SAM3X8E is used in Arduino Due. The Unique Identifier is located in the first 128 bits of the Flash memory mapping. So, at the address 0x400000-0x400003. -"Each device integrates its own 128-bit unique identifier. These bits are factory configured and cannot be changed by the user. The ERASE pin has no effect on the unique identifier." (http://ww1.microchip.com/downloads/en/devicedoc/atmel-11057-32-bit-cortex-m3-microcontroller-sam3x-sam3a_datasheet.pdf) + +Atmel SAM3X8E is used in Arduino Due. + +The Unique Identifier is located in the first 128 bits of the Flash memory mapping. So, at the address 0x400000-0x400003. + +"Each device integrates its own 128-bit unique identifier. These bits are factory configured and cannot be changed by the user. The ERASE pin has no effect on the unique identifier." [Datasheet Section 7.2.3.7](http://ww1.microchip.com/downloads/en/devicedoc/atmel-11057-32-bit-cortex-m3-microcontroller-sam3x-sam3a_datasheet.pdf) ## Tested Microcontroller * Atmel SAM3X8E ARM Cortex-M3 - 16 bytes +# Atmel SAMD ARM Microcontroller + +Atmel SAMD21 is used in Arduino Zero / Arduino M0. + +Each device has a unique 128-bit serial number which is a concatenation of four 32-bit words contained at the following addresses: + +* Word 0: 0x0080A00C +* Word 1: 0x0080A040 +* Word 2: 0x0080A044 +* Word 3: 0x0080A048 + +The uniqueness of the serial number is guaranteed only when using all 128 bits. [Datasheet Section 9.3.3](https://cdn.sparkfun.com/datasheets/Dev/Arduino/Boards/Atmel-42181-SAM-D21_Datasheet.pdf) + +## Tested Microcontroller + +* Atmel SAMD21 ARM Cortex-M0 - 16 bytes + # Espressif ESP Microcontroller ESP microcontroller has basically two versions, ESP8266 and ESP32, each one has a specific function to request the chip id.
@@ -81,7 +102,7 @@ This library only supports AVR Microcontroller and ESP Microcontroller. ## Installation * Install the library by [Using the Library Manager](https://www.arduino.cc/en/Guide/Libraries#toc3) -* **OR** by [Importing the .zip library](https://www.arduino.cc/en/Guide/Libraries#toc4) using either the [master](https://github.com/ricaun/ArduinoUniqueID/archive/1.0.5.zip) or one of the [releases](https://github.com/ricaun/ArduinoUniqueID/releases) ZIP files. +* **OR** by [Importing the .zip library](https://www.arduino.cc/en/Guide/Libraries#toc4) using either the [master](https://github.com/ricaun/ArduinoUniqueID/archive/1.0.7.zip) or one of the [releases](https://github.com/ricaun/ArduinoUniqueID/releases) ZIP files. ## Examples diff --git a/examples/ArduinoUniqueIDSerialUSB/ArduinoUniqueIDSerialUSB.ino b/examples/ArduinoUniqueIDSerialUSB/ArduinoUniqueIDSerialUSB.ino new file mode 100644 index 0000000..3aaffe9 --- /dev/null +++ b/examples/ArduinoUniqueIDSerialUSB/ArduinoUniqueIDSerialUSB.ino @@ -0,0 +1,19 @@ +// +// ArduinoUniqueIDSerialUSB.ino +// +// Example shows the UniqueID on the SerialUSB Monitor. +// + +#include + +void setup() +{ + SerialUSB.begin(115200); + while (!SerialUSB); + UniqueIDdump(SerialUSB); + UniqueID8dump(SerialUSB); +} + +void loop() +{ +} \ No newline at end of file diff --git a/library.properties b/library.properties index ad09ce2..3395766 100644 --- a/library.properties +++ b/library.properties @@ -1,10 +1,10 @@ name=ArduinoUniqueID -version=1.0.6 +version=1.0.7 author=Luiz Henrique Cassettari maintainer=Luiz Henrique Cassettari -sentence=Arduino Library to get the AVR microcontroler Unique ID / Manufacture Serial Number. -paragraph=The ArduinoUniqueID Library use the buildin feature to select the manufacture serial number from the microcontroler. Suported microcontroler: Atmega328pb, Atmega328p, Atmega2560, Attiny85, SAM3X8E, ESP8266 & ESP32. +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. category=Other url=https://github.com/ricaun/ArduinoUniqueID -architectures=avr, esp8266, esp32, sam +architectures=avr, esp8266, esp32, sam, samd includes=ArduinoUniqueID.h diff --git a/src/ArduinoUniqueID.cpp b/src/ArduinoUniqueID.cpp index eb6b573..9598196 100644 --- a/src/ArduinoUniqueID.cpp +++ b/src/ArduinoUniqueID.cpp @@ -65,6 +65,29 @@ ArduinoUniqueID::ArduinoUniqueID() { status = EFC1->EEFC_FSR ; } while ( (status & EEFC_FSR_FRDY) != EEFC_FSR_FRDY ); + +#elif defined(ARDUINO_ARCH_SAMD) + + // from section 9.3.3 of the datasheet + #define SERIAL_NUMBER_WORD_0 *(volatile uint32_t*)(0x0080A00C) + #define SERIAL_NUMBER_WORD_1 *(volatile uint32_t*)(0x0080A040) + #define SERIAL_NUMBER_WORD_2 *(volatile uint32_t*)(0x0080A044) + #define SERIAL_NUMBER_WORD_3 *(volatile uint32_t*)(0x0080A048) + + uint32_t pdwUniqueID[4]; + pdwUniqueID[0] = SERIAL_NUMBER_WORD_0; + pdwUniqueID[1] = SERIAL_NUMBER_WORD_1; + pdwUniqueID[2] = SERIAL_NUMBER_WORD_2; + pdwUniqueID[3] = SERIAL_NUMBER_WORD_3; + + for (int i = 0; i < 4; i++) + { + id[i*4+0] = (uint8_t)(pdwUniqueID[i] >> 24); + id[i*4+1] = (uint8_t)(pdwUniqueID[i] >> 16); + id[i*4+2] = (uint8_t)(pdwUniqueID[i] >> 8); + id[i*4+3] = (uint8_t)(pdwUniqueID[i] >> 0); + } + #endif } diff --git a/src/ArduinoUniqueID.h b/src/ArduinoUniqueID.h index ce703ed..f63cc57 100644 --- a/src/ArduinoUniqueID.h +++ b/src/ArduinoUniqueID.h @@ -14,8 +14,9 @@ #elif defined(ARDUINO_ARCH_ESP8266) #elif defined(ARDUINO_ARCH_ESP32) #elif defined(ARDUINO_ARCH_SAM) +#elif defined(ARDUINO_ARCH_SAMD) #else -#error "ArduinoUniqueID only works on AVR, SAM and ESP Architecture" +#error "ArduinoUniqueID only works on AVR, SAM, SAMD and ESP Architecture" #endif #if defined(ARDUINO_ARCH_AVR) @@ -37,6 +38,9 @@ #elif defined(ARDUINO_ARCH_SAM) #define UniqueIDsize 16 #define UniqueIDbuffer 16 +#elif defined(ARDUINO_ARCH_SAMD) +#define UniqueIDsize 16 +#define UniqueIDbuffer 16 #endif #define UniqueID8 (_UniqueID.id + UniqueIDbuffer - 8)