From cfc3bd1f8c69a5534c45048f1a1ba3237625713e Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 15 Mar 2017 15:33:17 +0700 Subject: [PATCH] get SD version instead of hardcode string --- cores/nRF5/debug.cpp | 5 +- cores/nRF5/utility/utilities.c | 107 ++++++++++++++++++ cores/nRF5/utility/utilities.h | 15 ++- .../Bluefruit52Lib/src/services/BLEDis.cpp | 15 +-- 4 files changed, 128 insertions(+), 14 deletions(-) diff --git a/cores/nRF5/debug.cpp b/cores/nRF5/debug.cpp index 04cdc229..0220e64c 100644 --- a/cores/nRF5/debug.cpp +++ b/cores/nRF5/debug.cpp @@ -38,6 +38,7 @@ #include #include #include "debug.h" +#include "utility/utilities.h" // defined in linker script extern uint32_t __data_start__[]; @@ -140,8 +141,8 @@ void dbgPrintVersion(void) { Serial.println(); Serial.println("BSP Library: " ARDUINO_BSP_VERSION); - Serial.printf ("Bootloader : %d.%d.%d\n", U32_BYTE2(bootloaderVersion), U32_BYTE3(bootloaderVersion), U32_BYTE4(bootloaderVersion)); - Serial.println("SoftDevice : S132 2.0.1"); + Serial.printf ("Firmware : %s\n", getFirmwareVersion()); + Serial.printf ("Serial No : %s\n", getMcuUniqueID()); Serial.println(); } diff --git a/cores/nRF5/utility/utilities.c b/cores/nRF5/utility/utilities.c index 8109bfa9..04e189cc 100644 --- a/cores/nRF5/utility/utilities.c +++ b/cores/nRF5/utility/utilities.c @@ -34,8 +34,23 @@ */ /**************************************************************************/ +#include #include "utilities.h" +#include "nrf_sdm.h" +#include "nrf52/nrf_mbr.h" + +static lookup_entry_t const sd_lookup_items[] = +{ + { .key = 0x0088, .data = "S132 2.0.1" }, +}; + +static const lookup_table_t sd_lookup_table = +{ + .count = sizeof(sd_lookup_items)/sizeof(lookup_entry_t), + .items = sd_lookup_items +}; + /******************************************************************************/ /*! @brief Find the corresponding data from the key @@ -51,3 +66,95 @@ void const * lookup_find(lookup_table_t const* p_table, uint32_t key) return NULL; } +/** + * Format: SDname SDverion, bootloader version + * e.g + * "S132 2.0.1, 0.5.0" + * @return + */ +const char* getFirmwareVersion(void) +{ + static char fw_str[20+1] = { 0 }; + + // Skip if already created + if ( fw_str[0] == 0 ) + { + uint32_t sd_id = SD_FWID_GET(MBR_SIZE) & 0x0000ffff; + char const* p_lookup = (char const*) lookup_find(&sd_lookup_table, sd_id); + + if (p_lookup) + { + sprintf(fw_str, "%s, %d.%d.%d", p_lookup, + U32_BYTE2(bootloaderVersion), U32_BYTE3(bootloaderVersion), U32_BYTE4(bootloaderVersion)); + }else + { + // Unknown SD ID --> display ID + sprintf(fw_str, "0x%04X, %d.%d.%d", (uint16_t) sd_id, + U32_BYTE2(bootloaderVersion), U32_BYTE3(bootloaderVersion), U32_BYTE4(bootloaderVersion)); + } + } + + return fw_str; +} + +const char* getMcuUniqueID(void) +{ + static char serial_str[16+1] = { 0 }; + + // Skip if already created + if ( serial_str[0] == 0 ) + { + sprintf(serial_str, "%08lX%08lX", NRF_FICR->DEVICEID[1], NRF_FICR->DEVICEID[0]); + } + + return serial_str; +} + +/* + * nrfjprog --family NRF52 --memrd 0x0000300C + * + SoftDevice | FWID | memory address | + --------------------|--------|---------------- + S110 v5.2.1 | 0x0043 | 0x10001010 | + S110 v6.0.0 | 0x0049 | 0x10001010 | + S110 v6.2.1 | 0x0035 | 0x10001010 | + S110 v7.0.0 | 0x004F | 0x0000300C | + S110 v7.1.0 | 0x005A | 0x0000300C | + S110 v7.3.0 | 0x0063 | 0x0000300C | + S110 v8.0.0 | 0x0064 | 0x0000300C | + ---------------------------------------------- + S120 v1.0.0 | 0x0055 | 0x0000300C | + S120 v1.0.1 | 0x0058 | 0x0000300C | + S120 v2.0.0-1.alpha | 0x005B | 0x0000300C | + S120 v2.0.0 | 0x0060 | 0x0000300C | + S120 v2.1.0 | 0x006B | 0x0000300C | + ---------------------------------------------- + S130 v0.9.0-1.alpha | 0x005E | 0x0000300C | + S130 v1.0.0-3.alpha | 0x0066 | 0x0000300C | + S130 v1.0.0 | 0x0067 | 0x0000300C | + S130 v2.0.0 | 0x0080 | 0x0000300C | + S130 v2.0.1 | 0x0087 | 0x0000300C | + ---------------------------------------------- + S210 v3.0.0 | 0x004B | 0x10001010 | + S210 v4.0.0 | 0x0057 | 0x0000300C | + ---------------------------------------------- + S310 v1.0.0 | 0x004D | 0x10001010 | + S310 v2.0.0 | 0x005D | 0x0000300C | + S310 v2.0.1 | 0x005D | 0x0000300C | + S310 v3.0.0 | 0x0065 | 0x0000300C | + ---------------------------------------------- + S132 v1.0.0-3.alpha | 0x006D | ? | + S132 v2.0.0-4.alpha | 0x0074 | ? | + S132 v2.0.0-7.alpha | 0x0079 | 0x0000300C | + S132 v2.0.0 | 0x0081 | 0x0000300C | + S132 v2.0.1 | 0x0088 | 0x0000300C | + ---------------------------------------------- + S212 v0.6.0.alpha | 0x007F | 0x0000300C | + S212 v0.9.1.alpha | 0x0083 | 0x0000300C | + ---------------------------------------------- + S332 v0.6.0.alpha | 0x007E | 0x0000300C | + S332 v0.9.1.alpha | 0x0082 | 0x0000300C | + ---------------------------------------------- + Development/any | 0xFFFE + ---------------------------- + */ diff --git a/cores/nRF5/utility/utilities.h b/cores/nRF5/utility/utilities.h index 1c98b720..a4811396 100644 --- a/cores/nRF5/utility/utilities.h +++ b/cores/nRF5/utility/utilities.h @@ -36,7 +36,11 @@ #ifndef UTILITIES_H_ #define UTILITIES_H_ -#include +#include + +#ifdef __cplusplus +extern "C" { +#endif typedef struct { @@ -47,11 +51,16 @@ typedef struct typedef struct { uint16_t count; - uint16_t data_size; - lookup_entry_t const* items; } lookup_table_t; void const * lookup_find(lookup_table_t const* p_table, uint32_t key); +const char* getFirmwareVersion(void); +const char* getMcuUniqueID(void); + +#ifdef __cplusplus +} +#endif + #endif /* UTILITIES_H_ */ diff --git a/libraries/Bluefruit52Lib/src/services/BLEDis.cpp b/libraries/Bluefruit52Lib/src/services/BLEDis.cpp index ab2559b5..5c75fea0 100644 --- a/libraries/Bluefruit52Lib/src/services/BLEDis.cpp +++ b/libraries/Bluefruit52Lib/src/services/BLEDis.cpp @@ -35,17 +35,14 @@ /**************************************************************************/ #include "bluefruit.h" - -static char bledis_serial_str[16+1]; -static char bledis_fw_str[16+1]; - +#include "utility/utilities.h" BLEDis::BLEDis(void) : BLEService(UUID16_SVC_DEVICE_INFORMATION) { _model = "Bluefruit Feather52"; - _serial = bledis_serial_str; - _firmware_rev = bledis_fw_str; + _serial = NULL; + _firmware_rev = NULL; _hardware_rev = NULL; _software_rev = ARDUINO_BSP_VERSION; _manufacturer = "Adafruit Industries"; @@ -75,9 +72,8 @@ err_t BLEDis::begin(void) { VERIFY_STATUS( this->addToGatt() ); - sprintf(bledis_serial_str, "%08lX%08lX", NRF_FICR->DEVICEID[1], NRF_FICR->DEVICEID[0]); - sprintf(bledis_fw_str, "%d.%d.%d,S132,2.0.1", - U32_BYTE2(bootloaderVersion), U32_BYTE3(bootloaderVersion), U32_BYTE4(bootloaderVersion)); + _serial = getMcuUniqueID(); + _firmware_rev = getFirmwareVersion(); for(uint8_t i=0; i