Skip to content

Commit

Permalink
Memfault Firmware SDK 1.11.1 (Build 9373)
Browse files Browse the repository at this point in the history
  • Loading branch information
Memfault Inc committed Aug 12, 2024
1 parent de66fe8 commit d53956a
Show file tree
Hide file tree
Showing 16 changed files with 227 additions and 14 deletions.
1 change: 1 addition & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ coverage:
project:
default:
target: 70%
informational: true

ignore:
- "tests" # Don't include the tests themselves in the code coverage report
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.11.1] - 2024-08-12

### :chart_with_upwards_trend: Improvements

- General:

- Add additional stubs to `ports/templates/memfault_platform_port.c` to help
when integrating on a new platform

- ESP-IDF:

- Trigger a null dereference crash when the `BOOT` button is pressed on the
ESP32 example app. This is useful for testing the Memfault crash handling
functionality without using the serial console.

## [1.11.0] - 2024-08-07

### :boom: Breaking Changes
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: 9315
GIT COMMIT: 2d67818dc2
VERSION: 1.11.0
BUILD ID: 9373
GIT COMMIT: 4730bd7818
VERSION: 1.11.1
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 = 11, .patch = 0 }
#define MEMFAULT_SDK_VERSION_STR "1.11.0"
#define MEMFAULT_SDK_VERSION { .major = 1, .minor = 11, .patch = 1 }
#define MEMFAULT_SDK_VERSION_STR "1.11.1"

#ifdef __cplusplus
}
Expand Down
1 change: 1 addition & 0 deletions examples/esp32/apps/memfault_demo_app/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
list(APPEND
COMPONENT_SRCS
button.c
led.c
main.c
)
Expand Down
15 changes: 15 additions & 0 deletions examples/esp32/apps/memfault_demo_app/main/Kconfig.projbuild
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,21 @@ config BLINK_GPIO
GPIO number (IOxx) to blink on and off or the RMT signal for the addressable LED.
Some GPIOs are used for other purposes (flash connections, etc.) and cannot be used to blink.

config BUTTON_GPIO
int "Input pin for the EN button on the dev board"
# https://dl.espressif.com/dl/schematics/esp32_devkitc_v4_sch.pdf
# https://dl.espressif.com/dl/schematics/esp-idf/SCH_ESP32-S2-DEVKITC-1_V1_20220817.pdf
# https://dl.espressif.com/dl/schematics/SCH_ESP32-S3-DevKitC-1_V1.1_20221130.pdf
default 0 if IDF_TARGET_ESP32 || IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3
# https://dl.espressif.com/dl/schematics/SCH_ESP32-C3-DEVKITC-02_V1_1_20210126A.pdf
# https://dl.espressif.com/dl/schematics/SCH_ESP32-C3-DEVKITM-1_V1_20200915A.pdf
# https://docs.espressif.com/projects/esp-dev-kits/en/latest/_static/esp32-c6-devkitc-1/schematics/esp32-c6-devkitc-1-schematics_v1.4.pdf
default 9 if IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32C6
default 0
help
GPIO pin number for the BOOT button. Used to trigger a crash for testing.


# esp32c3/c6 specific settings
if IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32C6
# Default optimize for size due to increase in binary size
Expand Down
86 changes: 86 additions & 0 deletions examples/esp32/apps/memfault_demo_app/main/button.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
//! @file
//!
//! Copyright (c) Memfault, Inc.
//! See License.txt for details
//!
//! Button setup and handling

#include "button.h"

#include "driver/gpio.h"
#include "esp_attr.h"
#include "esp_log.h"
#include "esp_system.h"

static const char *TAG = "button";

static void IRAM_ATTR prv_gpio_isr_handler(void *arg) {
uint32_t gpio_num = (uint32_t)arg;

// dereference a null point to trigger a crash
volatile uint32_t *ptr = NULL;
*ptr = gpio_num;
}

