Skip to content

Commit f1089c0

Browse files
committed
Support Atmel SAMD21 (Arduino Zero)
Add Support Atmel SAMD21 (Arduino Zero) Add Example to SerialUSB for convenience.
1 parent 483693b commit f1089c0

File tree

5 files changed

+76
-9
lines changed

5 files changed

+76
-9
lines changed

README.md

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

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

55
# Atmel AVR Microcontroller
66

@@ -33,13 +33,34 @@ Apparently, the chip Atmega328p have a hidden serial number with 9 bytes, and ot
3333
* Attiny85 - 9 bytes
3434

3535
# Atmel SAM ARM Microcontroller
36-
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.
37-
"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)
36+
37+
Atmel SAM3X8E is used in Arduino Due.
38+
39+
The Unique Identifier is located in the first 128 bits of the Flash memory mapping. So, at the address 0x400000-0x400003.
40+
41+
"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)
3842

3943
## Tested Microcontroller
4044

4145
* Atmel SAM3X8E ARM Cortex-M3 - 16 bytes
4246

47+
# Atmel SAMD ARM Microcontroller
48+
49+
Atmel SAMD21 is used in Arduino Zero / Arduino M0.
50+
51+
Each device has a unique 128-bit serial number which is a concatenation of four 32-bit words contained at the following addresses:
52+
53+
* Word 0: 0x0080A00C
54+
* Word 1: 0x0080A040
55+
* Word 2: 0x0080A044
56+
* Word 3: 0x0080A048
57+
58+
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)
59+
60+
## Tested Microcontroller
61+
62+
* Atmel SAMD21 ARM Cortex-M0 - 16 bytes
63+
4364
# Espressif ESP Microcontroller
4465

4566
ESP microcontroller has basically two versions, ESP8266 and ESP32, each one has a specific function to request the chip id. <br/>
@@ -81,7 +102,7 @@ This library only supports AVR Microcontroller and ESP Microcontroller.
81102
## Installation
82103

83104
* Install the library by [Using the Library Manager](https://www.arduino.cc/en/Guide/Libraries#toc3)
84-
* **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.
105+
* **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.
85106

86107
## Examples
87108

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// ArduinoUniqueIDSerialUSB.ino
3+
//
4+
// Example shows the UniqueID on the SerialUSB Monitor.
5+
//
6+
7+
#include <ArduinoUniqueID.h>
8+
9+
void setup()
10+
{
11+
SerialUSB.begin(115200);
12+
while (!SerialUSB);
13+
UniqueIDdump(SerialUSB);
14+
UniqueID8dump(SerialUSB);
15+
}
16+
17+
void loop()
18+
{
19+
}

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.6
2+
version=1.0.7
33
author=Luiz Henrique Cassettari
44
maintainer=Luiz Henrique Cassettari <ricaun@gmail.com>
5-
sentence=Arduino Library to get the AVR microcontroler Unique ID / Manufacture Serial Number.
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, ESP8266 & ESP32.
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.
77
category=Other
88
url=https://github.com/ricaun/ArduinoUniqueID
9-
architectures=avr, esp8266, esp32, sam
9+
architectures=avr, esp8266, esp32, sam, samd
1010
includes=ArduinoUniqueID.h

src/ArduinoUniqueID.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,29 @@ ArduinoUniqueID::ArduinoUniqueID()
6565
{
6666
status = EFC1->EEFC_FSR ;
6767
} while ( (status & EEFC_FSR_FRDY) != EEFC_FSR_FRDY );
68+
69+
#elif defined(ARDUINO_ARCH_SAMD)
70+
71+
// from section 9.3.3 of the datasheet
72+
#define SERIAL_NUMBER_WORD_0 *(volatile uint32_t*)(0x0080A00C)
73+
#define SERIAL_NUMBER_WORD_1 *(volatile uint32_t*)(0x0080A040)
74+
#define SERIAL_NUMBER_WORD_2 *(volatile uint32_t*)(0x0080A044)
75+
#define SERIAL_NUMBER_WORD_3 *(volatile uint32_t*)(0x0080A048)
76+
77+
uint32_t pdwUniqueID[4];
78+
pdwUniqueID[0] = SERIAL_NUMBER_WORD_0;
79+
pdwUniqueID[1] = SERIAL_NUMBER_WORD_1;
80+
pdwUniqueID[2] = SERIAL_NUMBER_WORD_2;
81+
pdwUniqueID[3] = SERIAL_NUMBER_WORD_3;
82+
83+
for (int i = 0; i < 4; i++)
84+
{
85+
id[i*4+0] = (uint8_t)(pdwUniqueID[i] >> 24);
86+
id[i*4+1] = (uint8_t)(pdwUniqueID[i] >> 16);
87+
id[i*4+2] = (uint8_t)(pdwUniqueID[i] >> 8);
88+
id[i*4+3] = (uint8_t)(pdwUniqueID[i] >> 0);
89+
}
90+
6891
#endif
6992
}
7093

src/ArduinoUniqueID.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
#elif defined(ARDUINO_ARCH_ESP8266)
1515
#elif defined(ARDUINO_ARCH_ESP32)
1616
#elif defined(ARDUINO_ARCH_SAM)
17+
#elif defined(ARDUINO_ARCH_SAMD)
1718
#else
18-
#error "ArduinoUniqueID only works on AVR, SAM and ESP Architecture"
19+
#error "ArduinoUniqueID only works on AVR, SAM, SAMD and ESP Architecture"
1920
#endif
2021

2122
#if defined(ARDUINO_ARCH_AVR)
@@ -37,6 +38,9 @@
3738
#elif defined(ARDUINO_ARCH_SAM)
3839
#define UniqueIDsize 16
3940
#define UniqueIDbuffer 16
41+
#elif defined(ARDUINO_ARCH_SAMD)
42+
#define UniqueIDsize 16
43+
#define UniqueIDbuffer 16
4044
#endif
4145

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

0 commit comments

Comments
 (0)