diff --git a/IO.h b/IO.h index 09987ef..2ae3604 100644 --- a/IO.h +++ b/IO.h @@ -58,6 +58,10 @@ public: void resetWatchdog(); uint32_t getWatchdog(); + uint8_t getCPU() const; + + void getUDID(uint8_t* buffer); + void selfTest(); private: diff --git a/IODue.cpp b/IODue.cpp index 8921d5b..b4e0700 100644 --- a/IODue.cpp +++ b/IODue.cpp @@ -291,4 +291,24 @@ void CIO::delayInt(unsigned int dly) delay(dly); } +uint8_t CIO::getCPU() const +{ + return 0U; +} + +// Code taken from https://github.com/emagii/at91sam3s/blob/master/examples/eefc_uniqueid/main.c +void CIO::getUDID(uint8_t* buffer) +{ + EFC->EEFC_FCR = (0x5A << 24) | EFC_FCMD_STUI; + + ::memcpy(buffer, (void *)IFLASH_ADDR, 16U); + + EFC->EEFC_FCR = (0x5A << 24) | EFC_FCMD_SPUI; + + do { + status = EFC->EEFC_FSR ; + } while ((status & EEFC_FSR_FRDY) != EEFC_FSR_FRDY); +} + #endif + diff --git a/IOSTM.cpp b/IOSTM.cpp index ecf4f75..db87da0 100644 --- a/IOSTM.cpp +++ b/IOSTM.cpp @@ -545,4 +545,21 @@ void CIO::delayInt(unsigned int dly) } } +uint8_t CIO::getCPU() const +{ + return 2U; +} + +void CIO::getUDID(uint8_t* buffer) +{ +#if defined(STM32F4XX) + ::memcpy(buffer, (void *)0x1FFF7A10, 12U); +#elif defined(STM32F722xx) + ::memcpy(buffer, (void *)0x1FF07A10, 12U); +#elif defined(STM32F767xx) + ::memcpy(buffer, (void *)0x1FF0F420, 12U); #endif +} + +#endif + diff --git a/IOSTM_CMSIS.cpp b/IOSTM_CMSIS.cpp index 165c03d..300a88a 100644 --- a/IOSTM_CMSIS.cpp +++ b/IOSTM_CMSIS.cpp @@ -23,7 +23,6 @@ #include "Globals.h" #include "IO.h" - #if defined(STM32F1) #if defined(STM32F1_POG) @@ -485,4 +484,17 @@ void CIO::delayInt(unsigned int dly) delay(dly); } +uint8_t CIO::getCPU() const +{ + return 2U; +} + +void CIO::getUDID(uint8_t* buffer) +{ +#if defined(STM32F105xC) + ::memcpy(buffer, (void *)0x1FFFF7E8, 12U); #endif +} + +#endif + diff --git a/IOTeensy.cpp b/IOTeensy.cpp index 0ee4fad..5e1028d 100644 --- a/IOTeensy.cpp +++ b/IOTeensy.cpp @@ -275,4 +275,15 @@ void CIO::delayInt(unsigned int dly) delay(dly); } +uint8_t CIO::getCPU() const +{ + return 1U; +} + +void CIO::getUDID(uint8_t* buffer) +{ + ::memcpy(buffer, (void *)0x4058, 16U); +} + #endif + diff --git a/SerialPort.cpp b/SerialPort.cpp index 72614ac..6208904 100644 --- a/SerialPort.cpp +++ b/SerialPort.cpp @@ -112,7 +112,7 @@ const uint8_t MMDVM_DEBUG5 = 0xF5U; #define HW_TYPE "MMDVM" #endif -#define DESCRIPTION "20201108 (D-Star/DMR/System Fusion/P25/NXDN/M17/POCSAG/FM/AX.25)" +#define DESCRIPTION "20201109 (D-Star/DMR/System Fusion/P25/NXDN/M17/POCSAG/FM/AX.25)" #if defined(GITVERSION) #define concat(h, a, b, c) h " " a " " b " GitID #" c "" @@ -290,7 +290,7 @@ void CSerialPort::getStatus() void CSerialPort::getVersion() { - uint8_t reply[150U]; + uint8_t reply[200U]; reply[0U] = MMDVM_FRAME_START; reply[1U] = 0U; @@ -298,7 +298,13 @@ void CSerialPort::getVersion() reply[3U] = PROTOCOL_VERSION; - uint8_t count = 4U; + reply[4U] = io.getCPU(); + + // Reserve 16 bytes for the UDID + ::memcpy(reply + 5U, 0x00U, 16U); + io.getUDID(reply + 5U); + + uint8_t count = 21U; for (uint8_t i = 0U; HARDWARE[i] != 0x00U; i++, count++) reply[count] = HARDWARE[i];