// The flex glitch filter is only available on 5.1. Skip it for earlier SDKs.
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 0)
#include "driver/gpio_filter.h"
static void prv_button_glitch_filter_enable(void) {
#if SOC_GPIO_FLEX_GLITCH_FILTER_NUM > 0
gpio_glitch_filter_handle_t filter;
gpio_flex_glitch_filter_config_t filter_cfg = {
.clk_src = GLITCH_FILTER_CLK_SRC_DEFAULT,
.gpio_num = CONFIG_BUTTON_GPIO,
.window_thres_ns = 500,
.window_width_ns = 500,
};
esp_err_t err = gpio_new_flex_glitch_filter(&filter_cfg, &filter);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to create glitch filter: %s", esp_err_to_name(err));
return;
}

err = gpio_glitch_filter_enable(filter);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to enable glitch filter: %s", esp_err_to_name(err));
return;
}
#endif
}
#else // ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 0)
static void prv_button_glitch_filter_enable(void) {
// No-op
}
#endif // ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 0)

void button_setup(void) {
// configure the button as an input
gpio_config_t io_conf = {
.intr_type = GPIO_INTR_NEGEDGE,
.mode = GPIO_MODE_INPUT,
.pin_bit_mask = 1ULL << CONFIG_BUTTON_GPIO,
.pull_down_en = GPIO_PULLDOWN_DISABLE,
.pull_up_en = GPIO_PULLUP_ENABLE,
};
esp_err_t err = gpio_config(&io_conf);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to configure button: %s", esp_err_to_name(err));
return;
}

prv_button_glitch_filter_enable();

// install gpio isr service
err = gpio_install_isr_service(0);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to install gpio isr service: %s", esp_err_to_name(err));
return;
}

// install isr handler for specific gpio pin
err = gpio_isr_handler_add(CONFIG_BUTTON_GPIO, prv_gpio_isr_handler, (void *)CONFIG_BUTTON_GPIO);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to add isr handler for button: %s", esp_err_to_name(err));
return;
}
}
10 changes: 10 additions & 0 deletions examples/esp32/apps/memfault_demo_app/main/button.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//! @file
//!
//! Copyright (c) Memfault, Inc.
//! See License.txt for details
//!
//! Button setup and handling

#pragma once

void button_setup(void);
3 changes: 3 additions & 0 deletions examples/esp32/apps/memfault_demo_app/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include "app_memfault_transport.h"
#include "argtable3/argtable3.h"
#include "button.h"
#include "cmd_decl.h"
#include "driver/uart.h"
#include "esp_console.h"
Expand Down Expand Up @@ -496,6 +497,8 @@ void app_main() {
#endif // CONFIG_LOG_COLORS
}

button_setup();

