Skip to content

Commit a1e2c82

Browse files
author
Memfault Inc
committed
Memfault Firmware SDK 1.1.0 (Build 2706)
1 parent 0e579c2 commit a1e2c82

File tree

49 files changed

+1328
-114
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1328
-114
lines changed

.cyignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ ports/dialog
99
ports/emlib
1010
ports/esp8266_sdk
1111
ports/esp_idf
12+
ports/freertos/src/memfault_sdk_metrics_freertos.c
13+
ports/lwip
1214
ports/mbedtls
1315
ports/mynewt
1416
ports/nrf5_sdk

CHANGES.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,44 @@
1+
### Changes between Memfault SDK 1.0.1 and 1.1.0 - June 29, 2023
2+
3+
#### :chart_with_upwards_trend: Improvements
4+
5+
- New built-in metrics 🎉 !
6+
7+
- FreeRTOS Idle Task runtime percentage metric: `idle_task_run_time_percent`.
8+
This is automatically enabled for FreeRTOS builds with the correct tracing
9+
options enabled, see
10+
[ports/include/memfault/ports/freertos/metrics.h](ports/include/memfault/ports/freertos/metrics.h)
11+
for details on how to enable or disable this metric.
12+
- MbedTLS metrics for maximum and current memory used: `mbedtls_mem_max_bytes`
13+
and `mbedtls_mem_used_bytes`. These are automatically enabled for ESP-IDF
14+
projects, see
15+
[ports/mbedtls/memfault_mbedtls_metrics.c](ports/mbedtls/memfault_mbedtls_metrics.c)
16+
for usage details
17+
- Renamed the built-in LwIP metrics added in SDK version 1.0.1 from
18+
`Tcp_Drop_Count`/`Tcp_Rx_Count`/`Tcp_Tx_Count`,
19+
`Udp_Drop_Count`/`Udp_Rx_Count`/`Udp_Tx_Count` to be all lowercase
20+
`tcp_drop_count`/`tcp_rx_count`/`tcp_tx_count`,
21+
`udp_drop_count`/`udp_rx_count`/`udp_tx_count`
22+
- Add the following automatically enabled WiFi performance metrics to the
23+
ESP-IDF port:
24+
- `wifi_connected_time_ms`
25+
- `wifi_disconnect_count`
26+
- `wifi_sta_min_rssi`
27+
28+
- Fix a bug in the [mbedtls port](ports/mbedtls/) causing an infinite loop under
29+
certain error conditions on TLS handshake
30+
31+
- Zephyr:
32+
33+
- Improve log flushing in the Memfault log backend during fault when deferred
34+
logging is enabled. This ensures the latest log statements are included in
35+
the coredump log data, when the `CONFIG_MEMFAULT_LOGGING_ENABLE=y`
36+
37+
- ESP-IDF:
38+
39+
- `ESP_ERROR_CHECK()` assert coredumps will now correctly show as assert in
40+
the Memfault coredump analysis view, instead of "Hard Fault"
41+
142
### Changes between Memfault SDK 1.0.1 and 1.0.0 - June 9, 2023
243

344
#### :chart_with_upwards_trend: Improvements

VERSION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
BUILD ID: 2436
2-
GIT COMMIT: 6273359e7
1+
BUILD ID: 2706
2+
GIT COMMIT: 81c373788

components/core/src/memfault_log.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -374,18 +374,18 @@ void memfault_log_save(eMemfaultPlatformLogLevel level, const char *fmt, ...) {
374374
va_end(args);
375375
}
376376

