Skip to content

Commit 483693b

Browse files
authored
Merge pull request #1 from TimGremalm/AtmelSAM
Support Atmel SAM3X8E (Arduino Due)
2 parents d8465f8 + bfaaa24 commit 483693b

File tree

4 files changed

+52
-6
lines changed

4 files changed

+52
-6
lines changed

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
This Library gets the Unique Serial ID from the AVR Microcontroller and ESP Microcontroller.
44

5-
# AVR Microcontroller
5+
# Atmel AVR Microcontroller
66

77
## Unique Serial ID - Hidden Serial Number
88

@@ -32,7 +32,15 @@ Apparently, the chip Atmega328p have a hidden serial number with 9 bytes, and ot
3232
* Atmega2560 - 9 bytes
3333
* Attiny85 - 9 bytes
3434

35-
# ESP Microcontroller
35+
# 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)
38+
39+
## Tested Microcontroller
40+
41+
* Atmel SAM3X8E ARM Cortex-M3 - 16 bytes
42+
43+
# Espressif ESP Microcontroller
3644

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

library.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
name=ArduinoUniqueID
2-
version=1.0.5
2+
version=1.0.6
33
author=Luiz Henrique Cassettari
44
maintainer=Luiz Henrique Cassettari <ricaun@gmail.com>
55
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, ESP8266 & ESP32.
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.
77
category=Other
88
url=https://github.com/ricaun/ArduinoUniqueID
9-
architectures=avr, esp8266, esp32
9+
architectures=avr, esp8266, esp32, sam
1010
includes=ArduinoUniqueID.h

src/ArduinoUniqueID.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,40 @@ ArduinoUniqueID::ArduinoUniqueID()
3131
id[5] = chipid >> 24;
3232
id[6] = chipid >> 32;
3333
id[7] = chipid >> 40;
34+
35+
#elif defined(ARDUINO_ARCH_SAM)
36+
unsigned int status ;
37+
/* Send the Start Read unique Identifier command (STUI) by writing the Flash Command Register with the STUI command.*/
38+
EFC1->EEFC_FCR = (0x5A << 24) | EFC_FCMD_STUI;
39+
do
40+
{
41+
status = EFC1->EEFC_FSR ;
42+
} while ( (status & EEFC_FSR_FRDY) == EEFC_FSR_FRDY ) ;
43+
44+
/* The Unique Identifier is located in the first 128 bits of the Flash memory mapping. So, at the address 0x400000-0x400003. */
45+
uint32_t pdwUniqueID[4];
46+
pdwUniqueID[0] = *(uint32_t *)IFLASH1_ADDR;
47+
pdwUniqueID[1] = *(uint32_t *)(IFLASH1_ADDR + 4);
48+
pdwUniqueID[2] = *(uint32_t *)(IFLASH1_ADDR + 8);
49+
pdwUniqueID[3] = *(uint32_t *)(IFLASH1_ADDR + 12);
50+
for (int i = 0; i < 4; i++)
51+
{
52+
id[i*4+0] = (uint8_t)(pdwUniqueID[i] >> 24);
53+
id[i*4+1] = (uint8_t)(pdwUniqueID[i] >> 16);
54+
id[i*4+2] = (uint8_t)(pdwUniqueID[i] >> 8);
55+
id[i*4+3] = (uint8_t)(pdwUniqueID[i] >> 0);
56+
}
57+
58+
/* To stop the Unique Identifier mode, the user needs to send the Stop Read unique Identifier
59+
command (SPUI) by writing the Flash Command Register with the SPUI command. */
60+
EFC1->EEFC_FCR = (0x5A << 24) | EFC_FCMD_SPUI ;
61+
62+
/* When the Stop read Unique Unique Identifier command (SPUI) has been performed, the
63+
FRDY bit in the Flash Programming Status Register (EEFC_FSR) rises. */
64+
do
65+
{
66+
status = EFC1->EEFC_FSR ;
67+
} while ( (status & EEFC_FSR_FRDY) != EEFC_FSR_FRDY );
3468
#endif
3569
}
3670

src/ArduinoUniqueID.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
#endif
1414
#elif defined(ARDUINO_ARCH_ESP8266)
1515
#elif defined(ARDUINO_ARCH_ESP32)
16+
#elif defined(ARDUINO_ARCH_SAM)
1617
#else
17-
#error "ArduinoUniqueID only works on AVR and ESP Architecture"
18+
#error "ArduinoUniqueID only works on AVR, SAM and ESP Architecture"
1819
#endif
1920

2021
#if defined(ARDUINO_ARCH_AVR)
@@ -33,6 +34,9 @@
3334
#elif defined(ARDUINO_ARCH_ESP32)
3435
#define UniqueIDsize 6
3536
#define UniqueIDbuffer 8
37+
#elif defined(ARDUINO_ARCH_SAM)
38+
#define UniqueIDsize 16
39+
#define UniqueIDbuffer 16
3640
#endif
3741

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

0 commit comments

Comments
 (0)