Skip to content

Commit

Permalink
Memfault Firmware SDK 1.3.2 (Build 3642)
Browse files Browse the repository at this point in the history
  • Loading branch information
Memfault Inc committed Sep 26, 2023
1 parent 38e0ca9 commit 9f1addb
Show file tree
Hide file tree
Showing 21 changed files with 298 additions and 120 deletions.
25 changes: 25 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
# Memfault Firmware SDK Changelog

## 1.3.2 - Sept 26, 2023

### :chart_with_upwards_trend: Improvements

- Zephyr:

- use `<cmsis_core.h>` instead of `<nmi.h>`. Thanks @kmeihar for this change!
(see [#64](https://github.com/memfault/memfault-firmware-sdk/pull/64))

- nRF Connect SDK:

- Add missing Kconfig flags `CONFIG_FLASH_MAP=y` + `CONFIG_STREAM_FLASH=y` for
the [`examples/nrf-connect-sdk/nrf5/`](examples/nrf-connect-sdk/nrf5/)
example app, for compatibility with nRF Connect SDK v2.4.1+. This was
required due to an
[upstream Zephyr change](https://github.com/zephyrproject-rtos/zephyr/commit/1b4b979f8789af6087f877c0daad0a660c1b9b28).

- General:
- Add support for Memfault Compact Logs for C++ source files (previously only
supported in C source files). Compact logging can be enabled by setting
`MEMFAULT_LOG_COMPACT_ENABLE=1` in `memfault_platform_config.h`. See
[the docs](https://docs.memfault.com/docs/mcu/debugging/compact-logs) for
more details.
- Fix a missing include of `<intrinsics.h>` required by the IAR compiler

## 1.3.1 - Sept 21, 2023

### :chart_with_upwards_trend: Improvements
Expand Down
6 changes: 3 additions & 3 deletions VERSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
BUILD ID: 3608
GIT COMMIT: 4124d24ad
VERSION: 1.3.1
BUILD ID: 3642
GIT COMMIT: 5eb9f7b6a
VERSION: 1.3.2
8 changes: 0 additions & 8 deletions components/include/memfault/components.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
//! #include memfault/components.h
//!

#ifdef __cplusplus
extern "C" {
#endif

#include "memfault/config.h"
#include "memfault/core/arch.h"
#include "memfault/core/batched_events.h"
Expand Down Expand Up @@ -69,7 +65,3 @@ extern "C" {
#include "memfault/util/rle.h"
#include "memfault/util/varint.h"
#include "memfault/version.h"

#ifdef __cplusplus
}
#endif
62 changes: 49 additions & 13 deletions components/include/memfault/core/compact_log_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@

#include "memfault/config.h"

#ifdef __cplusplus
extern "C" {
#endif

#if MEMFAULT_COMPACT_LOG_ENABLE

#include "memfault/core/compiler.h"
Expand All @@ -43,16 +39,52 @@ extern "C" {

#ifdef __cplusplus

// C++ implementation of the type promotion logic
//
// Note: the C++ implementation requires the use of C++11 features and the GNU
// "##" variadic arg extension. Memfault Compact Logs in C++ require the
// compiler flag '--std=gnu++-11' or newer.

#ifdef MEMFAULT_UNITTEST
//! Note: For trace_event Memfault CppUTest tests, we pick up this header but do not actually use
//! the helpers defined so let's silence the warning generated
#else
# error "Compact logs not yet available when using CPP"
#endif
#include <type_traits>

#else // C Code implementation
// Default integer type is int64
template <typename T, typename E = void>
struct MemfaultLogArgPromotionType
: std::integral_constant<int, MEMFAULT_LOG_ARG_PROMOTED_TO_INT64> {};

// If sizeof(T) <= 32, then it's int32
template <typename T>
struct MemfaultLogArgPromotionType<
T, typename std::enable_if<sizeof(T) <= 4>::type>
: std::integral_constant<int, MEMFAULT_LOG_ARG_PROMOTED_TO_INT32> {};

// More specific types
template <>
struct MemfaultLogArgPromotionType<float>
: std::integral_constant<int, MEMFAULT_LOG_ARG_PROMOTED_TO_DOUBLE> {};

template <>
struct MemfaultLogArgPromotionType<double>
: std::integral_constant<int, MEMFAULT_LOG_ARG_PROMOTED_TO_DOUBLE> {};

template <>
struct MemfaultLogArgPromotionType<long double>
: std::integral_constant<int, MEMFAULT_LOG_ARG_PROMOTED_TO_DOUBLE> {};

template <>
struct MemfaultLogArgPromotionType<char *>
: std::integral_constant<int, MEMFAULT_LOG_ARG_PROMOTED_TO_STR> {};

template <>
struct MemfaultLogArgPromotionType<const char *>
: std::integral_constant<int, MEMFAULT_LOG_ARG_PROMOTED_TO_STR> {};

// When expressing the final type via the template parameter expansion, operate
// on (arg) + 0 to force integer promotion
#define _MEMFAULT_LOG_ARG_PROMOTION_TYPE(arg) \
MemfaultLogArgPromotionType<decltype((arg) + 0)>::value

#else // C Code implementation

//! Preprocessor macro to encode promotion type info about each va_arg in a uint32_t
//!
Expand Down Expand Up @@ -94,6 +126,10 @@ extern "C" {
default: sizeof((arg) + 0) <= sizeof(int) ? \
MEMFAULT_LOG_ARG_PROMOTED_TO_INT32 : MEMFAULT_LOG_ARG_PROMOTED_TO_INT64) \

#endif // __cplusplus

#ifdef __cplusplus
extern "C" {
#endif

#define _MF_FMT_0(fmt_op) 0
Expand Down Expand Up @@ -176,8 +212,8 @@ typedef struct MemfaultLogFmtElfSectionHeader {
extern const sMemfaultLogFmtElfSectionHeader g_memfault_log_fmt_elf_section_hdr;
#endif /* MEMFAULT_COMPACT_LOG_ENABLE */

#ifdef __cplusplus
}
#endif
#endif /* MEMFAULT_COMPACT_LOG_ENABLE */
2 changes: 2 additions & 0 deletions components/include/memfault/core/compiler_iar.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
extern "C" {
#endif

#include "intrinsics.h"

#define MEMFAULT_PACKED __packed
#define MEMFAULT_PACKED_STRUCT MEMFAULT_PACKED struct
#define MEMFAULT_NORETURN __noreturn
Expand Down
4 changes: 2 additions & 2 deletions components/include/memfault/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ typedef struct {
uint8_t patch;
} sMfltSdkVersion;

#define MEMFAULT_SDK_VERSION { .major = 1, .minor = 3, .patch = 1 }
#define MEMFAULT_SDK_VERSION_STR "1.3.1"
#define MEMFAULT_SDK_VERSION { .major = 1, .minor = 3, .patch = 2 }
#define MEMFAULT_SDK_VERSION_STR "1.3.2"

#ifdef __cplusplus
}
Expand Down
21 changes: 16 additions & 5 deletions examples/freertos/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@ BUILD_DIR := build/$(BOARD)
ELF = $(BUILD_DIR)/main.elf

ARM_CC ?= arm-none-eabi-gcc
ARM_CXX ?= arm-none-eabi-g++
# if cc isn't set by the user, set it to ARM_CC
ifeq ($(origin CC),default)
CC := $(ARM_CC)
CXX := $(ARM_CXX)
endif
# use ccache if available
CCACHE := $(shell command -v ccache 2> /dev/null)
ifdef CCACHE
CC := ccache $(CC)
CXX := ccache $(CXX)
endif
OBJCOPY ?= $(shell $(CC) -print-prog-name=objcopy)

Expand Down Expand Up @@ -59,6 +62,7 @@ FREERTOS_SRCS = \
# Add application sources
SRCS += \
main.c \
compact_log.cpp \
$(BOARD_DIR)/startup.c \
console.c \
$(BOARD_DIR)/memfault_platform_impl.c \
Expand All @@ -79,7 +83,7 @@ SRCS += \
$(MEMFAULT_SDK_ROOT)/ports/panics/src/memfault_platform_ram_backed_coredump.c \

# Fixup build path for objects of the Memfault SDK, all build output kept within build/
OBJS := $(subst $(MEMFAULT_SDK_ROOT),memfault-firmware-sdk,$(SRCS:%.c=$(BUILD_DIR)/%.o))
OBJS := $(subst $(MEMFAULT_SDK_ROOT),memfault-firmware-sdk,$(SRCS:%=$(BUILD_DIR)/%.o))

INCLUDE_PATHS += \
-I$(FREERTOS_DIR)/include \
Expand All @@ -102,8 +106,10 @@ CFLAGS += \
-Og \
-MD \

LINKER_SCRIPT = $(BOARD_DIR)/linker.ld

LDFLAGS += \
-Wl,-T$(BOARD_DIR)/linker.ld \
-Wl,-T$(LINKER_SCRIPT) \
-Wl,--gc-sections \
--specs=nano.specs \
--specs=rdimon.specs \
Expand All @@ -119,17 +125,22 @@ all: $(ELF)
$(SRCS): $(FREERTOS_DIR)/.clonedone

# Add rules for patched build objects from SDK
$(BUILD_DIR)/memfault-firmware-sdk/%.o: $(MEMFAULT_SDK_ROOT)/%.c
$(BUILD_DIR)/memfault-firmware-sdk/%.c.o: $(MEMFAULT_SDK_ROOT)/%.c
mkdir -p $(dir $@)
$(info Compiling $<)
$(CC) $(CFLAGS) $(INCLUDE_PATHS) -c $< -o $@

$(BUILD_DIR)/%.o: %.c
$(BUILD_DIR)/%.c.o: %.c
mkdir -p $(dir $@)
$(info Compiling $<)
$(CC) $(CFLAGS) $(INCLUDE_PATHS) -c $< -o $@

$(ELF).uncompressed: $(OBJS)
$(BUILD_DIR)/%.cpp.o: %.cpp
mkdir -p $(dir $@)
$(info Compiling $<)
$(CXX) -std=gnu++11 $(CFLAGS) $(INCLUDE_PATHS) -c $< -o $@

$(ELF).uncompressed: $(OBJS) $(LINKER_SCRIPT)
$(info Linking $@)
$(CC) $(CFLAGS) $(LDFLAGS) $(OBJS) -o $@

Expand Down
4 changes: 3 additions & 1 deletion examples/freertos/boards/qemu_mps2_an385/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ RUN_COMMAND = qemu-system-arm -machine mps2-an385 -monitor null -semihosting \

DEBUG_COMMAND = $(RUN_COMMAND) $(ATTACH_DEBUGGER)

# Permit overriding the gdb executable
GDB ?= gdb
GDB_COMMAND = \
gdb --ex 'target extended-remote :1234' $(ELF)
$(GDB) --ex 'target extended-remote :1234' $(ELF)
6 changes: 6 additions & 0 deletions examples/freertos/boards/qemu_mps2_an385/linker.ld
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ SECTIONS
__StackLimit = __StackTop - _Min_Stack_Size;
PROVIDE(__stack = __StackTop);

log_fmt 0xF0000000 (INFO):
{
KEEP(*(*.log_fmt_hdr))
KEEP(*(log_fmt))
}

/* Check if data + heap + stack exceeds RAM limit */
ASSERT(__StackLimit >= _heap_top, "region RAM overflowed with stack")
}
22 changes: 22 additions & 0 deletions examples/freertos/compact_log.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//! @file
//!
//! Small example showcasing the use of compact logs from C++.

#include "compact_log.h"

#include <inttypes.h>

#include "memfault/components.h"

void compact_log_cpp_example(void) {
#if MEMFAULT_COMPACT_LOG_ENABLE
MEMFAULT_COMPACT_LOG_SAVE(kMemfaultPlatformLogLevel_Info,
"This is a compact log example from c++ "
// clang-format off
"%d" " %" PRIu64 " %f" " %f" " %s",
1234, (uint64_t)0x7, 1.0f, 2.0, "1212"
// ^int ^uint64_t ^float ^double ^string
// clang-format on
);
#endif
}
16 changes: 16 additions & 0 deletions examples/freertos/compact_log.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//! @file
//!
//! Copyright (c) Memfault, Inc.
//! See License.txt for details

#pragma once

#ifdef __cplusplus
extern "C" {
#endif

void compact_log_cpp_example(void);

#ifdef __cplusplus
}
#endif
12 changes: 12 additions & 0 deletions examples/freertos/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <sys/times.h>

#include "FreeRTOS.h"
#include "compact_log.h"
#include "console.h"
#include "memfault/components.h"
#include "task.h"
Expand Down Expand Up @@ -144,6 +145,17 @@ int main(void) {
prv_heap_task();
prv_metrics_task();
console_init();

compact_log_cpp_example();

// Enable this to export compact log data to stdio. This is intended only for
// testing deserialization of the compact log example above and is not
// typically useful.
#if defined(DEBUG_COMPACT_LOGS)
printf(">> exporting logs...\n");
memfault_log_export_logs();
#endif

// Initialize the FreeRTOS kernel
vTaskStartScheduler();

Expand Down
1 change: 1 addition & 0 deletions examples/freertos/memfault/memfault_platform_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@
#define MEMFAULT_FREERTOS_PORT_HEAP_STATS_ENABLE 1
#define MEMFAULT_COREDUMP_HEAP_STATS_LOCK_ENABLE 0
#define MEMFAULT_METRICS_HEARTBEAT_INTERVAL_SECS 60
#define MEMFAULT_COMPACT_LOG_ENABLE 1
2 changes: 2 additions & 0 deletions examples/nrf-connect-sdk/nrf5/memfault_demo_app/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ CONFIG_BOOTLOADER_MCUBOOT=y
CONFIG_MCUBOOT_IMG_MANAGER=y
CONFIG_IMG_MANAGER=y
CONFIG_FLASH=y
CONFIG_FLASH_MAP=y
CONFIG_STREAM_FLASH=y

CONFIG_WATCHDOG=y

Expand Down
2 changes: 1 addition & 1 deletion examples/nrf-connect-sdk/nrf5/memfault_demo_app/west.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ manifest:
projects:
- name: nrf
url: https://github.com/nrfconnect/sdk-nrf
revision: v2.0.2
revision: v2.4.2
import: true

# Adding the memfault-firmware-sdk module here overrides the version the nRF
Expand Down
9 changes: 3 additions & 6 deletions ports/zephyr/v2.4/memfault_fault_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,10 @@
// Starting in v3.4, the handler set function was renamed and the declaration
// added to a public header
#if MEMFAULT_ZEPHYR_VERSION_GT(3, 3)
// The nmi.h header was moved after Zephyr v3.4. Support both locations.
#if __has_include(MEMFAULT_ZEPHYR_INCLUDE(arch/arm/aarch32/nmi.h))
#include MEMFAULT_ZEPHYR_INCLUDE(arch/arm/aarch32/nmi.h)
#elif __has_include(MEMFAULT_ZEPHYR_INCLUDE(arch/arm/nmi.h))
#include MEMFAULT_ZEPHYR_INCLUDE(arch/arm/nmi.h)
#if MEMFAULT_ZEPHYR_VERSION_GT(3, 4)
#include <cmsis_core.h>
#else
#error "Missing Zephyr nmi.h header"
#include MEMFAULT_ZEPHYR_INCLUDE(arch/arm/aarch32/nmi.h)
#endif
#define MEMFAULT_ZEPHYR_NMI_HANDLER_SET z_arm_nmi_set_handler
#else
Expand Down
Loading

0 comments on commit 9f1addb

Please sign in to comment.