Skip to content

Commit

Permalink
Support Atmel SAMD21 (Arduino Zero)
Browse files Browse the repository at this point in the history
Add Support Atmel SAMD21 (Arduino Zero)
Add Example to SerialUSB for convenience.
  • Loading branch information
ricaun committed May 3, 2019
1 parent 483693b commit f1089c0
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 9 deletions.
29 changes: 25 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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. <br/>
Expand Down Expand Up @@ -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

Expand Down
19 changes: 19 additions & 0 deletions examples/ArduinoUniqueIDSerialUSB/ArduinoUniqueIDSerialUSB.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// ArduinoUniqueIDSerialUSB.ino
//
// Example shows the UniqueID on the SerialUSB Monitor.
//

#include <ArduinoUniqueID.h>

void setup()
{
SerialUSB.begin(115200);
while (!SerialUSB);
UniqueIDdump(SerialUSB);
UniqueID8dump(SerialUSB);
}

void loop()
{
}
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.6
version=1.0.7
author=Luiz Henrique Cassettari
maintainer=Luiz Henrique Cassettari <[email protected]>
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
23 changes: 23 additions & 0 deletions src/ArduinoUniqueID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
6 changes: 5 additions & 1 deletion src/ArduinoUniqueID.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit f1089c0

Please sign in to comment.