Skip to content

Commit

Permalink
Memfault Firmware SDK 0.31.0 (Build 451641)
Browse files Browse the repository at this point in the history
  • Loading branch information
Memfault Inc committed Jun 6, 2022
1 parent bdacc2d commit cdb5fdb
Show file tree
Hide file tree
Showing 22 changed files with 741 additions and 59 deletions.
27 changes: 27 additions & 0 deletions .cyignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
cmake
examples
makefile
ports/atmel
ports/dialog
ports/emlib
ports/esp8266_sdk
ports/esp_idf
ports/mynewt
ports/nrf5_sdk
ports/nxp
ports/particle
ports/qp
ports/s32sdk
ports/stm32cube
ports/templates
ports/zephyr
scripts
tests
$(SEARCH_memfault-firmware-sdk)/components/include/memfault/core
$(SEARCH_memfault-firmware-sdk)/components/include/memfault/demo
$(SEARCH_memfault-firmware-sdk)/components/include/memfault/http
$(SEARCH_memfault-firmware-sdk)/components/include/memfault/metrics
$(SEARCH_memfault-firmware-sdk)/components/include/memfault/panics
$(SEARCH_memfault-firmware-sdk)/components/include/memfault/util
$(SEARCH_memfault-firmware-sdk)/ports/include/memfault/ports/ble
$(SEARCH_memfault-firmware-sdk)/ports/include/memfault/ports/stm32cube
18 changes: 18 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
### Changes between Memfault SDK 0.31.0 and SDK 0.30.5 - June 6, 2022

#### :chart_with_upwards_trend: Improvements

