Skip to content

Commit cfc3bd1

Browse files
committed
get SD version instead of hardcode string
1 parent bd7c8db commit cfc3bd1

File tree

4 files changed

+128
-14
lines changed

4 files changed

+128
-14
lines changed

cores/nRF5/debug.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include <stdarg.h>
3939
#include <malloc.h>
4040
#include "debug.h"
41+
#include "utility/utilities.h"
4142

4243
// defined in linker script
4344
extern uint32_t __data_start__[];
@@ -140,8 +141,8 @@ void dbgPrintVersion(void)
140141
{
141142
Serial.println();
142143
Serial.println("BSP Library: " ARDUINO_BSP_VERSION);
143-
Serial.printf ("Bootloader : %d.%d.%d\n", U32_BYTE2(bootloaderVersion), U32_BYTE3(bootloaderVersion), U32_BYTE4(bootloaderVersion));
144-
Serial.println("SoftDevice : S132 2.0.1");
144+
Serial.printf ("Firmware : %s\n", getFirmwareVersion());
145+
Serial.printf ("Serial No : %s\n", getMcuUniqueID());
145146
Serial.println();
146147
}
147148

cores/nRF5/utility/utilities.c

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,23 @@
3434
*/
3535
/**************************************************************************/
3636

37+
#include <Arduino.h>
3738
#include "utilities.h"
3839

40+
#include "nrf_sdm.h"
41+
#include "nrf52/nrf_mbr.h"
42+
43+
static lookup_entry_t const sd_lookup_items[] =
44+
{
45+
{ .key = 0x0088, .data = "S132 2.0.1" },
46+
};
47+
48+
static const lookup_table_t sd_lookup_table =
49+
{
50+
.count = sizeof(sd_lookup_items)/sizeof(lookup_entry_t),
51+
.items = sd_lookup_items
52+
};
53+
3954
/******************************************************************************/
4055
/*!
4156
@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)
5166

5267
return NULL;
5368
}
69+
/**
70+
* Format: SDname SDverion, bootloader version
71+
* e.g
72+
* "S132 2.0.1, 0.5.0"
73+
* @return
74+
*/
75+
const char* getFirmwareVersion(void)
76+
{
77+
static char fw_str[20+1] = { 0 };
78+
79+
// Skip if already created
80+
if ( fw_str[0] == 0 )
81+
{
82+
uint32_t sd_id = SD_FWID_GET(MBR_SIZE) & 0x0000ffff;
83+
char const* p_lookup = (char const*) lookup_find(&sd_lookup_table, sd_id);
84+
85+
if (p_lookup)
86+
{
87+
sprintf(fw_str, "%s, %d.%d.%d", p_lookup,
88+
U32_BYTE2(bootloaderVersion), U32_BYTE3(bootloaderVersion), U32_BYTE4(bootloaderVersion));
89+
}else
90+
{
91+
// Unknown SD ID --> display ID
92+
sprintf(fw_str, "0x%04X, %d.%d.%d", (uint16_t) sd_id,
93+
U32_BYTE2(bootloaderVersion), U32_BYTE3(bootloaderVersion), U32_BYTE4(bootloaderVersion));
94+
}
95+
}
96+
97+
return fw_str;
98+
}
99+
100+
const char* getMcuUniqueID(void)
101+
{
102+
static char serial_str[16+1] = { 0 };
103+
104+
// Skip if already created
105+
if ( serial_str[0] == 0 )
106+
{
107+
sprintf(serial_str, "%08lX%08lX", NRF_FICR->DEVICEID[1], NRF_FICR->DEVICEID[0]);
108+
}
109+
110+
return serial_str;
111+
}
112+
113+
/*
114+
* nrfjprog --family NRF52 --memrd 0x0000300C
115+
*
116+
SoftDevice | FWID | memory address |
117+
--------------------|--------|----------------
118+
S110 v5.2.1 | 0x0043 | 0x10001010 |
119+
S110 v6.0.0 | 0x0049 | 0x10001010 |
120+
S110 v6.2.1 | 0x0035 | 0x10001010 |
121+
S110 v7.0.0 | 0x004F | 0x0000300C |
122+
S110 v7.1.0 | 0x005A | 0x0000300C |
123+
S110 v7.3.0 | 0x0063 | 0x0000300C |
124+
S110 v8.0.0 | 0x0064 | 0x0000300C |
125+
----------------------------------------------
126+
S120 v1.0.0 | 0x0055 | 0x0000300C |
127+
S120 v1.0.1 | 0x0058 | 0x0000300C |
128+
S120 v2.0.0-1.alpha | 0x005B | 0x0000300C |
129+
S120 v2.0.0 | 0x0060 | 0x0000300C |
130+
S120 v2.1.0 | 0x006B | 0x0000300C |
131+
----------------------------------------------
132+
S130 v0.9.0-1.alpha | 0x005E | 0x0000300C |
133+
S130 v1.0.0-3.alpha | 0x0066 | 0x0000300C |
134+
S130 v1.0.0 | 0x0067 | 0x0000300C |
135+
S130 v2.0.0 | 0x0080 | 0x0000300C |
136+
S130 v2.0.1 | 0x0087 | 0x0000300C |
137+
----------------------------------------------
138+
S210 v3.0.0 | 0x004B | 0x10001010 |
139+
S210 v4.0.0 | 0x0057 | 0x0000300C |
140+
----------------------------------------------
141+
S310 v1.0.0 | 0x004D | 0x10001010 |
142+
S310 v2.0.0 | 0x005D | 0x0000300C |
143+
S310 v2.0.1 | 0x005D | 0x0000300C |
144+
S310 v3.0.0 | 0x0065 | 0x0000300C |
145+
----------------------------------------------
146+
S132 v1.0.0-3.alpha | 0x006D | ? |
147+
S132 v2.0.0-4.alpha | 0x0074 | ? |
148+
S132 v2.0.0-7.alpha | 0x0079 | 0x0000300C |
149+
S132 v2.0.0 | 0x0081 | 0x0000300C |
150+
S132 v2.0.1 | 0x0088 | 0x0000300C |
151+
----------------------------------------------
152+
S212 v0.6.0.alpha | 0x007F | 0x0000300C |
153+
S212 v0.9.1.alpha | 0x0083 | 0x0000300C |
154+
----------------------------------------------
155+
S332 v0.6.0.alpha | 0x007E | 0x0000300C |
156+
S332 v0.9.1.alpha | 0x0082 | 0x0000300C |
157+
----------------------------------------------
158+
Development/any | 0xFFFE
159+
----------------------------
160+
*/

