Skip to content

Commit 79611f2

Browse files
author
Memfault Inc
committed
Memfault Firmware SDK 0.43.1 (Build 2030)
1 parent b94e256 commit 79611f2

File tree

13 files changed

+107
-50
lines changed

13 files changed

+107
-50
lines changed

CHANGES.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
### Changes between Memfault SDK 0.43.1 and 0.43.0 - April 26, 2023
2+
3+
#### :chart_with_upwards_trend: Improvements
4+
5+
- Zephyr:
6+
7+
- The `z_NmiHandlerSet` function is renamed for the upcoming Zephyr 3.4.
8+
Support the new name. Fixes
9+
[#49](https://github.com/memfault/memfault-firmware-sdk/issues/49). Thanks
10+
@mbolivar-nordic for filing this issue!
11+
112
### Changes between Memfault SDK 0.43.0 and 0.42.1 - April 18, 2023
213

314
#### :rocket: New Features

VERSION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
BUILD ID: 1963
2-
GIT COMMIT: bcb826788
1+
BUILD ID: 2030
2+
GIT COMMIT: 6bca4dee8

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 = 0, .minor = 43, .patch = 0 }
22+
#define MEMFAULT_SDK_VERSION { .major = 0, .minor = 43, .patch = 1 }
2323

2424
#ifdef __cplusplus
2525
}

examples/nrf-connect-sdk/nrf5/memfault_demo_app/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
cmake_minimum_required(VERSION 3.20.0)
44

5+
# The default board for this example is the nrf52840dk_nrf52840, but can be
6+
# overridden by passing --board=<board> to west or -DBOARD=<board> to cmake
7+
set(BOARD nrf52840dk_nrf52840)
8+
59
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
610
project(fs_shell)
711

examples/nrf-connect-sdk/nrf5/memfault_demo_app/Kconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11

22
menu "MEMFAULT_APP"
33

4+
# Set Memfault fw_version to the same as the mcuboot image version
5+
config MEMFAULT_NCS_FW_VERSION
6+
default MCUBOOT_IMAGE_VERSION
7+
48
config MEMFAULT_APP_CAPTURE_ALL_RAM
59
bool "Capture all RAM"
610
help

examples/nrf-connect-sdk/nrf5/memfault_demo_app/prj.conf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ CONFIG_MEMFAULT_NCS_DEVICE_ID_RUNTIME=y
2222
CONFIG_MEMFAULT_NCS_HW_VERSION="a"
2323
CONFIG_MEMFAULT_NCS_FW_TYPE="nrf52_example"
2424
CONFIG_MEMFAULT_NCS_FW_VERSION_STATIC=y
25-
CONFIG_MEMFAULT_NCS_FW_VERSION="0.0.1"
25+
# Note: MEMFAULT_NCS_FW_VERSION is set from this in the project Kconfig
26+
CONFIG_MCUBOOT_IMAGE_VERSION="0.0.1"
2627

2728
# Enable and configure logging
2829
CONFIG_LOG=y

ports/zephyr/common/memfault_platform_coredump_regions.c

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,41 +15,30 @@
1515
#include "memfault/ports/zephyr/version.h"
1616

1717
#if MEMFAULT_ZEPHYR_VERSION_GT(2, 1)
18-
#include <arch/arm/aarch32/cortex_m/cmsis.h>
18+
#include <arch/arm/aarch32/cortex_m/cmsis.h>
1919
#else
20-
#include <arch/arm/cortex_m/cmsis.h>
20+
#include <arch/arm/cortex_m/cmsis.h>
2121
#endif
2222

2323
#include "memfault/core/compiler.h"
2424
#include "memfault/core/math.h"
2525
#include "memfault/ports/zephyr/coredump.h"
2626

