Skip to content

Commit 6f7cc90

Browse files
author
Memfault Inc
committed
Memfault Firmware SDK 1.4.1 (Build 4232)
1 parent 66d6966 commit 6f7cc90

File tree

44 files changed

+385
-102
lines changed

Some content is hidden

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

44 files changed

+385
-102
lines changed

CHANGES.md

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

3+
## [1.4.1] - 2023-10-31
4+
5+
#### :rocket: New Features
6+
7+
- ESP-IDF:
8+
9+
- Add the following built-in heap allocation metrics by default. These can be
10+
disabled with the `CONFIG_MEMFAULT_ESP_HEAP_METRICS` Kconfig flag.
11+
12+
- `heap_free_bytes`
13+
- `heap_largest_free_block_bytes`
14+
- `heap_allocated_blocks_count`
15+
- `heap_min_free_bytes`
16+
17+
- Zephyr:
18+
19+
- Enable capturing [Memfault-style compact logs](https://mflt.io/compact-logs)
20+
on Zephyr systems. Note that this does not enable decoding
21+
[Zephyr "dictionary logs"](https://docs.zephyrproject.org/3.5.0/services/logging/index.html#dictionary-based-logging),
22+
but requires using the Memfault logging APIs directly (i.e.
23+
`MEMFAULT_LOG_INFO("...")` instead of `LOG_INF("...")`).
24+
25+
- General:
26+
27+
- Add a `coredump_size` CLI command to the Zephyr, ESP-IDF, and demo CLI
28+
implementations. This command will print the computed size of the coredump
29+
and the available storage space. Can be used to tune coredump size.
30+
31+
- Enable providing the Memfault HTTP Client with a custom
32+
`memfault_platform_get_device_info()` callback, for when the device is
33+
uploading data for a downstream device, with different device info.
34+
35+
- When [compact logging](https://mflt.io/compact-logs) is enabled, route all
36+
`MEMFAULT_LOG_x()` statements through the compact serializer
37+
(`MEMFAULT_COMPACT_LOG_SAVE`). Previously, logs had to explicitly use the
38+
`MEMFAULT_COMPACT_LOG_SAVE` API to store in the compact form.
39+
40+
- Capture C stdlib `assert.h` asserts, by implementing the correct assert
41+
hooks for Newlib/Picolibc and IAR libc's. This can be disabled with the
42+
Memfault platform config `MEMFAULT_ASSERT_CSTDLIB_HOOK_ENABLED`. This should
43+
improve the Trace quality for systems that are using the C stdlib
44+
`assert(x)` functions.
45+
46+
### :chart_with_upwards_trend: Improvements
47+
348
## [1.4.0] - 2023-10-23
449

550
#### :rocket: New Features

VERSION

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
BUILD ID: 4099
2-
GIT COMMIT: bb1ba895f
3-
VERSION: 1.4.0
1+
BUILD ID: 4232
2+
GIT COMMIT: 3f7cda509f
3+
VERSION: 1.4.1

components/demo/src/memfault_demo_shell_commands.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static const sMemfaultShellCommand s_memfault_shell_commands[] = {
4949
"Export base64-encoded chunks. To upload data see https://mflt.io/chunk-data-export"},
5050
{"get_core", memfault_demo_cli_cmd_get_core, "Get coredump info"},
5151
{"get_device_info", memfault_demo_cli_cmd_get_device_info, "Get device info"},
52-
52+
{"coredump_size", memfault_demo_cli_cmd_coredump_size, "Print the coredump storage capacity"},
5353
//
5454
// Test commands for validating SDK functionality: https://mflt.io/mcu-test-commands
5555
//

components/demo/src/panics/memfault_demo_panics.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@ int memfault_demo_cli_cmd_clear_core(MEMFAULT_UNUSED int argc, MEMFAULT_UNUSED c
112112
return 0;
113113
}
114114

115+
int memfault_demo_cli_cmd_coredump_size(MEMFAULT_UNUSED int argc, MEMFAULT_UNUSED char *argv[]) {
116+
size_t total_size = 0;
117+
size_t capacity = 0;
118+
memfault_coredump_size_and_storage_capacity(&total_size, &capacity);
119+
MEMFAULT_LOG_INFO("Coredump size: %d, capacity: %d", (int)total_size, (int)capacity);
120+
return 0;
121+
}
122+
115123
int memfault_demo_cli_cmd_assert(int argc, char *argv[]) {
116124
// permit running with a user-provided "extra" value for testing that path
117125
if (argc > 1) {

components/http/src/memfault_http_client.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616
#include "memfault/core/errors.h"
1717
#include "memfault/core/platform/device_info.h"
1818
#include "memfault/http/platform/http_client.h"
19+
#include "memfault/http/utils.h"
1920

2021
bool memfault_http_build_url(char url_buffer[MEMFAULT_HTTP_URL_BUFFER_SIZE], const char *subpath) {
2122
sMemfaultDeviceInfo device_info;
22-
memfault_platform_get_device_info(&device_info);
23+
memfault_http_get_device_info(&device_info);
2324

2425

2526
const int rv = snprintf(url_buffer, MEMFAULT_HTTP_URL_BUFFER_SIZE, "%s://%s" MEMFAULT_HTTP_CHUNKS_API_PREFIX "%s/%s",

components/http/src/memfault_http_utils.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ bool memfault_http_start_chunk_post(
9595
// \r\n
9696

9797
sMemfaultDeviceInfo device_info;
98-
memfault_platform_get_device_info(&device_info);
98+
memfault_http_get_device_info(&device_info);
9999

100100
char buffer[100];
101101
const size_t max_msg_len = sizeof(buffer);
@@ -156,7 +156,7 @@ bool memfault_http_get_latest_ota_payload_url(MfltHttpClientSendCb write_callbac
156156
}
157157

158158
sMemfaultDeviceInfo device_info = { 0 };
159-
memfault_platform_get_device_info(&device_info);
159+
memfault_http_get_device_info(&device_info);
160160

161161
#define DEVICE_SERIAL_QPARAM "device_serial"
162162
#define HARDWARE_VERSION_QPARAM "hardware_version"
@@ -708,3 +708,13 @@ int memfault_http_urlencode(const char *inbuf, size_t inbuf_len, char *outbuf, s
708708

709709
return 0;
710710
}
711+
712+
void memfault_http_get_device_info(sMemfaultDeviceInfo *info) {
713+
// Use the user provided callback if available, otherwise use the standard
714+
// platform implementation
715+
if (g_mflt_http_client_config.get_device_info != NULL) {
716+
g_mflt_http_client_config.get_device_info(info);
717+
return;
718+
}
719+
memfault_platform_get_device_info(info); // note: HTTP functions should always call this
720+
}

components/include/memfault/core/log.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ bool memfault_log_boot(void *buffer, size_t buf_len);
6464
//! By default, any logs >= kMemfaultPlatformLogLevel_Info can be saved
6565
void memfault_log_set_min_save_level(eMemfaultPlatformLogLevel min_log_level);
6666

67-
//! Macro which can be called from a platforms pre-existing logging macro.
67+
//! The MEMFAULT_LOG_SAVE macro backs the built-in SDK MEMFAULT_LOG_x logging
68+
//! macros, but can also be called from a platforms pre-existing logging
69+
//! macro.
6870
//!
6971
//! For example, if your platform already has something like this
7072
//!
@@ -79,7 +81,9 @@ void memfault_log_set_min_save_level(eMemfaultPlatformLogLevel min_log_level);
7981
//! MEMFAULT_LOG_SAVE(kMemfaultPlatformLogLevel_Error, __VA_ARGS__);
8082
//! your_platform_log_error(__VA_ARGS__)
8183
//! } while (0)
82-
#define MEMFAULT_LOG_SAVE(_level, ...) memfault_log_save(_level, __VA_ARGS__)
84+
//!
85+
//! The macro will save the log data in the normal or compact form depending on
86+
//! SDK configuration.
8387

8488
#if MEMFAULT_COMPACT_LOG_ENABLE
8589

@@ -96,13 +100,16 @@ void memfault_log_set_min_save_level(eMemfaultPlatformLogLevel min_log_level);
96100
## __VA_ARGS__); \
97101
} while (0)
98102

103+
#define MEMFAULT_LOG_SAVE MEMFAULT_COMPACT_LOG_SAVE
99104

100105
//! Serializes the provided compact log and saves it to backing storage
101106
//!
102107
//! @note: Should only be called via MEMFAULT_COMPACT_LOG_SAVE macro
103108
void memfault_compact_log_save(eMemfaultPlatformLogLevel level, uint32_t log_id,
104109
uint32_t compressed_fmt, ...);
105110

111+
#else // !MEMFAULT_COMPACT_LOG_ENABLE
112+
#define MEMFAULT_LOG_SAVE(_level, ...) memfault_log_save(_level, __VA_ARGS__)
106113
#endif /* MEMFAULT_COMPACT_LOG_ENABLE */
107114

108115
//! Function which can be called to save a log after it has been formatted

components/include/memfault/default_config.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ extern "C" {
5252
#define MEMFAULT_ASSERT_HALT_IF_DEBUGGING_ENABLED 0
5353
#endif
5454

55+
//! Install a low-level hook into the C stdlib assert() library call, to capture
56+
//! coredumps when asserts occur.
57+
#ifndef MEMFAULT_ASSERT_CSTDLIB_HOOK_ENABLED
58+
#define MEMFAULT_ASSERT_CSTDLIB_HOOK_ENABLED 1
59+
#endif
60+
5561
//! Controls whether or not device serial is encoded in events
5662
//!
5763
//! When disabled (default), the device serial is derived from the API route

components/include/memfault/demo/cli.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ int memfault_demo_cli_cmd_post_core(int argc, char *argv[]);
8484
//! It takes no arguments.
8585
int memfault_demo_cli_cmd_clear_core(int argc, char *argv[]);
8686

87+
//! Print coredump size and storage capacity
88+
int memfault_demo_cli_cmd_coredump_size(int argc, char *argv[]);
89+
8790
//! Command to print device info, as obtained through memfault_platform_get_device_info().
8891
//! It takes no arguments.
8992
int memfault_demo_cli_cmd_get_device_info(int argc, char *argv[]);

components/include/memfault/http/http_client.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "memfault/config.h"
1616
#include "memfault/core/compiler.h"
17+
#include "memfault/core/platform/device_info.h"
1718

1819
#define MEMFAULT_HTTP_URL_BUFFER_SIZE (128)
1920

@@ -45,12 +46,28 @@ typedef struct MfltHttpClientConfig {
4546
//! Route used to get information from the Memfault cloud pertaining to a device in your fleet.
4647
//! For example, the latest firmware release available.
4748
sMemfaultHttpApi device_api;
49+
//! Callback for fetching device info for the OTA'ing device. Typically this callback can be left unset, but
50+
//! if the request is on behalf of a downstream device, can be substituted with the downstream
51+
//! device's information.
52+
//! The function signature is the same as memfault_platform_get_device_info().
53+
//! If NULL, memfault_platform_get_device_info() will be used.
54+
void (*get_device_info)(sMemfaultDeviceInfo *info);
4855
} sMfltHttpClientConfig;
4956

5057
//! Global configuration of the Memfault HTTP client.
5158
//! See @ref sMfltHttpClientConfig for information about each of the fields.
5259
extern sMfltHttpClientConfig g_mflt_http_client_config;
5360

61+
//! If on a GNUC-compatible compiler, perform a type-compatibility check with
62+
//! the get_device_info callback. This will fail to compile if the callback
63+
//! signature does not match the expected signature.
64+
#if defined(__GNUC__) && !defined(__cplusplus)
65+
MEMFAULT_STATIC_ASSERT(
66+
__builtin_types_compatible_p(__typeof__(g_mflt_http_client_config.get_device_info),
67+
__typeof__(&memfault_platform_get_device_info)),
68+
"get_device_info callback signature does not match expected signature");
69+
#endif
70+
5471
//! Convenience macros to get the currently configured Chunks API hostname & Port
5572
#define MEMFAULT_HTTP_GET_CHUNKS_API_HOST() \
5673
(g_mflt_http_client_config.chunks_api.host ? g_mflt_http_client_config.chunks_api.host : \

0 commit comments

Comments
 (0)