- Added reference port for [CAT1A (PSoC:tm: 6)](https://github.com/Infineon/mtb-pdl-cat1) based
MCUs using the
[ModusToolbox:tm: Software](https://www.infineon.com/cms/en/design-support/tools/sdk/modustoolbox-software/)
stack. For more details see [ports/cypress/psoc6](ports/cypress/psoc6) directory.
- - Added a convenience utility function for posting chunks using the Memfault http client. See
[`memfault_http_client_post_chunk`](components/include/memfault/http/http_client.h#L101)
for more details!

#### :house: Internal

- Fixed compiler error in
[nRF91 sample test app](examples/nrf-connect-sdk/nrf9160/memfault_demo_app)
when compiling with the nRF Connect SDK 1.8 release

### Changes between Memfault SDK 0.30.5 and SDK 0.30.4 - May 24, 2022

#### :rocket: New Features
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: 447316
GIT COMMIT: 77b7799c5
BUILD ID: 451641
GIT COMMIT: 963211879
17 changes: 1 addition & 16 deletions components/demo/src/http/memfault_demo_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,5 @@ const char *memfault_demo_get_api_project_key(void) {
int memfault_demo_cli_cmd_post_core(MEMFAULT_UNUSED int argc,
MEMFAULT_UNUSED char *argv[]) {
MEMFAULT_LOG_INFO("Posting Memfault Data...");
sMfltHttpClient *http_client = memfault_http_client_create();
if (!http_client) {
MEMFAULT_LOG_ERROR("Failed to create HTTP client");
return MemfaultInternalReturnCode_Error;
}

const int rv = memfault_http_client_post_data(http_client);
if ((eMfltPostDataStatus)rv == kMfltPostDataStatus_NoDataFound) {
MEMFAULT_LOG_INFO("No new data found");
} else {
MEMFAULT_LOG_INFO("Result: %d", rv);
}
const uint32_t timeout_ms = 30 * 1000;
memfault_http_client_wait_until_requests_completed(http_client, timeout_ms);
memfault_http_client_destroy(http_client);
return rv;
return memfault_http_client_post_chunk();
}
38 changes: 38 additions & 0 deletions components/http/src/memfault_http_client_post_chunk.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//! @file
//!
//! Copyright (c) Memfault, Inc.
//! See License.txt for details
//!
//! @brief
//! Implements conveninece API for posting a single chunk of Memfault data

#include "memfault/http/http_client.h"

#include "memfault/core/debug_log.h"
#include "memfault/core/errors.h"
#include "memfault/core/data_packetizer.h"

int memfault_http_client_post_chunk(void) {
// A pre-flight check before we attempt to setup an HTTP client
// If there's no data to send, just early return
bool more_data = memfault_packetizer_data_available();
if (!more_data) {
// no new data to post
return kMfltPostDataStatus_NoDataFound;
}

sMfltHttpClient *http_client = memfault_http_client_create();
if (!http_client) {
MEMFAULT_LOG_ERROR("Failed to create HTTP client");
return MemfaultInternalReturnCode_Error;
}

const int rv = memfault_http_client_post_data(http_client);
if ((eMfltPostDataStatus)rv != kMfltPostDataStatus_Success) {
MEMFAULT_LOG_ERROR("Failed to post chunk: rv=%d", rv);
}
const uint32_t timeout_ms = 30 * 1000;
memfault_http_client_wait_until_requests_completed(http_client, timeout_ms);
memfault_http_client_destroy(http_client);
return rv;
}
6 changes: 6 additions & 0 deletions components/include/memfault/http/http_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ typedef enum {
//! if no data was found or else an error code.
int memfault_http_client_post_data(sMfltHttpClient *client);

//! Create a http client, post a chunk of data and then teardown the connection
//!
//! @return kMfltPostDataStatus_Success on success, kMfltPostDataStatus_NoDataFound
//! if no data was found or else an error code.
int memfault_http_client_post_chunk(void);

//! Waits until pending requests have been completed.
//! @param client The http client.
//! @return 0 on success, else error code
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 = 30, .patch = 5 }
#define MEMFAULT_SDK_VERSION { .major = 0, .minor = 31, .patch = 0 }

#ifdef __cplusplus
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ if (NCS_VERSION_MAJOR)
set(CONFIG_NEWLIB_LIBC y CACHE INTERNAL "")
endif()

# These were removed in NCS 1.9, but are needed prior to that.
if (${NCS_VERSION_MAJOR} LESS_EQUAL 1 AND ${NCS_VERSION_MINOR} LESS 9 AND ${NCS_VERSION_PATCH} LESS 99)
# These were removed in NCS 1.8.0, but are needed prior to that. Enable them
# if NCS version <1.7.99 (.99 patch version is used for the next revision's
# development series)
if (${NCS_VERSION_MAJOR}.${NCS_VERSION_MINOR}.${NCS_VERSION_PATCH} VERSION_LESS 1.7.99)
set(CONFIG_BSD_LIBRARY y CACHE INTERNAL "")
set(CONFIG_BSD_LIBRARY_SYS_INIT n CACHE INTERNAL "")
# ^ Note: CONFIG_BSD_ were renamed to _NRF_MODEM_ in
Expand Down
45 changes: 24 additions & 21 deletions examples/wiced/libraries/memfault/http/http.mk
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
NAME := MemfaultHttp

$(NAME)_SOURCES := src/memfault_http_client.c \
$(NAME)_SOURCES := \
src/memfault_http_client.c \
src/memfault_http_client_post_chunk.c


$(NAME)_COMPONENTS := libraries/memfault/core \
libraries/memfault/panics \
protocols/HTTP_client \

$(NAME)_COMPONENTS := \
libraries/memfault/core \
libraries/memfault/panics \
protocols/HTTP_client

$(NAME)_INCLUDES += include

GLOBAL_INCLUDES += include

VALID_OSNS_COMBOS := ThreadX-NetX_Duo FreeRTOS-LwIP
VALID_PLATFORMS := BCM943362WCD4 \
BCM943362WCD6 \
BCM943362WCD8 \
BCM943364WCD1 \
CYW94343WWCD1_EVB \
BCM943438WCD1 \
BCM94343WWCD2 \
CY8CKIT_062 \
NEB1DX* \
CYW9MCU7X9N364 \
CYW943907AEVAL1F \
CYW954907AEVAL1F \
CYW9WCD2REFAD2* \
CYW9WCD760PINSDAD2 \
CYW943455EVB* \
CYW943012EVB*
VALID_PLATFORMS := \
BCM943362WCD4 \
BCM943362WCD6 \
BCM943362WCD8 \
BCM943364WCD1 \
CYW94343WWCD1_EVB \
BCM943438WCD1 \
BCM94343WWCD2 \
CY8CKIT_062 \
NEB1DX* \
CYW9MCU7X9N364 \
CYW943907AEVAL1F \
CYW954907AEVAL1F \
CYW9WCD2REFAD2* \
CYW9WCD760PINSDAD2 \
CYW943455EVB* \
CYW943012EVB*
4 changes: 4 additions & 0 deletions ports/cypress/psoc6/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Memfault Library for ModusToolbox:tm:

To get started with the Memfault ModusToolbox:tm: port see the integration guide
available [here](https://mflt.io/mtb-integration-guide).
16 changes: 16 additions & 0 deletions ports/cypress/psoc6/memfault_bss.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
Custom section to be included in the linker command file to support recovery of all FreeRTOS tasks when
a coredump is collected.
*/

SECTIONS
{
.mflt_bss (NOLOAD) :
{
__memfault_capture_bss_start = .;
*tasks.o(.bss COMMON .bss*)
*timers*.o(.bss COMMON .bss*)
__memfault_capture_bss_end = .;
}
}
INSERT BEFORE .bss;
65 changes: 65 additions & 0 deletions ports/cypress/psoc6/memfault_platform_core.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//! @file
//!
//! Copyright (c) Memfault, Inc.
//! See License.txt for details
//!
//! @brief
//! Implementation of core dependencies and setup for PSOC6 based products that are using the
//! ModusToolbox SDK

#include "memfault/components.h"
#include "memfault/ports/reboot_reason.h"
#include "memfault/ports/freertos.h"

#ifndef MEMFAULT_EVENT_STORAGE_RAM_SIZE
#define MEMFAULT_EVENT_STORAGE_RAM_SIZE 1024
#endif

MEMFAULT_WEAK
void memfault_platform_reboot(void) {
NVIC_SystemReset();
while (1) { } // unreachable
}

size_t memfault_platform_sanitize_address_range(void *start_addr, size_t desired_size) {
static const struct {
uint32_t start_addr;
size_t length;
} s_mcu_mem_regions[] = {
{.start_addr = CY_SRAM_BASE, .length = CY_SRAM_SIZE},
};

for (size_t i = 0; i < MEMFAULT_ARRAY_SIZE(s_mcu_mem_regions); i++) {
const uint32_t lower_addr = s_mcu_mem_regions[i].start_addr;
const uint32_t upper_addr = lower_addr + s_mcu_mem_regions[i].length;
if ((uint32_t)start_addr >= lower_addr && ((uint32_t)start_addr < upper_addr)) {
return MEMFAULT_MIN(desired_size, upper_addr - (uint32_t)start_addr);
}
}

return 0;
}

int memfault_platform_boot(void) {
memfault_build_info_dump();
memfault_device_info_dump();

memfault_freertos_port_boot();
memfault_platform_reboot_tracking_boot();

static uint8_t s_event_storage[MEMFAULT_EVENT_STORAGE_RAM_SIZE];
const sMemfaultEventStorageImpl *evt_storage =
memfault_events_storage_boot(s_event_storage, sizeof(s_event_storage));
memfault_trace_event_boot(evt_storage);

memfault_reboot_tracking_collect_reset_info(evt_storage);

sMemfaultMetricBootInfo boot_info = {
.unexpected_reboot_count = memfault_reboot_tracking_get_crash_count(),
};
memfault_metrics_boot(evt_storage, &boot_info);

MEMFAULT_LOG_INFO("Memfault Initialized!");

return 0;
}
87 changes: 87 additions & 0 deletions ports/cypress/psoc6/memfault_platform_coredump_regions.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
//! @file
//!
//! Copyright (c) Memfault, Inc.
//! See License.txt for details
//!
//! @brief
//! A coredump port which scoops up all the FreeRTOS state in the system at the time of crash
//! To override and provide a custom port, simply add this file to the .cyignore for your project
//! so it is not included in the build:
//! (i.e $(SEARCH_memfault-firmware-sdk)/ports/cypress/psoc6/memfault_platform_coredump_regions.c)

#include <stddef.h>
#include <string.h>

#include "memfault/components.h"
#include "memfault/panics/arch/arm/cortex_m.h"
#include "memfault/ports/freertos_coredump.h"

#include "cy_syslib.h"
#include "cy_device_headers.h"

#define MEMFAULT_COREDUMP_MAX_TASK_REGIONS ((MEMFAULT_PLATFORM_MAX_TRACKED_TASKS) * 2)

static sMfltCoredumpRegion s_coredump_regions[
MEMFAULT_COREDUMP_MAX_TASK_REGIONS
+ 2 /* active stack(s) */
+ 1 /* _kernel variable */
+ 1 /* __memfault_capture_start */
];

//! Note: If you get a linker error because these symbols are missing, your forgot to add the Memfault ld file
//! to you LDFLAGS:
//! LDFLAGS += -T$(SEARCH_memfault-firmware-sdk)/ports/cypress/psoc6/memfault_bss.ld
extern uint32_t __memfault_capture_bss_end;
extern uint32_t __memfault_capture_bss_start;

//! Note: This function is called early on boot before the C runtime is loaded
//! We hook into this function in order to scrub the
void Cy_OnResetUser(void) {
const size_t memfault_region_size = (uint32_t)&__memfault_capture_bss_end -
(uint32_t)&__memfault_capture_bss_start;
memset((uint32_t*)&__memfault_capture_bss_start, 0x0, memfault_region_size);
}

const sMfltCoredumpRegion *memfault_platform_coredump_get_regions(
const sCoredumpCrashInfo *crash_info, size_t *num_regions) {
int region_idx = 0;
const size_t active_stack_size_to_collect = 512;

// first, capture the active stack (and ISR if applicable)
const bool msp_was_active = (crash_info->exception_reg_state->exc_return & (1 << 2)) == 0;

size_t stack_size_to_collect = memfault_platform_sanitize_address_range(
crash_info->stack_address, MEMFAULT_PLATFORM_ACTIVE_STACK_SIZE_TO_COLLECT);

s_coredump_regions[region_idx] = MEMFAULT_COREDUMP_MEMORY_REGION_INIT(
crash_info->stack_address, stack_size_to_collect);
region_idx++;

if (msp_was_active) {
// System crashed in an ISR but the running task state is on PSP so grab that too
void *psp = (void *)(uintptr_t)__get_PSP();

// Collect a little bit more stack for the PSP since there is an
// exception frame that will have been stacked on it as well
const uint32_t extra_stack_bytes = 128;
stack_size_to_collect = memfault_platform_sanitize_address_range(
psp, active_stack_size_to_collect + extra_stack_bytes);
s_coredump_regions[region_idx] = MEMFAULT_COREDUMP_MEMORY_REGION_INIT(
psp, stack_size_to_collect);
region_idx++;
}

// Scoop up memory regions necessary to perform unwinds of the FreeRTOS tasks
const size_t memfault_region_size = (uint32_t)&__memfault_capture_bss_end -
(uint32_t)&__memfault_capture_bss_start;

s_coredump_regions[region_idx] = MEMFAULT_COREDUMP_MEMORY_REGION_INIT(
&__memfault_capture_bss_start, memfault_region_size);
region_idx++;

region_idx += memfault_freertos_get_task_regions(&s_coredump_regions[region_idx],
MEMFAULT_ARRAY_SIZE(s_coredump_regions) - region_idx);

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

0 comments on commit cdb5fdb

Please sign in to comment.