Skip to content

Commit

Permalink
Memfault Firmware SDK 0.32.0 (Build 490129)
Browse files Browse the repository at this point in the history
  • Loading branch information
Memfault Inc committed Aug 8, 2022
1 parent 130caec commit 806df3e
Show file tree
Hide file tree
Showing 34 changed files with 615 additions and 433 deletions.
83 changes: 83 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,86 @@
### Changes between Memfault SDK 0.32.0 and SDK 0.31.5 - Aug 7, 2022

#### :chart_with_upwards_trend: Improvements

- [ModusToolbox:tm: Software](https://www.infineon.com/cms/en/design-support/tools/sdk/modustoolbox-software/)
port updates
- Added heartbeat metrics for heap and Wi-Fi performance tracking when using
the default port for
[CAT1A (PSoC:tm: 6)](https://github.com/Infineon/mtb-pdl-cat1). See
[ports/cypress/psoc6/memfault_platform_core.c](ports/cypress/psoc6/memfault_platform_core.c)
for more details
- Fixed reboot reason reported when PSoC 6 is fully reset to report "Power On
Reset" instead of "Unknown"
- Zephyr port updates
- Memfault logs (eg `MEMFAULT_LOG_DEBUG()` etc) are now routed to the Zephyr
logging infrastructure. The typical set of Kconfig options for Memfault logs
are available (`CONFIG_MEMFAULT_LOG_LEVEL_WRN` etc). See details in
"Breaking Changes" below for enabling logs in your project.
- Added a new Kconfig option, `MEMFAULT_ZEPHYR_FATAL_HANDLER`, which can be
used to disable the Zephyr fault handler print facilities.

#### :boom: Breaking Changes

- Users will no longer see internal Memfault log output by default, but will
have to enable it explicitly to see the output:

```ini
# enable LOG
CONFIG_LOG=y
# not required- enabling the Memfault logging component enables including the
# log buffer in coredumps
CONFIG_MEMFAULT_LOGGING_ENABLE=y

# if on pre-v3.1.0 zephyr, you can choose either the default LOG v1
# implementation, or select a LOG2 mode to enable LOG2. on zephyr 3.1.0+, LOG
# v1 is removed and LOG v2 is now the only log implementation
# CONFIG_LOG2_MODE_DEFERRED=y

# make sure to select a log backend to see the output
CONFIG_LOG_BACKEND_UART=y
```

The log statements affected by this change are likely only the internal
Memfault SDK logs (`MEMFAULT_LOG_DEBUG()` etc), unless those macros are used
in the user application.

- Removed support for Zephyr LTS release 1.14 as it was superseded by
[LTS V2 almost a year ago now](https://www.zephyrproject.org/zephyr-lts-v2-release/).
A project using this release of Zephyr must target a memfault-firmware-sdk
release less than 0.32.0.

#### :house: Internal

- More logically grouped Kconfig settings in Zephyr example app's
[prj.conf](examples/zephyr/apps/memfault_demo_app/prj.conf)
- Fixed a few typos in particle port documentation
- Simplified compilation steps for the
[nRF91 sample test app](examples/nrf-connect-sdk/nrf9160/memfault_demo_app)
when compiling with older releases of the nRF Connect SDK and refreshed the
example to target the v2.0.2 release by default
- Updated default demo CLI commands to better align with
[our suggested integration test commands](https://mflt.io/mcu-test-commands).
The default set now looks like this:

```bash
mflt> help
clear_core: Clear an existing coredump
drain_chunks: Flushes queued Memfault data. To upload data see https://mflt.io/posting-chunks-with-gdb
export: Export base64-encoded chunks. To upload data see https://mflt.io/chunk-data-export
get_core: Get coredump info
get_device_info: Get device info
test_assert: Trigger memfault assert
test_busfault: Trigger a busfault
test_hardfault: Trigger a hardfault
test_memmanage: Trigger a memory management fault
test_usagefault: Trigger a usage fault
test_log: Writes test logs to log buffer
test_log_capture: Trigger capture of current log buffer contents
test_reboot: Force system reset and track it with a trace event
test_trace: Capture an example trace event
help: Lists all commands
```

### Changes between Memfault SDK 0.31.5 and SDK 0.31.4 - July 22, 2022

#### :chart_with_upwards_trend: Improvements
Expand Down
4 changes: 2 additions & 2 deletions VERSION
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
BUILD ID: 481181
GIT COMMIT: 95031d142
BUILD ID: 490129
GIT COMMIT: d8f64c57b
8 changes: 8 additions & 0 deletions components/core/src/arch_arm_cortex_m.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ bool memfault_arch_is_inside_isr(void) {
return ((*ICSR & 0xff) != 0x0);
}

void memfault_arch_disable_configurable_faults(void) {
// Clear MEMFAULTENA, BUSFAULTENA, USGFAULTENA, SECUREFAULTENA
//
// This will force all faults to be routed through the HardFault Handler
volatile uint32_t *SHCSR = (uint32_t*)0xE000ED24;
*SHCSR &= ~((uint32_t)0x000F0000);
}

MEMFAULT_WEAK
void memfault_platform_halt_if_debugging(void) {
volatile uint32_t *dhcsr = (volatile uint32_t *)0xE000EDF0;
Expand Down
11 changes: 11 additions & 0 deletions components/demo/src/memfault_demo_cli_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,24 @@

#include "memfault/core/compiler.h"
#include "memfault/core/log.h"
#include "memfault/config.h"
#include "memfault/core/debug_log.h"

int memfault_demo_cli_cmd_test_log(MEMFAULT_UNUSED int argc,
MEMFAULT_UNUSED char *argv[]) {
MEMFAULT_LOG_DEBUG("Debug log!");
MEMFAULT_LOG_INFO("Info log!");
MEMFAULT_LOG_WARN("Warning log!");
MEMFAULT_LOG_ERROR("Error log!");

#if MEMFAULT_SDK_LOG_SAVE_DISABLE
// MEMFAULT_LOGs are not written to the ram backed log buffer so do
// it explicitly
MEMFAULT_LOG_SAVE(kMemfaultPlatformLogLevel_Debug, "Debug log!");
MEMFAULT_LOG_SAVE(kMemfaultPlatformLogLevel_Info, "Info log!");
MEMFAULT_LOG_SAVE(kMemfaultPlatformLogLevel_Warning, "Warning log!");
MEMFAULT_LOG_SAVE(kMemfaultPlatformLogLevel_Error, "Error log!");
#endif
return 0;
}

Expand Down
31 changes: 23 additions & 8 deletions components/demo/src/memfault_demo_shell_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@

#include <stddef.h>

#include "memfault/core/compiler.h"
#include "memfault/core/data_export.h"
#include "memfault/core/debug_log.h"
#include "memfault/core/math.h"
#include "memfault/demo/cli.h"
#include "memfault/core/compiler.h"
#include "memfault/core/data_export.h"

static int prv_panics_component_required(void) {
MEMFAULT_LOG_RAW("Disabled. panics component integration required");
Expand Down Expand Up @@ -43,15 +43,30 @@ int memfault_demo_cli_cmd_export(MEMFAULT_UNUSED int argc, MEMFAULT_UNUSED char
}

static const sMemfaultShellCommand s_memfault_shell_commands[] = {
{"get_core", memfault_demo_cli_cmd_get_core, "Get coredump info"},
{"clear_core", memfault_demo_cli_cmd_clear_core, "Clear an existing coredump"},
{"crash", memfault_demo_cli_cmd_crash, "Trigger a crash"},
{"trigger_logs", memfault_demo_cli_cmd_trigger_logs, "Trigger capture of current log buffer contents"},
{"drain_chunks", memfault_demo_drain_chunk_data, "Flushes queued Memfault data. To upload data see https://mflt.io/posting-chunks-with-gdb"},
{"trace", memfault_demo_cli_cmd_trace_event_capture, "Capture an example trace event"},
{"get_device_info", memfault_demo_cli_cmd_get_device_info, "Get device info"},
{"reboot", memfault_demo_cli_cmd_system_reboot, "Reboot system and tracks it with a trace event"},
{"export", memfault_demo_cli_cmd_export, "Export base64-encoded chunks. To upload data see https://mflt.io/chunk-data-export"},
{"get_core", memfault_demo_cli_cmd_get_core, "Get coredump info"},
{"get_device_info", memfault_demo_cli_cmd_get_device_info, "Get device info"},

//
// Test commands for validating SDK functionality: https://mflt.io/mcu-test-commands
//

{"test_assert", memfault_demo_cli_cmd_assert, "Trigger memfault assert"},

#if MEMFAULT_COMPILER_ARM
{"test_busfault", memfault_demo_cli_cmd_busfault, "Trigger a busfault"},
{"test_hardfault", memfault_demo_cli_cmd_hardfault, "Trigger a hardfault"},
{"test_memmanage", memfault_demo_cli_cmd_memmanage, "Trigger a memory management fault"},
{"test_usagefault", memfault_demo_cli_cmd_usagefault, "Trigger a usage fault"},
#endif

{"test_log", memfault_demo_cli_cmd_test_log, "Writes test logs to log buffer"},
{"test_log_capture", memfault_demo_cli_cmd_trigger_logs, "Trigger capture of current log buffer contents"},
{"test_reboot", memfault_demo_cli_cmd_system_reboot, "Force system reset and track it with a trace event"},
{"test_trace", memfault_demo_cli_cmd_trace_event_capture, "Capture an example trace event"},

{"help", memfault_shell_help_handler, "Lists all commands"},
};

Expand Down
54 changes: 52 additions & 2 deletions components/demo/src/panics/memfault_demo_panics.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
//! @brief
//! CLI commands which require integration of the "panic" component.

#include "memfault/demo/cli.h"

#include <stdlib.h>

#include "memfault/core/arch.h"
#include "memfault/core/compiler.h"
#include "memfault/core/debug_log.h"
#include "memfault/core/errors.h"
#include "memfault/core/platform/core.h"
#include "memfault/core/platform/device_info.h"
#include "memfault/core/reboot_tracking.h"
#include "memfault/demo/cli.h"
#include "memfault/panics/assert.h"
#include "memfault/panics/coredump.h"
#include "memfault/panics/platform/coredump.h"
Expand Down Expand Up @@ -110,3 +110,53 @@ int memfault_demo_cli_cmd_clear_core(MEMFAULT_UNUSED int argc, MEMFAULT_UNUSED c
memfault_platform_coredump_storage_clear();
return 0;
}

int memfault_demo_cli_cmd_assert(MEMFAULT_UNUSED int argc, MEMFAULT_UNUSED char *argv[]) {
MEMFAULT_ASSERT(0);
}

#if MEMFAULT_COMPILER_ARM

int memfault_demo_cli_cmd_hardfault(MEMFAULT_UNUSED int argc, MEMFAULT_UNUSED char *argv[]) {
memfault_arch_disable_configurable_faults();

uint64_t *buf = g_memfault_unaligned_buffer;
*buf = 0xdeadbeef0000;

return -1;
}

int memfault_demo_cli_cmd_memmanage(MEMFAULT_UNUSED int argc, MEMFAULT_UNUSED char *argv[]) {
// Per "Relation of the MPU to the system memory map" in ARMv7-M reference manual:
//
// "The MPU is restricted in how it can change the default memory map attributes associated with
// System space, that is, for addresses 0xE0000000 and higher. System space is always marked as
// XN, Execute Never."
//
// So we can trip a MemManage exception by simply attempting to execute any addresss >= 0xE000.0000
void (*bad_func)(void) = (void (*)(void))0xEEEEDEAD;
bad_func();

// We should never get here -- platforms MemManage or HardFault handler should be tripped
return -1;
}

int memfault_demo_cli_cmd_busfault(MEMFAULT_UNUSED int argc, MEMFAULT_UNUSED char *argv[]) {
void (*unaligned_func)(void) = (void (*)(void))0x50000001;
unaligned_func();

// We should never get here -- platforms BusFault or HardFault handler should be tripped
// with a precise error due to unaligned execution
return -1;
}

int memfault_demo_cli_cmd_usagefault(MEMFAULT_UNUSED int argc, MEMFAULT_UNUSED char *argv[]) {
uint64_t *buf = g_memfault_unaligned_buffer;
*buf = 0xbadcafe0000;

// We should never get here -- platforms UsageFault or HardFault handler should be tripped due to
// unaligned access
return -1;
}

#endif /* MEMFAULT_COMPILER_ARM */
3 changes: 3 additions & 0 deletions components/include/memfault/core/arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ extern "C" {
//! Return true if the code is currently running in an interrupt context, false otherwise
bool memfault_arch_is_inside_isr(void);

//! Disable any configurable fault handlers supported by the platform
void memfault_arch_disable_configurable_faults(void);

#ifdef __cplusplus
}
#endif
21 changes: 21 additions & 0 deletions components/include/memfault/demo/cli.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,34 @@
extern "C" {
#endif

#include "memfault/core/compiler.h"

//! Command to crash the device, for example, to trigger a coredump to be captured.
//! It takes one number argument, which is the crash type:
//! - 0: crash by MEMFAULT_ASSERT(0)
//! - 1: crash by jumping to 0xbadcafe
//! - 2: crash by unaligned memory store
int memfault_demo_cli_cmd_crash(int argc, char *argv[]);

#if MEMFAULT_COMPILER_ARM

//! Command which will generate a HardFault
int memfault_demo_cli_cmd_hardfault(int argc, char *argv[]);

//! Command which will generate a BusFault on Cortex-M hardware
int memfault_demo_cli_cmd_busfault(int argc, char *argv[]);

//! Command which will generate a Memory Management fault on Cortex-M hardware
int memfault_demo_cli_cmd_memmanage(int argc, char *argv[]);

//! Command which will generate a UsageFault on Cortex-M hardware
int memfault_demo_cli_cmd_usagefault(int argc, char *argv[]);

#endif /* MEMFAULT_COMPILER_ARM */

//! Command which will generate an assert
int memfault_demo_cli_cmd_assert(int argc, char *argv[]);

//! Command to exercise the MEMFAULT_TRACE_EVENT API, capturing a
//! Trace Event with the error reason set to "MemfaultDemoCli_Error".
int memfault_demo_cli_cmd_trace_event_capture(int argc, char *argv[]);
Expand Down
2 changes: 1 addition & 1 deletion components/include/memfault/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ typedef struct {
uint8_t patch;
} sMfltSdkVersion;

#define MEMFAULT_SDK_VERSION { .major = 0, .minor = 31, .patch = 5 }
#define MEMFAULT_SDK_VERSION { .major = 0, .minor = 32, .patch = 0 }

#ifdef __cplusplus
}
Expand Down
15 changes: 12 additions & 3 deletions examples/nrf-connect-sdk/nrf9160/memfault_demo_app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ find_package(Ncs HINTS $ENV{ZEPHYR_BASE}/../nrf)
# so we set the ones we need here using that:
# https://docs.zephyrproject.org/latest/guides/build/kconfig/setting.html#the-initial-configuration
if (NCS_VERSION_MAJOR)
if (${NCS_VERSION_MAJOR} LESS_EQUAL 1 AND ${NCS_VERSION_MINOR} LESS 6 )
if (${NCS_VERSION_MAJOR} LESS_EQUAL 1 AND ${NCS_VERSION_MINOR} LESS 5 )
# Legacy name for CONFIG_DEBUG_THREAD_INFO needed for nRF Connect version <= 1.5
# due to the version of Zephyr included (pre v2.5)
set(CONFIG_OPENOCD_SUPPORT n CACHE INTERNAL "")

elseif (${NCS_VERSION_MAJOR} LESS_EQUAL 1 AND ${NCS_VERSION_MINOR} LESS 6 )
# Required for logging to work from crash, deprecated in Zephyr included in NCS 1.6
set(CONFIG_LOG_IMMEDIATE y CACHE INTERNAL "")
elseif (${NCS_VERSION_MAJOR} LESS_EQUAL 1 AND ${NCS_VERSION_MINOR} GREATER_EQUAL 6 )
Expand All @@ -53,9 +58,13 @@ if (NCS_VERSION_MAJOR)

# For nRF Connect SDK v1.5 default value changed here
set(CONFIG_AT_CMD_SYS_INIT n CACHE INTERNAL "")
else()
# in v1.9+, use the modem_info library to get the IMEI for device_serial
else() # nRF Connect SDK Version >= 1.8.0
# in v1.8+, use the modem_info library to get the IMEI for device_serial
set(CONFIG_MEMFAULT_NCS_DEVICE_ID_RUNTIME y CACHE INTERNAL "")
set(CONFIG_MODEM_INFO y CACHE INTERNAL "")

# Use SPM instead of TFM for Secure Firmware as TFM does not (yet) support forwarding of fault handlers
set(CONFIG_BUILD_WITH_TFM n CACHE INTERNAL "")
endif()
endif()

Expand Down
Loading

0 comments on commit 806df3e

Please sign in to comment.