27-
static sMfltCoredumpRegion s_coredump_regions[
28-
MEMFAULT_COREDUMP_MAX_TASK_REGIONS
29-
+ 2 /* active stack(s) */
30-
+ 1 /* _kernel variable */
31-
+ 1 /* s_task_watermarks */
32-
+ 1 /* s_task_tcbs */
33-
#if CONFIG_MEMFAULT_COREDUMP_COLLECT_DATA_REGIONS
34-
+ 1
35-
#endif
36-
#if CONFIG_MEMFAULT_COREDUMP_COLLECT_BSS_REGIONS
37-
+ 1
38-
#endif
39-
];
40-
41-
MEMFAULT_WEAK
42-
const sMfltCoredumpRegion *memfault_platform_coredump_get_regions(
43-
const sCoredumpCrashInfo *crash_info, size_t *num_regions) {
27+
size_t memfault_zephyr_coredump_get_regions(const sCoredumpCrashInfo *crash_info,
28+
sMfltCoredumpRegion *regions, size_t num_regions) {
29+
// Check that regions is valid and has enough space to store all required regions
30+
if (regions == NULL || num_regions < MEMFAULT_ZEPHYR_COREDUMP_REGIONS) {
31+
return 0;
32+
}
4433

4534
const bool msp_was_active = (crash_info->exception_reg_state->exc_return & (1 << 2)) == 0;
46-
int region_idx = 0;
35+
size_t region_idx = 0;
4736

4837
size_t stack_size_to_collect = memfault_platform_sanitize_address_range(
49-
crash_info->stack_address, CONFIG_MEMFAULT_COREDUMP_STACK_SIZE_TO_COLLECT);
38+
crash_info->stack_address, CONFIG_MEMFAULT_COREDUMP_STACK_SIZE_TO_COLLECT);
5039

51-
s_coredump_regions[region_idx] = MEMFAULT_COREDUMP_MEMORY_REGION_INIT(
52-
crash_info->stack_address, stack_size_to_collect);
40+
regions[region_idx] =
41+
MEMFAULT_COREDUMP_MEMORY_REGION_INIT(crash_info->stack_address, stack_size_to_collect);
5342
region_idx++;
5443

5544
if (msp_was_active) {
@@ -60,19 +49,15 @@ const sMfltCoredumpRegion *memfault_platform_coredump_get_regions(
6049
// exception frame that will have been stacked on it as well
6150
const uint32_t extra_stack_bytes = 128;
6251
stack_size_to_collect = memfault_platform_sanitize_address_range(
63-
psp, CONFIG_MEMFAULT_COREDUMP_STACK_SIZE_TO_COLLECT + extra_stack_bytes);
64-
s_coredump_regions[region_idx] = MEMFAULT_COREDUMP_MEMORY_REGION_INIT(
65-
psp, stack_size_to_collect);
52+
psp, CONFIG_MEMFAULT_COREDUMP_STACK_SIZE_TO_COLLECT + extra_stack_bytes);
53+
regions[region_idx] = MEMFAULT_COREDUMP_MEMORY_REGION_INIT(psp, stack_size_to_collect);
6654
region_idx++;
6755
}
6856

69-
s_coredump_regions[region_idx] = MEMFAULT_COREDUMP_MEMORY_REGION_INIT(
70-
&_kernel, sizeof(_kernel));
57+
regions[region_idx] = MEMFAULT_COREDUMP_MEMORY_REGION_INIT(&_kernel, sizeof(_kernel));
7158
region_idx++;
7259

73-
region_idx += memfault_zephyr_get_task_regions(
74-
&s_coredump_regions[region_idx],
75-
MEMFAULT_ARRAY_SIZE(s_coredump_regions) - region_idx);
60+
region_idx += memfault_zephyr_get_task_regions(&regions[region_idx], num_regions - region_idx);
7661

7762
//
7863
// Now that we have captured all the task state, we will
@@ -81,15 +66,22 @@ const sMfltCoredumpRegion *memfault_platform_coredump_get_regions(
8166
//
8267

8368
#if CONFIG_MEMFAULT_COREDUMP_COLLECT_DATA_REGIONS
84-
region_idx += memfault_zephyr_get_data_regions(
85-
&s_coredump_regions[region_idx], MEMFAULT_ARRAY_SIZE(s_coredump_regions) - region_idx);
69+
region_idx += memfault_zephyr_get_data_regions(&regions[region_idx], num_regions - region_idx);
8670
#endif
8771

8872
#if CONFIG_MEMFAULT_COREDUMP_COLLECT_BSS_REGIONS
89-
region_idx += memfault_zephyr_get_bss_regions(
90-
&s_coredump_regions[region_idx], MEMFAULT_ARRAY_SIZE(s_coredump_regions) - region_idx);
73+
region_idx += memfault_zephyr_get_bss_regions(&regions[region_idx], num_regions - region_idx);
9174
#endif
9275

93-
*num_regions = region_idx;
76+
return region_idx;
77+
}
78+
79+
MEMFAULT_WEAK
80+
const sMfltCoredumpRegion *memfault_platform_coredump_get_regions(
81+
const sCoredumpCrashInfo *crash_info, size_t *num_regions) {
82+
static sMfltCoredumpRegion s_coredump_regions[MEMFAULT_ZEPHYR_COREDUMP_REGIONS];
83+
84+
*num_regions = memfault_zephyr_coredump_get_regions(crash_info, s_coredump_regions,
85+
MEMFAULT_ARRAY_SIZE(s_coredump_regions));
9486
return &s_coredump_regions[0];
9587
}

ports/zephyr/include/memfault/ports/zephyr/coredump.h

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,31 @@ extern "C" {
1717
//! For each task, we will collect the TCB and the portion of the stack where context is saved
1818
#define MEMFAULT_COREDUMP_MAX_TASK_REGIONS (CONFIG_MEMFAULT_COREDUMP_MAX_TRACKED_TASKS * 2)
1919

20-
//! Helper to collect minimal RAM needed for backtraces of non-running FreeRTOS tasks
20+
//! Define base number of regions to collect (active stack(s)[2] + _kernel[1] + s_task_watermarks[1]
21+
//! + s_task_tcbs[1])
22+
#define MEMFAULT_ZEPHYR_BASE_COREDUMP_REGIONS (5)
23+
24+
//! Define the total regions to collect
25+
#define MEMFAULT_ZEPHYR_COREDUMP_REGIONS \
26+
(MEMFAULT_ZEPHYR_BASE_COREDUMP_REGIONS + MEMFAULT_COREDUMP_MAX_TASK_REGIONS + \
27+
IS_ENABLED(CONFIG_MEMFAULT_COREDUMP_COLLECT_BSS_REGIONS) + \
28+
IS_ENABLED(CONFIG_MEMFAULT_COREDUMP_COLLECT_DATA_REGIONS))
29+
30+
//! Helper to collect regions required to decode Zephyr state
31+
//!
32+
//! These regions include the active task, the kernel state, other tasks in the system,
33+
//! and bss/data regions if enabled.
34+
//!
35+
//! @param crash_info Contains info regarding the location and state of the crash
36+
//! @param regions Pointer to save region info into
37+
//! @param num_regions The number of entries in the 'regions' array
38+
size_t memfault_zephyr_coredump_get_regions(const sCoredumpCrashInfo *crash_info,
39+
sMfltCoredumpRegion *regions, size_t num_regions);
40+
41+
//! Helper to collect minimal RAM needed for backtraces of non-running Zephyr tasks
2142
//!
2243
//! @param[out] regions Populated with the regions that need to be collected in order
23-
//! for task and stack state to be recovered for non-running FreeRTOS tasks
44+
//! for task and stack state to be recovered for non-running Zephyr tasks
2445
//! @param[in] num_regions The number of entries in the 'regions' array
2546
//!
2647
//! @return The number of entries that were populated in the 'regions' argument. Will always

ports/zephyr/v2.4/memfault_fault_handler.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@
1818
#include "memfault/panics/arch/arm/cortex_m.h"
1919
#include "memfault/panics/coredump.h"
2020
#include "memfault/panics/fault_handling.h"
21+
#include "memfault/ports/zephyr/version.h"
22+
23+
// Starting in v3.4, the handler set function was renamed and the declaration
24+
// added to a public header
25+
#if MEMFAULT_ZEPHYR_VERSION_GT(3, 3)
26+
#include <arch/arm/aarch32/nmi.h>
27+
#define MEMFAULT_ZEPHYR_NMI_HANDLER_SET z_arm_nmi_set_handler
28+
#else
29+
#define MEMFAULT_ZEPHYR_NMI_HANDLER_SET z_NmiHandlerSet
30+
extern void MEMFAULT_ZEPHYR_NMI_HANDLER_SET(void (*pHandler)(void));
31+
#endif // MEMFAULT_ZEPHYR_VERSION_GT(3, 3)
2132

2233
// By default, the Zephyr NMI handler is an infinite loop. Instead
2334
// let's register the Memfault Exception Handler
@@ -28,8 +39,7 @@
2839
// Since we don't use the arguments we match anything with () to avoid
2940
// compiler warnings and share the same bootup logic
3041
static int prv_install_nmi_handler() {
31-
extern void z_NmiHandlerSet(void (*pHandler)(void));
32-
z_NmiHandlerSet(MEMFAULT_EXC_HANDLER_NMI);
42+
MEMFAULT_ZEPHYR_NMI_HANDLER_SET(MEMFAULT_EXC_HANDLER_NMI);
3343
return 0;
3444
}
3545

tests/makefiles/Makefile_memfault_printf_attribute.mk

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# Add a file to create dummy TARGET_LIB
2+
# We don't actually call anything from this lib so just add
3+
# the current source
4+
SRC_FILES = \
5+
$(MFLT_TEST_SRC_DIR)/test_memfault_printf_attribute.cpp
6+
17
TEST_SRC_FILES = \
28
$(MFLT_TEST_SRC_DIR)/test_memfault_printf_attribute.cpp \
39
$(MOCK_AND_FAKE_SRC_FILES)

0 commit comments

Comments
 (0)