cores/nRF5/utility/utilities.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@
3636
#ifndef UTILITIES_H_
3737
#define UTILITIES_H_
3838

39-
#include <Arduino.h>
39+
#include <stdint.h>
40+
41+
#ifdef __cplusplus
42+
extern "C" {
43+
#endif
4044

4145
typedef struct
4246
{
@@ -47,11 +51,16 @@ typedef struct
4751
typedef struct
4852
{
4953
uint16_t count;
50-
uint16_t data_size;
51-
5254
lookup_entry_t const* items;
5355
} lookup_table_t;
5456

5557
void const * lookup_find(lookup_table_t const* p_table, uint32_t key);
5658

59+
const char* getFirmwareVersion(void);
60+
const char* getMcuUniqueID(void);
61+
62+
#ifdef __cplusplus
63+
}
64+
#endif
65+
5766
#endif /* UTILITIES_H_ */

libraries/Bluefruit52Lib/src/services/BLEDis.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,14 @@
3535
/**************************************************************************/
3636

3737
#include "bluefruit.h"
38-
39-
static char bledis_serial_str[16+1];
40-
static char bledis_fw_str[16+1];
41-
38+
#include "utility/utilities.h"
4239

4340
BLEDis::BLEDis(void)
4441
: BLEService(UUID16_SVC_DEVICE_INFORMATION)
4542
{
4643
_model = "Bluefruit Feather52";
47-
_serial = bledis_serial_str;
48-
_firmware_rev = bledis_fw_str;
44+
_serial = NULL;
45+
_firmware_rev = NULL;
4946
_hardware_rev = NULL;
5047
_software_rev = ARDUINO_BSP_VERSION;
5148
_manufacturer = "Adafruit Industries";
@@ -75,9 +72,8 @@ err_t BLEDis::begin(void)
7572
{
7673
VERIFY_STATUS( this->addToGatt() );
7774

78-
sprintf(bledis_serial_str, "%08lX%08lX", NRF_FICR->DEVICEID[1], NRF_FICR->DEVICEID[0]);
79-
sprintf(bledis_fw_str, "%d.%d.%d,S132,2.0.1",
80-
U32_BYTE2(bootloaderVersion), U32_BYTE3(bootloaderVersion), U32_BYTE4(bootloaderVersion));
75+
_serial = getMcuUniqueID();
76+
_firmware_rev = getFirmwareVersion();
8177

8278
for(uint8_t i=0; i<arrcount(_strarr); i++)
8379
{
@@ -96,3 +92,4 @@ err_t BLEDis::begin(void)
9692

9793
return ERROR_NONE;
9894
}
95+

0 commit comments

Comments
 (0)