377-
static void prv_log_save(eMemfaultPlatformLogLevel level,
378-
const void *log, size_t log_len,
379-
eMemfaultLogRecordType log_type) {
380-
377+
static void prv_log_save(eMemfaultPlatformLogLevel level, const void *log, size_t log_len,
378+
eMemfaultLogRecordType log_type, bool should_lock) {
381379
if (!prv_should_log(level)) {
382380
return;
383381
}
384382

385383
bool log_written = false;
386384
const size_t truncated_log_len = MEMFAULT_MIN(log_len, MEMFAULT_LOG_MAX_LINE_SAVE_LEN);
387385
const size_t bytes_needed = sizeof(sMfltRamLogEntry) + truncated_log_len;
388-
memfault_lock();
386+
if (should_lock) {
387+
memfault_lock();
388+
}
389389
{
390390
sMfltCircularBuffer *circ_bufp = &s_memfault_ram_logger.circ_buffer;
391391
const bool space_free = prv_try_free_space(circ_bufp, (int)bytes_needed);
@@ -399,7 +399,9 @@ static void prv_log_save(eMemfaultPlatformLogLevel level,
399399
log_written = true;
400400
}
401401
}
402-
memfault_unlock();
402+
if (should_lock) {
403+
memfault_unlock();
404+
}
403405

404406
if (log_written) {
405407
memfault_log_handle_saved_callback();
@@ -426,15 +428,20 @@ void memfault_compact_log_save(eMemfaultPlatformLogLevel level, uint32_t log_id,
426428
}
427429

428430
const size_t bytes_written = memfault_cbor_encoder_deinit(&encoder);
429-
prv_log_save(level, log_buf, bytes_written, kMemfaultLogRecordType_Compact);
431+
prv_log_save(level, log_buf, bytes_written, kMemfaultLogRecordType_Compact, true);
430432
}
431433

432434
#endif /* MEMFAULT_COMPACT_LOG_ENABLE */
433435

434436

435437
void memfault_log_save_preformatted(eMemfaultPlatformLogLevel level,
436438
const char *log, size_t log_len) {
437-
prv_log_save(level, log, log_len, kMemfaultLogRecordType_Preformatted);
439+
prv_log_save(level, log, log_len, kMemfaultLogRecordType_Preformatted, true);
440+
}
441+
442+
void memfault_log_save_preformatted_nolock(eMemfaultPlatformLogLevel level, const char *log,
443+
size_t log_len) {
444+
prv_log_save(level, log, log_len, kMemfaultLogRecordType_Preformatted, false);
438445
}
439446

440447
bool memfault_log_boot(void *storage_buffer, size_t buffer_len) {

components/include/memfault/core/compiler_gcc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ extern "C" {
3838
#define MEMFAULT_USED __attribute__((used))
3939
#define MEMFAULT_WEAK __attribute__((weak))
4040
#define MEMFAULT_PRINTF_LIKE_FUNC(a, b) __attribute__ ((format (__printf__, a, b)))
41+
#define MEMFAULT_ALIGNOF(x) (__alignof__(x))
4142

4243
//! From https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html,
4344
//! If x is 0, the result is undefined.

components/include/memfault/core/log.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ void memfault_compact_log_save(eMemfaultPlatformLogLevel level, uint32_t log_id,
121121
void memfault_log_save_preformatted(eMemfaultPlatformLogLevel level, const char *log,
122122
size_t log_len);
123123

124+
//! As above, but do not acquire a lock internally.
125+
void memfault_log_save_preformatted_nolock(eMemfaultPlatformLogLevel level, const char *log,
126+
size_t log_len);
127+
124128
typedef enum {
125129
kMemfaultLogRecordType_Preformatted = 0,
126130
kMemfaultLogRecordType_Compact = 1,
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//! @file
2+
//!
3+
//! Copyright (c) Memfault, Inc.
4+
//! See License.txt for details
5+
#pragma once
6+
7+
#ifdef __cplusplus
8+
extern "C" {
9+
#endif
10+
11+
#include <stddef.h>
12+
#include <stdint.h>
13+
14+
#include "memfault/core/compiler.h"
15+
#include "memfault/core/math.h"
16+
#include "memfault/core/sdk_assert.h"
17+
18+
// C99 does not have a max_align_t type, so we use a union
19+
// of types with the largest alignments to determine max align
20+
// Taken from
21+
// https://github.com/zephyrproject-rtos/zephyr/blob/bfa0a87277c31d9e1b36104a29b17f3fc1a47444/include/zephyr/types.h#L22-L30
22+
typedef union {
23+
long long thelonglong;
24+
long double thelongdouble;
25+
uintmax_t theuintmax_t;
26+
size_t thesize_t;
27+
uintptr_t theuintptr_t;
28+
void *thepvoid;
29+
void (*thepfunc)(void);
30+
} uMemfaultMaxAlignType;
31+
32+
#if !defined(MEMFAULT_ALIGNOF)
33+
#error \
34+
"Compiler has no __alignof__ or equivalent extension. Please disable MEMFAULT_MBEDTLS_METRICS or contact support"
35+
#endif // !defined(MEMFAULT_ALIGN)
36+
37+
// Allow override for tests
38+
#if !defined(MEMFAULT_MAX_ALIGN_SIZE)
39+
#define MEMFAULT_MAX_ALIGN_SIZE (MEMFAULT_ALIGNOF(uMemfaultMaxAlignType))
40+
#endif // !defined(MEMFAULT_MAX_ALIGN_SIZE)
41+
42+
#ifdef __cplusplus
43+
}
44+
#endif

components/include/memfault/version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ typedef struct {
1919
uint8_t patch;
2020
} sMfltSdkVersion;
2121

22-
#define MEMFAULT_SDK_VERSION { .major = 1, .minor = 0, .patch = 1 }
22+
#define MEMFAULT_SDK_VERSION { .major = 1, .minor = 1, .patch = 0 }
2323

2424
#ifdef __cplusplus
2525
}

examples/esp32/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Memfault for ESP32
22

3-
This example application shows an integration with the ESP-IDF v4.2.2 SDK where
3+
This example application shows an integration with the ESP-IDF v5.0.2 SDK where
44
a saved coredump is posted to the Memfault cloud for analysis.
55

6-
If you already have an ESP-IDF project based on the v4.x or v3.x SDK, a step by
6+
If you already have an ESP-IDF project based on the v5.x, v4.x, or v3.x SDK, a step by
77
step getting started guide can be found [here](https://mflt.io/esp-tutorial).
88

99
The Memfault SDK has been tested to be compatible with these versions of
@@ -43,24 +43,24 @@ Make sure you have read the instructions in the `README.md` in the root of the
4343
SDK and performed the installation steps that are mentioned there.
4444

4545
We assume you have a working setup for the
46-
[v4.2.2 SDK](https://docs.espressif.com/projects/esp-idf/en/v4.2.2/):
46+
[v5.0.2 SDK](https://docs.espressif.com/projects/esp-idf/en/v5.0.2/):
4747

4848
- have a version of CMAKE installed
4949
- installed the xtensa
50-
[toolchain](https://docs.espressif.com/projects/esp-idf/en/v4.2.2/get-started/index.html#setup-toolchain)
50+
[toolchain](https://docs.espressif.com/projects/esp-idf/en/v5.0.2/get-started/index.html#setup-toolchain)
5151
and added it to your path
5252

5353
<a name="adding-memfault"></a>
5454

5555
### Adding Memfault to the ESP-IDF SDK
5656

5757
1. Delete the dummy esp-idf directory (if present) and clone a copy of the
58-
v4.2.2 SDK.
58+
v5.0.2 SDK.
5959

6060
```bash
6161
cd examples/esp32/
6262
rm -rf esp-idf
63-
git clone -b v4.2.4 --recursive https://github.com/espressif/esp-idf.git esp-idf
63+
git clone -b v5.0.2 --recursive https://github.com/espressif/esp-idf.git esp-idf
6464
cd esp-idf
6565
export IDF_TOOLS_PATH=$(pwd)
6666
# you may need to install the sdk tools by running ./install.sh here

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ bool wifi_join(const char *ssid, const char *pass) {
9797

9898
ESP_ERROR_CHECK(esp_netif_init());
9999

100-
ESP_ERROR_CHECK(esp_event_loop_create_default());
100+
ESP_ERROR_CHECK_WITHOUT_ABORT(esp_event_loop_create_default());
101101
esp_netif_create_default_wifi_sta();
102102

103103
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
@@ -151,6 +151,10 @@ bool wifi_join(const char *ssid, const char *pass) {
151151
return false;
152152
}
153153

154+
static int wifi_disconnect() {
155+
return esp_wifi_disconnect();
156+
}
157+
154158
/** Arguments used by 'join' function */
155159
static struct {
156160
struct arg_str *ssid;
@@ -355,4 +359,11 @@ void register_wifi(void) {
355359
.func = &wifi_creds_set,
356360
.argtable = &wifi_creds_args};
357361
ESP_ERROR_CHECK(esp_console_cmd_register(&config_cmd));
362+
363+
const esp_console_cmd_t disconnect_cmd = {.command = "wifi_disconnect",
364+
.help = "Disconnect from WiFi AP",
365+
.hint = NULL,
366+
.func = &wifi_disconnect,
367+
.argtable = NULL};
368+
ESP_ERROR_CHECK(esp_console_cmd_register(&disconnect_cmd));
358369
}

0 commit comments

Comments
 (0)