/* Main loop */
while (true) {
/* Get a line using linenoise (blocking call).
Expand Down
21 changes: 19 additions & 2 deletions examples/freertos/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ BOARD ?= qemu_mps2_an385

$(info Building for $(BOARD))

# Set to 1 to build with templates/memfault_platform_port.c instead of
# FreeRTOS platform functions. Used to test compilation with template files
MEMFAULT_TEST_USE_PORT_TEMPLATE ?= 0

ifeq ($(MEMFAULT_TEST_USE_PORT_TEMPLATE),1)
ifneq (qemu_mps2_an385,$(BOARD))
$(error Testing with the template port only supported on the qemu_mps2_an385 board)
endif
endif

BOARD_DIR := boards/$(BOARD)

BUILD_DIR := build/$(BOARD)
Expand Down Expand Up @@ -87,9 +97,14 @@ CFLAGS += $(foreach each, $(MEMFAULT_COMPONENTS), -DMEMFAULT_COMPONENT_$(each)_)
# have them enabled in this example app.
SRCS += \
$(MEMFAULT_COMPONENTS_SRCS) \
$(wildcard $(MEMFAULT_SDK_ROOT)/ports/freertos/src/*.c) \
$(MEMFAULT_SDK_ROOT)/ports/panics/src/memfault_platform_ram_backed_coredump.c \

ifneq ($(MEMFAULT_TEST_USE_PORT_TEMPLATE), 1)
SRCS += \
$(wildcard $(MEMFAULT_SDK_ROOT)/ports/freertos/src/*.c)
endif


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

Expand Down Expand Up @@ -119,7 +134,9 @@ CFLAGS += \

# Enable the self test by default
MEMFAULT_DEMO_CLI_SELF_TEST ?= 1
CFLAGS += -DMEMFAULT_DEMO_CLI_SELF_TEST=$(MEMFAULT_DEMO_CLI_SELF_TEST)
CFLAGS += \
-DMEMFAULT_DEMO_CLI_SELF_TEST=$(MEMFAULT_DEMO_CLI_SELF_TEST) \
-DMEMFAULT_TEST_USE_PORT_TEMPLATE=$(MEMFAULT_TEST_USE_PORT_TEMPLATE)

LINKER_SCRIPT = $(BOARD_DIR)/linker.ld

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#define MEMFAULT_COREDUMP_MAX_TASK_REGIONS ((MEMFAULT_PLATFORM_MAX_TRACKED_TASKS)*2)

#if MEMFAULT_TEST_USE_PORT_TEMPLATE != 1
void memfault_platform_reboot(void) {
volatile uint32_t *SCB_AIRCR = (uint32_t *)SCB_AIRCR_ADDR;
*SCB_AIRCR = SCB_AIRCR_RESET_SYSTEM;
Expand All @@ -46,6 +47,7 @@ size_t memfault_platform_sanitize_address_range(void *start_addr, size_t desired

return 0;
}
#endif

static uint32_t prv_read_psp_reg(void) {
uint32_t reg_val;
Expand Down Expand Up @@ -100,13 +102,16 @@ const sMfltCoredumpRegion *memfault_platform_coredump_get_regions(
MEMFAULT_COREDUMP_MEMORY_REGION_INIT(&__memfault_capture_bss_start, memfault_region_size);
region_idx++;

#if MEMFAULT_TEST_USE_PORT_TEMPLATE != 1
region_idx += memfault_freertos_get_task_regions(
&s_coredump_regions[region_idx], MEMFAULT_ARRAY_SIZE(s_coredump_regions) - region_idx);
#endif

*num_regions = region_idx;
return &s_coredump_regions[0];
}

#if MEMFAULT_TEST_USE_PORT_TEMPLATE != 1
static uint32_t prv_read_reboot_reg(void) {
volatile uint32_t *cmsdk_rstinfo = (uint32_t *)CMSDK_RSTINFO_ADDR;
return (*cmsdk_rstinfo & CMSDK_RSTINFO_MASK);
Expand Down Expand Up @@ -147,3 +152,4 @@ void memfault_reboot_reason_get(sResetBootupInfo *reset_info) {
.reset_reason = reboot_reason,
};
}
#endif
19 changes: 14 additions & 5 deletions examples/freertos/src/FreeRTOSConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H

#include "memfault/ports/freertos_trace.h"
#if MEMFAULT_TEST_USE_PORT_TEMPLATE != 1
#include "memfault/ports/freertos_trace.h"
#endif

/*-----------------------------------------------------------
* Application specific definitions.
Expand All @@ -41,10 +43,12 @@
* See https://www.freertos.org/a00110.html
*----------------------------------------------------------*/

#define configASSERT_DEFINED 1
#if MEMFAULT_TEST_USE_PORT_TEMPLATE != 1
#define configASSERT_DEFINED 1
extern void vAssertCalled(const char *file, int line);
#define configASSERT(x) \
if ((x) == 0) vAssertCalled(__FILE__, __LINE__)
#define configASSERT(x) \
if ((x) == 0) vAssertCalled(__FILE__, __LINE__)
#endif
#define configQUEUE_REGISTRY_SIZE 20

#define configUSE_PREEMPTION 1
Expand Down Expand Up @@ -76,7 +80,12 @@ extern void vAssertCalled(const char *file, int line);
/* Set the following definitions to 1 to include the API function, or zero
* to exclude the API function. */

#define configCHECK_FOR_STACK_OVERFLOW 1
#if MEMFAULT_TEST_USE_PORT_TEMPLATE != 1
#define configCHECK_FOR_STACK_OVERFLOW 1
#else
#define configCHECK_FOR_STACK_OVERFLOW 0
#endif

#define configUSE_MALLOC_FAILED_HOOK 0
#define configUSE_MUTEXES 1
#define configUSE_RECURSIVE_MUTEXES 1
Expand Down
2 changes: 2 additions & 0 deletions examples/freertos/src/metrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,7 @@ void memfault_metrics_heartbeat_collect_sdk_data(void) {
MEMFAULT_METRICS_HEARTBEAT_INTERVAL_SECS <= (60 * 60),
"Heartbeat must be an hour or less for runtime metrics to mitigate counter overflow");

#if MEMFAULT_TEST_USE_PORT_TEMPLATE != 1
memfault_freertos_port_task_runtime_metrics();
#endif
}
47 changes: 47 additions & 0 deletions ports/templates/memfault_platform_port.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,53 @@ size_t memfault_platform_sanitize_address_range(void *start_addr, size_t desired
return 0;
}

