Skip to content

Commit 81daeb7

Browse files
noahpjtguggedal
authored andcommitted
modules: memfault: Improve support for custom device info
Adjust how CONFIG_MEMFAULT_DEVICE_INFO_BUILTIN is used to enable the built-in implementation of memfault_platform_get_device_info(), so users can more easily enable a custom version by setting CONFIG_MEMFAULT_DEVICE_INFO_CUSTOM=y (no longer need to set placeholder values for CONFIG_MEMFAULT_NCS_DEVICE_ID etc when custom device info is selected). Now it's possible to enable Memfault with less manual Kconfig settings on short-range chips: Before; we build with 'MEMFAULT_DEVICE_INFO_CUSTOM', but we still need to set CONFIG_MEMFAULT_NCS_DEVICE_ID: ❯ west build --sysbuild --board nrf54l15dk/nrf54l15/cpuapp \ --pristine=always \ nrf/samples/bluetooth/peripheral_lbs \ -- \ -DCONFIG_SHELL=y \ -DCONFIG_MEMFAULT=y \ -DCONFIG_MEMFAULT_DEVICE_INFO_CUSTOM=y \ -DCONFIG_HWINFO=y \ -DCONFIG_MEMFAULT_NCS_DEVICE_ID=\"testserial\" After, we can select 'CUSTOM' + 'HWINFO' to get a built-in device ID from the Memfault SDK ❯ west build --sysbuild --board nrf54l15dk/nrf54l15/cpuapp \ --pristine=always \ nrf/samples/bluetooth/peripheral_lbs \ -- \ -DCONFIG_SHELL=y \ -DCONFIG_MEMFAULT=y \ -DCONFIG_MEMFAULT_NCS_DEVICE_INFO_CUSTOM=y \ -DCONFIG_HWINFO=y # HWINFO enables default Memfault device info Device shell shows default values: uart:~$ mflt get_device_info I: S/N: nrf54l15-testserial I: SW type: app I: SW version: 3.0.99 I: HW version: nrf54l15dk Rename these Kconfig options to better show they are in NCS, not the Memfault module: - MEMFAULT_DEVICE_INFO_BUILTIN -> MEMFAULT_NCS_DEVICE_INFO_BUILTIN - MEMFAULT_DEVICE_INFO_CUSTOM -> MEMFAULT_NCS_DEVICE_INFO_CUSTOM This is a breaking change (but will show up as a build error when updating). Signed-off-by: Noah Pendleton <[email protected]>
1 parent 5b2b422 commit 81daeb7

File tree

3 files changed

+44
-32
lines changed

3 files changed

+44
-32
lines changed

doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,10 @@ Edge Impulse integration
750750
Memfault integration
751751
--------------------
752752

753-
|no_changes_yet_note|
753+
* Updated:
754+
755+
* The ``CONFIG_MEMFAULT_DEVICE_INFO_CUSTOM`` Kconfig option has been renamed to :kconfig:option:`CONFIG_MEMFAULT_NCS_DEVICE_INFO_CUSTOM`.
756+
* The ``CONFIG_MEMFAULT_DEVICE_INFO_BUILTIN`` Kconfig option has been renamed to :kconfig:option:`CONFIG_MEMFAULT_NCS_DEVICE_INFO_BUILTIN`.
754757

755758
AVSystem integration
756759
--------------------

modules/memfault-firmware-sdk/Kconfig

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ config MEMFAULT_DEVICE_INFO_BUILTIN
2020
help
2121
Use built-in Memfault Device Info implementation
2222

23-
config MEMFAULT_DEVICE_INFO_CUSTOM
23+
config MEMFAULT_NCS_DEVICE_INFO_CUSTOM
2424
bool "Custom user-defined Memfault Device Info implementation"
2525
help
2626
Use custom user-defined Memfault Device Info implementation.
@@ -29,6 +29,8 @@ config MEMFAULT_DEVICE_INFO_CUSTOM
2929

3030
endchoice
3131

32+
if MEMFAULT_DEVICE_INFO_BUILTIN
33+
3234
choice
3335
prompt "Memfault device ID generation method"
3436
default MEMFAULT_NCS_DEVICE_ID_IMEI if (BOARD_NRF9160DK_NRF9160_NS || BOARD_NRF9161DK_NRF9161_NS || BOARD_THINGY91_NRF9160_NS)
@@ -120,6 +122,8 @@ config MEMFAULT_NCS_FW_VERSION
120122
When using a statically configured firmware version, this value
121123
will be reported to Memfault
122124

125+
endif # MEMFAULT_DEVICE_INFO_BUILTIN
126+
123127
config MEMFAULT_NCS_INIT_PRIORITY
124128
int "Memfault initialization priority"
125129
default 90

