Skip to content

Commit aa688ab

Browse files
author
Memfault Inc
committed
Memfault Firmware SDK 0.24.2 (Build 294635)
1 parent 1b88521 commit aa688ab

File tree

8 files changed

+280
-32
lines changed

8 files changed

+280
-32
lines changed

CHANGES.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
### Changes between Memfault SDK 0.24.2 and SDK 0.24.1 - August 17, 2021
2+
3+
#### :chart_with_upwards_trend: Improvements
4+
5+
- Added a new utility API, `memfault_packetizer_set_active_sources`, to the
6+
[data_packetizer](components/include/memfault/core/data_packetizer.h) module,
7+
which let's one control the exact data sources that will get packetized. See
8+
description in the header for more details
9+
- Port Improvements:
10+
- NXP i.MX RT102x
11+
- [rich reboot reason info derived from SRC_SRSR register](ports/nxp/rt1021/src_reboot_tracking.c)
12+
113
### Changes between Memfault SDK 0.24.1 and SDK 0.24.0 - August 9, 2021
214

315
#### :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: 290406
2-
GIT COMMIT: e752751b3
1+
BUILD ID: 294635
2+
GIT COMMIT: 0276687c3

components/core/src/memfault_data_packetizer.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,19 @@ typedef enum {
7272
kMfltMessageType_Coredump = 1,
7373
kMfltMessageType_Event = 2,
7474
kMfltMessageType_Log = 3,
75+
kMfltMessageType_NumTypes
7576
} eMfltMessageType;
7677

