Skip to content

Commit 246a21e

Browse files
author
Memfault Inc
committed
Memfault Firmware SDK 1.3.4 (Build 3914)
1 parent c374e92 commit 246a21e

File tree

14 files changed

+508
-156
lines changed

14 files changed

+508
-156
lines changed

CHANGES.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,31 @@
11
# Memfault Firmware SDK Changelog
22

3+
## [1.3.4] - 2023-10-12
4+
5+
### :chart_with_upwards_trend: Improvements
6+
7+
- ESP-IDF:
8+
9+
- Add a missing dependency to the `memfault` component, `esp_https_ota`. It's
10+
only linked into the target project if the `memfault_esp_port_ota_update()`
11+
API is used. This was previously an implicit dependency from the `common`
12+
component dependencies, when building `memfault` into an ESP-IDF
13+
component-style project. This change fixes building for non-component-style
14+
ESP-IDF projects, where the default component dependencies might not be
15+
included.
16+
17+
- Multiple changes to the
18+
[`examples/esp32`](examples/esp32/apps/memfault_demo_app) sample project:
19+
20+
- Add a new `coredump_size` shell command, which prints out the maximum
21+
coredump size and the available coredump storage capacity.
22+
- Add new `settings_[get|set]` shell commands, and enable setting the LED
23+
brightness and blink interval to NVS. This is intended as a minor
24+
quality-of-life change for internal Memfault users of the example app.
25+
26+
- Fix a build error in the public unit tests, caused by the recent addition of
27+
the `-fanalyzer` flag to the unit test compilation options.
28+
329
## 1.3.3 - Oct 10, 2023
430

531
### :chart_with_upwards_trend: Improvements

VERSION

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
BUILD ID: 3838
2-
GIT COMMIT: 86077d06f
3-
VERSION: 1.3.3
1+
BUILD ID: 3914
2+
GIT COMMIT: 18179b7fb
3+
VERSION: 1.3.4

components/include/memfault/version.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ typedef struct {
1919
uint8_t patch;
2020
} sMfltSdkVersion;
2121

22-
#define MEMFAULT_SDK_VERSION { .major = 1, .minor = 3, .patch = 3 }
23-
#define MEMFAULT_SDK_VERSION_STR "1.3.3"
22+
#define MEMFAULT_SDK_VERSION { .major = 1, .minor = 3, .patch = 4 }
23+
#define MEMFAULT_SDK_VERSION_STR "1.3.4"
2424

2525
#ifdef __cplusplus
2626
}