modules/memfault-firmware-sdk/memfault_integration.c

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ BUILD_ASSERT(sizeof(CONFIG_MEMFAULT_NCS_PROJECT_KEY) > 1,
4141
"Memfault Project Key not configured. Please visit " MEMFAULT_URL " ");
4242
#endif
4343

44+
extern void memfault_ncs_metrics_init(void);
45+
46+
/* Memfault HTTP client configuration
47+
*
48+
* This symbol has public scope- it's used by the Memfault SDK when executing
49+
* HTTP requests
50+
*/
51+
sMfltHttpClientConfig g_mflt_http_client_config = {
52+
.api_key = CONFIG_MEMFAULT_NCS_PROJECT_KEY,
53+
};
54+
55+
#if defined(CONFIG_MEMFAULT_DEVICE_INFO_BUILTIN)
4456
/* Firmware type check */
4557
BUILD_ASSERT(sizeof(CONFIG_MEMFAULT_NCS_FW_TYPE) > 1, "Firmware type must be configured");
4658

@@ -63,13 +75,6 @@ BUILD_ASSERT(sizeof(CONFIG_MEMFAULT_NCS_FW_VERSION_STATIC) > 1,
6375
/* Hardware version check */
6476
BUILD_ASSERT(sizeof(CONFIG_MEMFAULT_NCS_HW_VERSION) > 1, "Hardware version must be configured");
6577

66-
extern void memfault_ncs_metrics_init(void);
67-
68-
sMfltHttpClientConfig g_mflt_http_client_config = {
69-
.api_key = CONFIG_MEMFAULT_NCS_PROJECT_KEY,
70-
};
71-
72-
#if defined(CONFIG_MEMFAULT_DEVICE_INFO_BUILTIN)
7378
void memfault_platform_get_device_info(sMemfaultDeviceInfo *info)
7479
{
7580
#if defined(CONFIG_MEMFAULT_NCS_FW_VERSION_AUTO)
@@ -98,6 +103,29 @@ void memfault_platform_get_device_info(sMemfaultDeviceInfo *info)
98103
.hardware_version = CONFIG_MEMFAULT_NCS_HW_VERSION,
99104
};
100105
}
106+
107+
int memfault_ncs_device_id_set(const char *device_id, size_t len)
108+
{
109+
if (!IS_ENABLED(CONFIG_MEMFAULT_NCS_DEVICE_ID_RUNTIME)) {
110+
LOG_ERR("CONFIG_MEMFAULT_NCS_DEVICE_ID_RUNTIME is disabled");
111+
return -ENOTSUP;
112+
}
113+
114+
if (device_id == NULL) {
115+
return -EINVAL;
116+
}
117+
118+
if (len > (sizeof(device_serial) - 1)) {
119+
LOG_ERR("Device ID is longer than CONFIG_MEMFAULT_NCS_DEVICE_ID_MAX_LEN");
120+
LOG_WRN("The Memfault device ID will be truncated");
121+
}
122+
123+
memcpy(device_serial, device_id, MIN(sizeof(device_serial) - 1, len));
124+
125+
device_serial[MIN(sizeof(device_serial) - 1, len)] = '\0';
126+
127+
return 0;
128+
}
101129
#endif /* defined(CONFIG_MEMFAULT_DEVICE_INFO_BUILTIN) */
102130

103131
#if defined(CONFIG_MEMFAULT_NCS_DEVICE_ID_IMEI) || defined(CONFIG_MEMFAULT_NCS_DEVICE_ID_NET_MAC)
@@ -152,29 +180,6 @@ static int init(void)
152180
return err;
153181
}
154182

155-
int memfault_ncs_device_id_set(const char *device_id, size_t len)
156-
{
157-
if (!IS_ENABLED(CONFIG_MEMFAULT_NCS_DEVICE_ID_RUNTIME)) {
158-
LOG_ERR("CONFIG_MEMFAULT_NCS_DEVICE_ID_RUNTIME is disabled");
159-
return -ENOTSUP;
160-
}
161-
162-
if (device_id == NULL) {
163-
return -EINVAL;
164-
}
165-
166-
if (len > (sizeof(device_serial) - 1)) {
167-
LOG_ERR("Device ID is longer than CONFIG_MEMFAULT_NCS_DEVICE_ID_MAX_LEN");
168-
LOG_WRN("The Memfault device ID will be truncated");
169-
}
170-
171-
memcpy(device_serial, device_id, MIN(sizeof(device_serial) - 1, len));
172-
173-
device_serial[MIN(sizeof(device_serial) - 1, len)] = '\0';
174-
175-
return 0;
176-
}
177-
178183
#if defined(CONFIG_NRF_MODEM_LIB)
179184
NRF_MODEM_LIB_ON_INIT(memfault_ncs_init_hook, on_modem_lib_init, NULL);
180185

0 commit comments

Comments
 (0)