Memfault Firmware SDK

repository·master·Indexed 42 days ago

https://github.com/memfault/memfault-firmware-sdk

A modular collection of C components for embedded developers to monitor device health, handle faults (coredumps), and track metrics. Features include reboot tracking, event storage, a lightweight logging infrastructure, and a Metrics API for monitoring connectivity, battery life, and MCU resource utilization.

Tokens
23.8K
Snippets
63
Records
123
Agent score
54%

What's inside Memfault Firmware SDK

  1. Overview of the Memfault SDK util component

    master

    The util component provides a collection of lightweight, specialized utilities designed to support Memfault services within firmware. It includes implementations for data encoding, error detection, and data transport management.

    Key utilities provided:

    • Encoding/Decoding: Base-64 encoder, RLE (Run-Length Encoding) encoder, and a minimal CBOR (Concise Binary Object Representation) implementation.
    • Data Integrity: CCITT CRC16 calculator.
    • Data Structures: Circular buffer implementation.
    • Integer Encoding: Base-128 Varint utilities.
    • Transport: Memfault chunk transport utilities, which ensure that data chunks are correctly mapped to device MTU (Maximum Transmission Unit) sizes.
  2. Overview of the panics component

    master

    The panics component provides the core infrastructure for:

    • Fault handling: Managing system exceptions and crashes.
    • Coredump: Capturing the state of memory at the time of a fault.
    • Reboot tracking: Monitoring device restarts.
    • Reboot loop detection: Identifying if a device is stuck in a continuous crash/reboot cycle.

    For detailed API usage, refer to the documentation provided within the header files.

  3. Use the demo component for platform-agnostic demo apps

    master

    The demo component provides common code used by demo applications across various platforms. It is designed to facilitate bringup and initial integrations.

    Note that the component includes a collection of CLI commands. If you are using the provided CMake or Make build system helpers, these commands are conditionally included: they will only be compiled into your binary if the demo component is explicitly enabled and selected.

  4. Use Memfault Port Files for STM32CubeSDK

    master

    The STM32CubeSDK port files provide platform-specific implementations for select STM32 chip families. These ports allow the Memfault SDK to interface with STM32 hardware to provide:

    • Reboot Reason: Identifying why the device restarted.
    • Coredump Platform Storage: Managing the storage of crash data.
    • Watchdog Integration: Interfacing with hardware watchdog timers.

    These ports are designed to work alongside the STM32CubeSDK CMSIS and HAL layers. To use them, you must ensure you have the appropriate STM32CubeSDK installed for your specific chip family. You can find the list of publicly available STM32CubeSDKs from STMicroelectronics via their official GitHub repository.

  5. Explore Example Platform Ports and Demo Applications

    master

    The Memfault SDK provides example integrations for various development boards. These serve as references for implementing your own integration or exploring SDK features.

    Supported platforms include:

    • nRF5 SDK / Nordic nRF52840 (PCA10056)
    • Quantum Leap Quantum Platform in C / STMicroelectronics STM32F4 series (STM32F407G-DISC1)
    • WICED SDK / Cypress BCM943364WCD1
    • Zephyr / STMicroelectronics STM32L4 series (B-L475E-IOT01A Discovery kit)
    • Amazon FreeRTOS / Cypress PSoC 64 MCU (CY8CKIT-064S0S2-4343W)
    • Dialog DA145xx and DA1469x
    • Espressif ESP-IDF / ESP32 (ESP-WROVER-KIT)
    • nRF Connect SDK / Nordic nRF9160 (PCA10090)
  6. Understand the CY8CKIT-064S0S2-4343W Port Structure

    master

    The port for this evaluation kit is organized into several key files that handle different aspects of the Memfault integration:

    • memfault_platform_port.c: Handles device information, system reboots, memory range definitions, reboot reason detection, logging, and the Memfault/FreeRTOS boot setup.
    • memfault_platform_storage.c/h: Implements the I/O operations required to write coredumps to the flash memory region and manage the device memory regions to be dumped.
    • memfault_test.c/h: Provides utility functions for testing Memfault features, such as on-demand heartbeat, trace, and fault generation.

    Note on Coredumps: Coredumps on this port include the data, bss, and stack regions.

  7. Monitor device health with the Memfault Metrics API

    master

    The Memfault Metrics API allows you to monitor device health over time, including metrics such as connectivity, battery life, MCU resource utilization, and hardware degradation. These metrics can be uploaded to the Memfault cloud and used to configure Alerts in the Memfault backend.

    For a detailed getting started guide, refer to the official documentation at https://mflt.io/2D8TRLX.

  8. Example integrations for Dialog Semiconductor Wireless MCUs

    master
    This directory contains example implementations of the Memfault coredump feature specifically for Dialog Semiconductor Wireless MCUs. Each subdirectory provides a unique integration pattern and detailed instructions on how to incorporate Memfault into a target Dialog Wireless MCU device.
  9. Core features of the Memfault SDK

    master

    The core component provides the fundamental building blocks for the SDK:

    • Build ID: Identifies the specific build used.
    • Packetizing and Serialization: Handles the formatting of data for transmission to the Memfault cloud.
    • Event Storage: Manages storage for metrics, heartbeats, reboot reasons, and trace events. RAM-based events can be persisted to NVRAM using user-installed callbacks.
    • Logging Support: A lightweight logging infrastructure with level filtering. It supports user-installable callbacks to drain logs to slower mediums (NVRAM, serial). Logs are automatically uploaded during crashes or when memfault_log_trigger_collection() is called.
    • Reboot Tracking: Captures reset causes in a dedicated, protected RAM section that remains unmodified during resets.
    • Memfault Assert: A macro that can halt execution if a debugger is attached and trigger a user-defined function.
    • Trace Event Capturing: Provides mechanisms for capturing trace events.
  10. Overview of Memfault SDK components

    master

    The SDK is modular, allowing you to include only the components required for your project to minimize impact on code-space, bandwidth, and power consumption.

    Main Components

    • panics: Handles fault handling, coredump, reboot tracking, and reboot loop detection.
    • metrics: Monitors device health (e.g., connectivity, battery life, MCU resource utilization, hardware degradation).

    Support Components

    • core: Common code used by all other components.
    • demo: Common code used by demo applications across various platforms.
    • http: HTTP client API for posting coredumps and events directly to the Memfault service.
    • util: Various utility functions.

    Platform Abstraction

    Each component relies on platform header files that define interfaces you must implement. To assist with this:

    • Ports: Check the ports/ folder for implementations you can link directly or use as templates.
    • Examples: Check the examples/ folder for reference implementations for popular MCUs and vendor SDKs.
  11. Configure Application Metrics and Heartbeat Intervals

    master

    The demo application illustrates how to create metrics to monitor system performance, such as FreeRTOS heap usage.

    Example Metrics

    • FreeRTOS_HeapFreeBytes: Current total bytes free in the FreeRTOS heap.
    • FreeRTOS_HeapMinFreeBytes: Lowest total bytes free in the FreeRTOS heap since boot.
    • FreeRTOS_Heap_pct_max: Maximum percentage of the FreeRTOS heap used since boot.

    Adjusting Collection Frequency

    Metrics are collected at a regular interval. In this example, they are collected every 60 seconds. To change this frequency, modify the MEMFAULT_METRICS_HEARTBEAT_INTERVAL_SECS constant in memfault_platform_config.h.