components/metrics/src/memfault_metrics.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,13 @@ typedef enum {
479479
static bool prv_update_timer_metric(const sMemfaultMetricValueInfo *value_info,
480480
eMemfaultTimerOp op) {
481481
sMemfaultMetricValueMetadata *meta_datap = value_info->meta_datap;
482+
#if defined(MEMFAULT_UNITTEST)
483+
// It's a programming error if we reach this point and meta_datap is NULL. It
484+
// should always be valid for a timer metric class. Use c stdlib assert to
485+
// prevent the static analyzer from triggering below.
486+
#include <assert.h>
487+
assert(meta_datap != NULL);
488+
#endif
482489
const bool timer_running = meta_datap->is_running;
483490

484491
// The timer is not running _and_ we received a Start request

examples/esp32/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,18 @@ occupied. Typically coredumps are cleared once they have been posted to the
240240
memfault cloud by using the `memfault_platform_coredump_storage_clear` function.
241241
You can invoke this command from the cli by running `clear_core`.
242242

243+
### Checking coredump storage capacity
244+
245+
Memfault coredumps will be written to the `coredump` partition by default. Use
246+
the `coredump_size` command to see the computed maximum coredump size, and the
247+
available storage capacity:
248+
249+
```bash
250+
esp32> coredump_size
251+
coredump storage capacity: 262144B
252+
coredump size required: 456988B
253+
```
254+
243255
### Testing OTA
244256

245257
The following steps can be used to exercise OTA functionality:

examples/esp32/apps/memfault_demo_app/main/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ list(APPEND
44
cmd_system.c
55
console_example_main.c
66
led.c
7+
settings.c
78
)
89

910
if (CONFIG_APP_MEMFAULT_TRANSPORT_HTTP)

examples/esp32/apps/memfault_demo_app/main/cmd_app.c

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "esp_log.h"
1515
#include "freertos/FreeRTOS.h"
1616
#include "freertos/semphr.h"
17+
#include "memfault/components.h"
1718
#include "sdkconfig.h"
1819

1920
//! cause the task watchdog to fire by deadlocking the example task
@@ -26,16 +27,31 @@ static int test_task_watchdog(int argc, char** argv) {
2627
return 0;
2728
}
2829

29-
static void register_test_task_watchdog(void) {
30-
const esp_console_cmd_t cmd = {
30+
static int prv_coredump_size(int argc, char** argv) {
31+
(void)argc, (void)argv;
32+
33+
sMfltCoredumpStorageInfo storage_info = {0};
34+
memfault_platform_coredump_storage_get_info(&storage_info);
35+
const size_t size_needed = memfault_coredump_storage_compute_size_required();
36+
printf("coredump storage capacity: %zuB\n", storage_info.size);
37+
printf("coredump size required: %zuB\n", size_needed);
38+
return 0;
39+
}
40+
41+
void register_app(void) {
42+
const esp_console_cmd_t test_watchdog_cmd = {
3143
.command = "test_task_watchdog",
3244
.help = "Demonstrate the task watchdog tripping on a deadlock",
3345
.hint = NULL,
3446
.func = &test_task_watchdog,
3547
};
36-
ESP_ERROR_CHECK(esp_console_cmd_register(&cmd));
37-
}
48+
ESP_ERROR_CHECK(esp_console_cmd_register(&test_watchdog_cmd));
3849

39-
void register_app(void) {
40-
register_test_task_watchdog();
50+
const esp_console_cmd_t coredump_size_cmd = {
51+
.command = "coredump_size",
52+
.help = "Print the coredump storage capacity and the capacity required",
53+
.hint = NULL,
54+
.func = &prv_coredump_size,
55+
};
56+
ESP_ERROR_CHECK(esp_console_cmd_register(&coredump_size_cmd));
4157
}

examples/esp32/apps/memfault_demo_app/main/cmd_wifi.c

Lines changed: 15 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
#include "esp_wifi.h"
1717
#include "freertos/FreeRTOS.h"
1818
#include "freertos/event_groups.h"
19-
#include "nvs.h"
20-
#include "nvs_flash.h"
19+
#include "settings.h"
2120

2221
// enable for more verbose debug logs
2322
#define LOG_LOCAL_LEVEL ESP_LOG_DEBUG
@@ -180,71 +179,23 @@ static int connect(int argc, char **argv) {
180179
return 0;
181180
}
182181

183-
static esp_err_t prv_open_nvs(nvs_handle_t* nvs_handle) {
184-
// Initialize NVS
185-
esp_err_t err = nvs_flash_init();
186-
if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
187-
// NVS partition was truncated and needs to be erased
188-
// Retry nvs_flash_init
189-
ESP_ERROR_CHECK(nvs_flash_erase());
190-
err = nvs_flash_init();
191-
}
192-
ESP_ERROR_CHECK(err);
193-
194-
// Open
195-
err = nvs_open("storage", NVS_READWRITE, nvs_handle);
196-
if (err != ESP_OK) {
197-
ESP_LOGE(__func__, "Error (%s) opening NVS handle!", esp_err_to_name(err));
198-
return err;
199-
}
200-
201-
return ESP_OK;
202-
}
203-
204182
//! Since the creds are set via cli, we can safely assume there's no null bytes
205183
//! in the password, despite being theoretically permissible by the spec
206184
static void prv_save_wifi_creds(const char* ssid, const char* password) {
207-
// Initialize NVS
208-
nvs_handle_t nvs_handle;
209-
esp_err_t err = prv_open_nvs(&nvs_handle);
185+
// length arg is ignored for string-type settings
186+
esp_err_t err = settings_set(kSettingsWifiSsid, ssid, 0);
210187
if (err != ESP_OK) {
211-
ESP_LOGE(__func__, "Error (%s) opening NVS handle!", esp_err_to_name(err));
212-
return;
188+
ESP_LOGE(__func__, "Error (%s) writing ssid to NVS!", esp_err_to_name(err));
213189
}
214-
215-
ESP_LOGD(__func__, "Opened NVS handle");
216-
217-
// Write
218-
err = nvs_set_str(nvs_handle, "wifi_ssid", ssid);
190+
err = settings_set(kSettingsWifiPassword, password, 0);
219191
if (err != ESP_OK) {
220-
ESP_LOGE(__func__, "Error (%s) writing ssid to NVS!", esp_err_to_name(err));
221-
} else {
222-
ESP_LOGD(__func__, "Wrote ssid to NVS");
192+
ESP_LOGE(__func__, "Error (%s) writing password to NVS!", esp_err_to_name(err));
223193
}
224-
err = nvs_set_str(nvs_handle, "wifi_password", password);
225194
if (err == ESP_OK) {
226-
if (err != ESP_OK) {
227-
ESP_LOGE(__func__, "Error (%s) writing password to NVS!", esp_err_to_name(err));
228-
} else {
229-
ESP_LOGD(__func__, "Wrote password to NVS");
230-
}
231-
}
232-
233-
// Commit written value.
234-
// After setting any values, nvs_commit() must be called to ensure changes are written
235-
// to flash storage. Implementations may write to storage at other times,
236-
// but this is not guaranteed.
237-
err = nvs_commit(nvs_handle);
238-
if (err != ESP_OK) {
239-
ESP_LOGE(__func__, "Error (%s) committing NVS!", esp_err_to_name(err));
240-
} else {
241195
ESP_LOGD(__func__, "Successfully saved new wifi creds");
242196
strncpy(s_wifi_ssid, ssid, sizeof(s_wifi_ssid) - 1);
243197
strncpy(s_wifi_pass, password, sizeof(s_wifi_pass) - 1);
244198
}
245-
246-
// Close
247-
nvs_close(nvs_handle);
248199
}
249200

250201
//! Return ssid + password pointers, or NULL if not found
@@ -260,41 +211,23 @@ void wifi_load_creds(char** ssid, char** password) {
260211
*ssid = NULL;
261212
*password = NULL;
262213

263-
// Initialize NVS
264-
nvs_handle_t nvs_handle;
265-
esp_err_t err = prv_open_nvs(&nvs_handle);
266-
if (err != ESP_OK) {
267-
ESP_LOGE(__func__, "Error (%s) opening NVS handle!", esp_err_to_name(err));
268-
return;
269-
}
270-
271-
ESP_LOGD(__func__, "Opened NVS handle");
272-
273-
// Read
274214
ESP_LOGD(__func__, "Reading wifi creds ... ");
275215
size_t len = sizeof(s_wifi_ssid);
276-
err = nvs_get_str(nvs_handle, "wifi_ssid", s_wifi_ssid, &len);
277-
if (err == ESP_OK) {
278-
ESP_LOGD(__func__, "ssid size: %d", len);
279-
} else {
216+
esp_err_t err = settings_get(kSettingsWifiSsid, s_wifi_ssid, &len);
217+
if (err != ESP_OK) {
280218
ESP_LOGE(__func__, "failed reading ssid");
281-
goto close;
219+
return;
282220
}
283221

284222
len = sizeof(s_wifi_pass);
285-
err = nvs_get_str(nvs_handle, "wifi_password", s_wifi_pass, &len);
286-
if (err == ESP_OK) {
287-
ESP_LOGD(__func__, "pw size: %d", len);
288-
} else {
223+
err = settings_get(kSettingsWifiPassword, s_wifi_pass, &len);
224+
if (err != ESP_OK) {
289225
ESP_LOGE(__func__, "failed reading pw");
290-
goto close;
226+
return;
291227
}
292228

293229
*ssid = s_wifi_ssid;
294230
*password = s_wifi_pass;
295-
296-
close:
297-
nvs_close(nvs_handle);
298231
}
299232

300233
// argtable3 requires this data structure to be valid through the entire command
@@ -353,29 +286,8 @@ __attribute__((access(write_only, 1, 2))) int wifi_get_project_key(char* project
353286
MEMFAULT_PROJECT_KEY_LEN + 1);
354287
return 1;
355288
}
356-
357-
// Initialize NVS
358-
nvs_handle_t nvs_handle;
359-
esp_err_t err = prv_open_nvs(&nvs_handle);
360-
if (err != ESP_OK) {
361-
ESP_LOGE(__func__, "Error (%s) opening NVS handle!", esp_err_to_name(err));
362-
return err;
363-
}
364-
365-
ESP_LOGD(__func__, "Opened NVS handle");
366-
367-
// load the project key, if it exists
368-
size_t len = project_key_len + 1;
369-
err = nvs_get_str(nvs_handle, "project_key", project_key, &len);
370-
if (err == ESP_OK) {
371-
ESP_LOGD(__func__, "project key size: %d", len);
372-
} else {
373-
ESP_LOGE(__func__, "failed reading project key %d", err);
374-
}
375-
376-
nvs_close(nvs_handle);
377-
378-
return err;
289+
size_t len = project_key_len;
290+
return settings_get(kSettingsProjectKey, project_key, &len);
379291
}
380292

381293
__attribute__((access(read_only, 1, 2))) static esp_err_t prv_set_project_key(
@@ -384,39 +296,7 @@ __attribute__((access(read_only, 1, 2))) static esp_err_t prv_set_project_key(
384296
assert((project_key_len == MEMFAULT_PROJECT_KEY_LEN) &&
385297
(strlen(project_key) == MEMFAULT_PROJECT_KEY_LEN));
386298

387-
// Initialize NVS
388-
nvs_handle_t nvs_handle;
389-
esp_err_t err = prv_open_nvs(&nvs_handle);
390-
if (err != ESP_OK) {
391-
ESP_LOGE(__func__, "Error (%s) opening NVS handle!", esp_err_to_name(err));
392-
return err;
393-
}
394-
395-
ESP_LOGD(__func__, "Opened NVS handle");
396-
397-
// Write
398-
err = nvs_set_str(nvs_handle, "project_key", project_key);
399-
if (err != ESP_OK) {
400-
ESP_LOGE(__func__, "Error (%s) writing project key to NVS!", esp_err_to_name(err));
401-
} else {
402-
ESP_LOGD(__func__, "Wrote project key to NVS");
403-
}
404-
405-
// Commit written value.
406-
// After setting any values, nvs_commit() must be called to ensure changes are written
407-
// to flash storage. Implementations may write to storage at other times,
408-
// but this is not guaranteed.
409-
err = nvs_commit(nvs_handle);
410-
if (err != ESP_OK) {
411-
ESP_LOGE(__func__, "Error (%s) committing NVS!", esp_err_to_name(err));
412-
} else {
413-
ESP_LOGD(__func__, "Successfully saved new project key");
414-
}
415-
416-
// Close
417-
nvs_close(nvs_handle);
418-
419-
return err;
299+
return settings_set(kSettingsProjectKey, project_key, project_key_len);
420300
}
421301

422302
static int project_key_set(int argc, char** argv) {

examples/esp32/apps/memfault_demo_app/main/console_example_main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "memfault/esp_port/version.h"
3434
#include "nvs.h"
3535
#include "nvs_flash.h"
36+
#include "settings.h"
3637

3738
static const char *TAG = "example";
3839

@@ -363,6 +364,7 @@ void app_main() {
363364
register_system();
364365
register_wifi();
365366
register_app();
367+
settings_register_shell_commands();
366368

367369
// Attempt to load project key from nvs
368370
static char project_key[MEMFAULT_PROJECT_KEY_LEN + 1] = {0};

0 commit comments

Comments
 (0)