MEMFAULT_PUT_IN_SECTION(".noinit.mflt_reboot_info")
static uint8_t s_reboot_tracking[MEMFAULT_REBOOT_TRACKING_REGION_SIZE];

void memfault_reboot_reason_get(sResetBootupInfo *info) {
//! !FIXME: Read reboot reason register
//! Fill in sResetBootupInfo with reboot reason and reboot register value
*info = (sResetBootupInfo){
.reset_reason_reg = 0x0,
.reset_reason = kMfltRebootReason_Unknown,
};
}

void memfault_platform_reboot_tracking_boot(void) {
sResetBootupInfo reset_info = { 0 };
memfault_reboot_reason_get(&reset_info);
memfault_reboot_tracking_boot(s_reboot_tracking, &reset_info);
}

//! !FIXME: Remove if using FreeRTOS port. The FreeRTOS port will provide this definition
bool memfault_platform_metrics_timer_boot(uint32_t period_sec,
MemfaultPlatformTimerCallback *callback) {
//! !FIXME: Initiate a periodic timer/task/thread to call callback every period_sec
(void)period_sec;
(void)callback;
return false;
}

//! !FIXME: Remove if using FreeRTOS port. The FreeRTOS port will provide this definition
MEMFAULT_WEAK uint64_t memfault_platform_get_time_since_boot_ms(void) {
//! !FIXME: Return the time since the device booted in milliseconds
return 0;
}

MEMFAULT_PRINTF_LIKE_FUNC(2, 3)
void memfault_platform_log(eMemfaultPlatformLogLevel level, const char *fmt, ...) {
//! !FIXME: Use this function to send logs to your application logging component, serial console,
//! etc
(void)level;
(void)fmt;
}

MEMFAULT_PRINTF_LIKE_FUNC(1, 2) void memfault_platform_log_raw(const char *fmt, ...) {
//! !FIXME: Use this function to send logs to your application logging component, serial console,
//! etc
(void)fmt;
}

//! !FIXME: This function _must_ be called by your main() routine prior
//! to starting an RTOS or baremetal loop.
int memfault_platform_boot(void) {
Expand Down
2 changes: 1 addition & 1 deletion scripts/memfault_gdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ def write(self, out_f):
def _counting_write(data):
# nonlocal total_size # Not python 2.x compatible :(
# total_size += len(data)
total_size["size"] = total_size["size"] + len(data)
total_size["size"] += len(data)

self._write(_counting_write)

Expand Down
3 changes: 2 additions & 1 deletion scripts/mflt-build-id/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ readme = "README.md"
mflt_build_id = 'mflt_build_id:main'

[tool.poetry.dependencies]
python = "^3.6" # must match memfault-cli
# must match memfault-cli
python = "^3.6"
pyelftools = "^0.31"

[tool.poetry.dev-dependencies]
Expand Down

0 comments on commit d53956a

Please sign in to comment.