From 1c3a4421f3af4877ee8ecd23b06e83978c3ce5f3 Mon Sep 17 00:00:00 2001 From: Andrey Klimov Date: Mon, 12 Nov 2018 02:21:38 +0300 Subject: [PATCH] Unique MPU id for due --- lighthub/main.cpp | 14 ++++++++++++ lighthub/utils.cpp | 54 ++++++++++++++++++++++++++++++++++++++-------- lighthub/utils.h | 1 + platformio.ini | 4 ++-- 4 files changed, 62 insertions(+), 11 deletions(-) diff --git a/lighthub/main.cpp b/lighthub/main.cpp index 4d77acf..5a60076 100644 --- a/lighthub/main.cpp +++ b/lighthub/main.cpp @@ -121,6 +121,7 @@ const char outprefix[] PROGMEM = OUTTOPIC; const char inprefix[] PROGMEM = INTOPIC; const char configserver[] PROGMEM = CONFIG_SERVER; +unsigned int UniqueID[5] = {0,0,0,0,0}; aJsonObject *root = NULL; aJsonObject *items = NULL; @@ -1200,6 +1201,19 @@ void printFirmwareVersionAndBuildOptions() { debugSerial<> 4); - debugSerial<<_HEX(addr[i] & 0x0f); + Serial.print(addr[i] >> 4, HEX); + Serial.print(addr[i] & 0x0f, HEX); } if (newline) - debugSerial<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 ) ; #endif +} #pragma message(VAR_NAME_VALUE(debugSerial)) diff --git a/lighthub/utils.h b/lighthub/utils.h index c1271cc..d710a9e 100644 --- a/lighthub/utils.h +++ b/lighthub/utils.h @@ -41,3 +41,4 @@ unsigned long freeRam (); void parseBytes(const char* str, char separator, byte* bytes, int maxBytes, int base); int log(const char *str, ...); void printFloatValueToStr(float value, char *valstr); +void ReadUniqueID( unsigned int * pdwUniqueID ); diff --git a/platformio.ini b/platformio.ini index 4c80693..1eda6a1 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,14 +9,14 @@ ; http://docs.platformio.org/page/projectconf.html [platformio] src_dir = lighthub -;env_default = +env_default = ; megaatmega2560 ; megaatmega2560-net ; due ; esp8266 ; esp32 ; megaatmega2560-5500 -; due-5500 + due-5500 ; controllino ; stm32