From ccb55e6e235d82260c79d004f322fc24dc0ed445 Mon Sep 17 00:00:00 2001 From: James Devine Date: Sun, 4 Dec 2016 17:59:45 +0100 Subject: [PATCH] --- DUEUniqueID | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 DUEUniqueID diff --git a/DUEUniqueID b/DUEUniqueID new file mode 100644 index 0000000..3341a79 --- /dev/null +++ b/DUEUniqueID @@ -0,0 +1,57 @@ + +/* Code borrowed from http://forum.arduino.cc/index.php?topic=289190.0 +Awesome work Mark T!*/ + + +__attribute__ ((section (".ramfunc"))) +void _EEFC_ReadUniqueID( unsigned int * pdwUniqueID ) +{ + unsigned int status ; + + /* Send the Start Read unique Identifier command (STUI) by writing the Flash Command Register with the STUI command.*/ + EFC1->EEFC_FCR = (0x5A << 24) | EFC_FCMD_STUI; + do + { + status = EFC1->EEFC_FSR ; + } while ( (status & EEFC_FSR_FRDY) == EEFC_FSR_FRDY ) ; + + /* The Unique Identifier is located in the first 128 bits of the Flash memory mapping. So, at the address 0x400000-0x400003. */ + pdwUniqueID[0] = *(uint32_t *)IFLASH1_ADDR; + pdwUniqueID[1] = *(uint32_t *)(IFLASH1_ADDR + 4); + pdwUniqueID[2] = *(uint32_t *)(IFLASH1_ADDR + 8); + pdwUniqueID[3] = *(uint32_t *)(IFLASH1_ADDR + 12); + + /* To stop the Unique Identifier mode, the user needs to send the Stop Read unique Identifier + command (SPUI) by writing the Flash Command Register with the SPUI command. */ + EFC1->EEFC_FCR = (0x5A << 24) | EFC_FCMD_SPUI ; + + /* When the Stop read Unique Unique Identifier command (SPUI) has been performed, the + FRDY bit in the Flash Programming Status Register (EEFC_FSR) rises. */ + do + { + status = EFC1->EEFC_FSR ; + } while ( (status & EEFC_FSR_FRDY) != EEFC_FSR_FRDY ) ; +} + +void setup () +{ + Serial.begin (9600) ; + + unsigned int adwUniqueID[5] ; + WDT_Disable( WDT ) ; + + Serial.println("Reading 128 bits unique identifier \n\r" ) ; + _EEFC_ReadUniqueID( adwUniqueID ) ; + + Serial.print ("ID: ") ; + for (byte b = 0 ; b < 4 ; b++) + Serial.print ((unsigned int) adwUniqueID [b], HEX) ; + Serial.println () ; +} + + + +void loop() { + // put your main code here, to run repeatedly: + +} \ No newline at end of file