78+
//! Make sure our externally facing types match the internal ones
79+
MEMFAULT_STATIC_ASSERT((1 << kMfltMessageType_Coredump) == kMfltDataSourceMask_Coredump,
80+
"kMfltDataSourceMask_Coredump is incorrectly defined");
81+
MEMFAULT_STATIC_ASSERT((1 << kMfltMessageType_Event) == kMfltDataSourceMask_Event,
82+
"kMfltDataSourceMask_Event, is incorrectly defined");
83+
MEMFAULT_STATIC_ASSERT((1 << kMfltMessageType_Log) == kMfltDataSourceMask_Log,
84+
"kMfltDataSourceMask_Log is incorrectly defined");
85+
MEMFAULT_STATIC_ASSERT(kMfltMessageType_NumTypes == 4, "eMfltDataSourceMask needs to be updated");
86+
87+
7788
typedef struct MemfaultDataSource {
7889
eMfltMessageType type;
7990
bool use_rle;
@@ -115,6 +126,13 @@ typedef MEMFAULT_PACKED_STRUCT {
115126

116127
static sMfltTransportState s_mflt_packetizer_state;
117128

129+
static eMfltDataSourceMask s_active_data_sources = kMfltDataSourceMask_All;
130+
131+
void memfault_packetizer_set_active_sources(uint32_t mask) {
132+
memfault_packetizer_abort();
133+
s_active_data_sources = mask;
134+
}
135+
118136
static void prv_reset_packetizer_state(void) {
119137
s_mflt_packetizer_state = (sMfltTransportState) {
120138
.active_message = false,
@@ -167,6 +185,13 @@ static void prv_data_source_chunk_transport_msg_reader(uint32_t offset, void *bu
167185
static bool prv_get_source_with_data(size_t *total_size, sMemfaultDataSource *active_source) {
168186
for (size_t i = 0; i < MEMFAULT_ARRAY_SIZE(s_memfault_data_source); i++) {
169187
const sMemfaultDataSource *data_source = &s_memfault_data_source[i];
188+
189+
const bool disabled_source = (((1 << data_source->type) & s_active_data_sources) == 0);
190+
if (disabled_source) {
191+
// sdk user has disabled extraction of data for specified source
192+
continue;
193+
}
194+
170195
const bool rle_enabled = data_source->use_rle &&
171196
memfault_data_source_rle_encoder_set_active(data_source->impl);
172197

components/include/memfault/core/data_packetizer.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,59 @@ eMemfaultPacketizerStatus memfault_packetizer_get_next(void *buf, size_t *buf_le
123123
//!
124124
//! @note This will cause any partially written pieces of data to be re-transmitted in their
125125
//! entirety (i.e coredump)
126+
//! @note This is a no-op when called and memfault_packetizer_get_next() is already returning
127+
//! kMemfaultPacketizerStatus_NoMoreData or memfault_packetizer_get_chunk() is already returning
128+
//! false
126129
void memfault_packetizer_abort(void);
127130

131+
typedef enum {
132+
kMfltDataSourceMask_None = (1 << 0),
133+
134+
// Coredumps recorded when the system crashes
135+
kMfltDataSourceMask_Coredump = (1 << 1),
136+
137+
// All "events" collected by the SDK (reboot, traces, heartbeats)
138+
kMfltDataSourceMask_Event = (1 << 2),
139+
// Any "triggered" log captures: https://mflt.io/logging
140+
kMfltDataSourceMask_Log = (1 << 3),
141+
142+
// A convenience mask which enables all active sources
143+
kMfltDataSourceMask_All =
144+
(kMfltDataSourceMask_Coredump | kMfltDataSourceMask_Event | kMfltDataSourceMask_Log)
145+
} eMfltDataSourceMask;
146+
147+
//! Set the data sources which will be drained by the packetizer
148+
//!
149+
//! @param mask A mask representing the data sources to drain
150+
//!
151+
//! @note By default, all data sources are active.
152+
//!
153+
//! @note This API can be used to prioritize the data source drained from the packetizer.
154+
//! This can be useful for use cases such as:
155+
//! - Devices with multi connectivity toplogies (i.e BLE & WiFi) For example, in this situation a
156+
//! user in this situation could choose to only enable Event and Log transfer when connected to
157+
//! BLE and enable all sources when connected to WiFi
158+
//! - Devices with extended periods where there is no connection to the internet In this
159+
//! situation, an end user may want to store data buffered in RAM (i.e events & logs) on flash
160+
//! to minimize the RAM footprint and prevent data from being lost by an unexpected reset.
161+
//! If an end user is already using a flash region to save coredumps, pre-encoded chunks
162+
//! can of just events can be saved, i.e
163+
//!
164+
//! 1. Only enable draining of events with the following API call:
165+
//! memfault_packetizer_set_active_sources(kMfltDataSourceMask_Event);
166+
//! 2. Using memfault_packetizer_get_chunk() API, now read out events and
167+
//! save to flash or a filesystem (https://mflt.io/data-to-cloud)
168+
//! 3. When a connection becomes available
169+
//! a) send pre-saved chunks from flash over your transport
170+
//! b) call memfault_packetizer_get_chunk() and send data until no more data is available
171+
//! c) re-enable all sources with memfault_packetizer_get_chunk(kMfltDataSourceMask_All) and
172+
//! then call memfault_packetizer_get_chunk() to drain and send any data from other
173+
//! sources that is now available (i.e coredumps)
174+
//!
175+
//! @note Calling this API invokes memfault_packetizer_abort(). This means any in-progress message
176+
//! packetization will be restarted when you next attempt to drain data.
177+
void memfault_packetizer_set_active_sources(uint32_t mask);
178+
128179
#ifdef __cplusplus
129180
}
130181
#endif
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#pragma once
2+
3+
//! @file
4+
//!
5+
//! Contains Memfault SDK version information.
6+
7+
#ifdef __cplusplus
8+
extern "C" {
9+
#endif
10+
11+
#include <stdint.h>
12+
13+
typedef struct {
14+
uint16_t major;
15+
uint16_t minor;
16+
uint16_t patch;
17+
} sMfltSdkVersion;
18+
19+
#define MEMFAULT_SDK_VERSION { .major = 0, .minor = 24, .patch = 2 }
20+
21+
#ifdef __cplusplus
22+
}
23+
#endif

examples/esp32/README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,26 +34,27 @@ Make sure you have read the instructions in the `README.md` in the root of the
3434
SDK and performed the installation steps that are mentioned there.
3535

3636
We assume you have a working setup for the
37-
[v3.3.5 SDK](https://docs.espressif.com/projects/esp-idf/en/v3.3.5/):
37+
[v4.2.2 SDK](https://docs.espressif.com/projects/esp-idf/en/v4.2.2/):
3838

3939
- have a version of CMAKE installed
4040
- installed the xtensa
41-
[toolchain](https://docs.espressif.com/projects/esp-idf/en/v3.3.5/get-started/index.html#setup-toolchain)
41+
[toolchain](https://docs.espressif.com/projects/esp-idf/en/v4.2.2/get-started/index.html#setup-toolchain)
4242
and added it to your path
4343

4444
<a name="adding-memfault"></a>
4545

4646
### Adding Memfault to the ESP-IDF SDK
4747

4848
1. Delete the dummy esp-idf directory (if present) and clone a copy of the
49-
v3.3.5 SDK.
49+
v4.2.2 SDK.
5050

5151
```bash
5252
cd examples/esp32/
5353
rm -rf esp-idf
54-
git clone -b v3.3.5 --recursive https://github.com/espressif/esp-idf.git esp-idf
54+
git clone -b v4.2.2 --recursive https://github.com/espressif/esp-idf.git esp-idf
5555
cd esp-idf
5656
export IDF_TOOLS_PATH=$(pwd)
57+
# you may need to install the sdk tools by running ./install.sh here
5758
source ./export.sh
5859
```
5960

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
//! @file
2+
//!
3+
//! Copyright (c) Memfault, Inc.
4+
//! See License.txt for details
5+
//!
6+
//! A port for recovering reset reason information by reading the "System Reset
7+
//! Controller" (SRC)'s "Reset Status Register" (SRC_SRSR).
8+
//!
9+
//! More details can be found in the chapter "21.8.3 SRC Reset Status Register
10+
//! (SRC_SRSR)" in the RT1021 Reference Manual
11+
12+
#include <inttypes.h>
13+
14+
#include "MIMXRT1021.h"
15+
#include "memfault/components.h"
16+
#include "memfault/ports/reboot_reason.h"
17+
18+
#if MEMFAULT_ENABLE_REBOOT_DIAG_DUMP
19+
#define MEMFAULT_PRINT_RESET_INFO(...) MEMFAULT_LOG_INFO(__VA_ARGS__)
20+
#else
21+
#define MEMFAULT_PRINT_RESET_INFO(...)
22+
#endif
23+
24+
void memfault_reboot_reason_get(sResetBootupInfo *info) {
25+
const uint32_t reset_cause = SRC->SRSR & (SRC_SRSR_W1C_BITS_MASK | SRC_SRSR_TEMPSENSE_RST_B_MASK);
26+
eMemfaultRebootReason reset_reason = kMfltRebootReason_Unknown;
27+
28+
// clear the SRC Reset Status Register by writing a 1 to each bit
29+
#if MEMFAULT_REBOOT_REASON_CLEAR
30+
SRC->SRSR = SRC_SRSR_W1C_BITS_MASK;
31+
#endif
32+
33+
MEMFAULT_LOG_INFO("Reset Reason, SRC_SRSR=0x%" PRIx32, reset_cause);
34+
35+
MEMFAULT_PRINT_RESET_INFO("Reset Cause: ");
36+
if (reset_cause & SRC_SRSR_JTAG_SW_RST_MASK) {
37+
MEMFAULT_PRINT_RESET_INFO(" Software");
38+
reset_reason = kMfltRebootReason_SoftwareReset;
39+
} else if (reset_cause & SRC_SRSR_TEMPSENSE_RST_B_MASK) {
40+
MEMFAULT_PRINT_RESET_INFO(" Temp Sensor");
41+
reset_reason = kMfltRebootReason_UnknownError;
42+
} else if (reset_cause & SRC_SRSR_WDOG3_RST_B_MASK) {
43+
MEMFAULT_PRINT_RESET_INFO(" HW Watchdog3");
44+
reset_reason = kMfltRebootReason_HardwareWatchdog;
45+
} else if (reset_cause & SRC_SRSR_WDOG_RST_B_MASK) {
46+
MEMFAULT_PRINT_RESET_INFO(" HW Watchdog");
47+
// reset_cause can be use to disambiguate the watchdog types
48+
reset_reason = kMfltRebootReason_HardwareWatchdog;
49+
} else if (reset_cause & SRC_SRSR_JTAG_RST_B_MASK) {
50+
MEMFAULT_PRINT_RESET_INFO(" Debugger");
51+
reset_reason = kMfltRebootReason_DebuggerHalted;
52+
} else if (reset_cause & SRC_SRSR_IPP_USER_RESET_B_MASK) {
53+
MEMFAULT_PRINT_RESET_INFO(" Button");
54+
reset_reason = kMfltRebootReason_ButtonReset;
55+
} else if (reset_cause & SRC_SRSR_CSU_RESET_B_MASK) {
56+
// Central Security Unit triggered the reset (see Security Reference
57+
// Manual)
58+
MEMFAULT_PRINT_RESET_INFO(" CSU");
59+
reset_reason = kMfltRebootReason_UnknownError;
60+
} else if (reset_cause & SRC_SRSR_LOCKUP_SYSRESETREQ_MASK) {
61+
MEMFAULT_PRINT_RESET_INFO(" Lockup");
62+
reset_reason = kMfltRebootReason_Lockup;
63+
} else if (reset_cause & SRC_SRSR_IPP_RESET_B_MASK) {
64+
// TODO this might be equivalent to POR...
65+
MEMFAULT_PRINT_RESET_INFO(" Pin Reset");
66+
reset_reason = kMfltRebootReason_PinReset;
67+
} else {
68+
MEMFAULT_PRINT_RESET_INFO(" Unknown");
69+
}
70+
71+
*info = (sResetBootupInfo){
72+
.reset_reason_reg = reset_cause,
73+
.reset_reason = reset_reason,
74+
};
75+
}

0 commit comments

Comments
 (0)