Skip to content

Commit

Permalink
chore: update app to latest esp32 app
Browse files Browse the repository at this point in the history
  • Loading branch information
gminn committed Oct 16, 2024
1 parent 5dba719 commit 6d19278
Show file tree
Hide file tree
Showing 22 changed files with 88 additions and 121 deletions.
41 changes: 18 additions & 23 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,26 @@ if(DEFINED IDF_VERSION_MAJOR)
endif()
endif()

# Look for the Memfault SDK in a subdirectory first, when this app is used
# standalone (not from within the Memfault SDK)
get_filename_component(memfault_firmware_sdk_dir third-party/memfault-firmware-sdk ABSOLUTE)
if(NOT EXISTS ${memfault_firmware_sdk_dir})
get_filename_component(memfault_firmware_sdk_dir ../../../../ ABSOLUTE)
# If we found the Memfault SDK, include it in the build
if(EXISTS ${memfault_firmware_sdk_dir}/ports/esp_idf/memfault.cmake)
include(${memfault_firmware_sdk_dir}/ports/esp_idf/memfault.cmake)
else()
# Otherwise, append this to the main/idf_component.yml file:
# memfault/memfault-firmware-sdk: "*"
# Ideally we'd push an environment variable and use a conditional dependency
# https://docs.espressif.com/projects/idf-component-manager/en/latest/reference/manifest_file.html#conditional-dependencies
# But that requires idf-component-manager v2+, which is not available on all
# esp-idf versions

# if the string "memfault/memfault-firmware-sdk" isn't in the file, append it:
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/main/idf_component.yml idf_component_yml)
if(NOT idf_component_yml MATCHES "memfault/memfault-firmware-sdk")
file(APPEND ${CMAKE_CURRENT_SOURCE_DIR}/main/idf_component.yml
" memfault/memfault-firmware-sdk: \"*\"\n"
)
endif()
endif()
include(${memfault_firmware_sdk_dir}/ports/esp_idf/memfault.cmake)

# NOTE: This include also applies global compiler options, make sure
# this happens first before defining other targets!
Expand Down Expand Up @@ -63,21 +76,3 @@ if (INVALID_PARTITION_TABLE)
If this error occurs repeatedly run `idf.py fullclean && rm sdkconfig`"
)
endif()

if (CONFIG_MEMFAULT)
# Add the Memfault Build ID so each build can have a unique version.
set(IDF_PROJECT_EXECUTABLE ${PROJECT_NAME}.elf)
add_custom_command(TARGET ${IDF_PROJECT_EXECUTABLE}
POST_BUILD
# Compute and insert the build id
COMMAND python ${memfault_firmware_sdk_dir}/scripts/fw_build_id.py ${IDF_PROJECT_EXECUTABLE}
# Save a copy of the ELF that includes the 'log_fmt' section
BYPRODUCTS ${IDF_PROJECT_EXECUTABLE}.memfault_log_fmt
# Compress debug sections; this reduces the elf file size from ~10MB -> ~4.8MB
COMMAND ${CMAKE_OBJCOPY} --compress-debug-sections ${IDF_PROJECT_EXECUTABLE}
COMMAND ${CMAKE_COMMAND} -E copy ${IDF_PROJECT_EXECUTABLE} ${IDF_PROJECT_EXECUTABLE}.memfault_log_fmt
COMMAND ${CMAKE_COMMAND} -E echo "*** NOTE: the symbol file to upload to app.memfault.com is ${IDF_PROJECT_EXECUTABLE}.memfault_log_fmt ***"
# Remove the 'log_fmt' compact log section, which confuses elf2image
COMMAND ${CMAKE_OBJCOPY} --remove-section log_fmt ${IDF_PROJECT_EXECUTABLE}
)
endif() # NOT CONFIG_MEMFAULT_DISABLE
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ You can either follow the steps outlined here or use your own MQTT setup.

### Broker Setup

1. Install a local installtion of Cedalo by following the [installation guide](https://docs.cedalo.com/management-center/installation/)
1. Install a local installation of Cedalo by following the [installation guide](https://docs.cedalo.com/management-center/installation/)
2. Login to Cedalo at <http://localhost:8088>
3. Create a new client login for the device
- Ensure device client has the "client" role to allow publishing data
Expand All @@ -21,7 +21,8 @@ You can either follow the steps outlined here or use your own MQTT setup.

### Service Setup

1. Modify the script found in Docs->Best Practices->MQTT with Memfault with the the following:
1. Modify the script found in [Docs->Best Practices->MQTT](https://docs.memfault.com/docs/best-practices/mqtt-with-memfault#service-examples)
with Memfault with the the following:
1. The service client login information previously created
2. Connection info for your local broker
3. Map of Memfault projects to project keys
Expand Down
5 changes: 5 additions & 0 deletions main/Kconfig.projbuild
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ config MEMFAULT_APP_WIFI_AUTOJOIN
help
Automatically join if credentials are configured.

config MEMFAULT_APP_HEAP_TRACING
bool "Print allocation tracing information at runtime"
default n
depends on HEAP_USE_HOOKS

choice APP_MEMFAULT_TRANSPORT
prompt "Protocol to send chunks over"
default APP_MEMFAULT_TRANSPORT_HTTP
Expand Down
2 changes: 1 addition & 1 deletion main/app_memfault_transport.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! @file
//!
//! Copyright (c) Memfault, Inc.
//! See License.txt for details
//! See LICENSE for details

#pragma once

Expand Down
2 changes: 1 addition & 1 deletion main/app_memfault_transport_http.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! @file
//!
//! Copyright (c) Memfault, Inc.
//! See License.txt for details
//! See LICENSE for details

#include "app_memfault_transport.h"
#include "memfault/esp_port/http_client.h"
Expand Down
2 changes: 1 addition & 1 deletion main/app_memfault_transport_mqtt.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! @file
//!
//! Copyright (c) Memfault, Inc.
//! See License.txt for details
//! See LICENSE for details

#include <stddef.h>
#include <stdint.h>
Expand Down
16 changes: 11 additions & 5 deletions main/button.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! @file
//!
//! Copyright (c) Memfault, Inc.
//! See License.txt for details
//! See LICENSE for details
//!
//! Button setup and handling

Expand All @@ -11,15 +11,21 @@
#include "esp_attr.h"
#include "esp_log.h"
#include "esp_system.h"
#include "freertos/FreeRTOS.h"

static const char *TAG = "button";
static portMUX_TYPE s_button_spinlock = portMUX_INITIALIZER_UNLOCKED;

static void IRAM_ATTR prv_gpio_isr_handler(void *arg) {
uint32_t gpio_num = (uint32_t)arg;
// Make volatile to prevent compiler optimization in while loop
volatile uint32_t gpio_num = (uint32_t)arg;

// dereference a null point to trigger a crash
volatile uint32_t *ptr = NULL;
*ptr = gpio_num;
// Grab a spinlock to ensure this ISR does not get interrupted
portENTER_CRITICAL_ISR(&s_button_spinlock);
// Hang the interrupt to trigger a fault from the interrupt watchdog
while (true) {
gpio_num++;
}
}

// The flex glitch filter is only available on 5.1. Skip it for earlier SDKs.
Expand Down
2 changes: 1 addition & 1 deletion main/button.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! @file
//!
//! Copyright (c) Memfault, Inc.
//! See License.txt for details
//! See LICENSE for details
//!
//! Button setup and handling

Expand Down
31 changes: 13 additions & 18 deletions main/cmd_app.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! @file
//!
//! Copyright (c) Memfault, Inc.
//! See License.txt for details
//! See LICENSE for details
//! Miscellaneous commands specific to this example app
//!

Expand Down Expand Up @@ -31,17 +31,16 @@ static int test_task_watchdog(int argc, char **argv) {
}
#endif

#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 3, 0)
#if defined(CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK) || \
!defined(CONFIG_FREERTOS_CHECK_STACKOVERFLOW_NONE)
#define OVERFLOW_TASK_STACK_SIZE 4096
#if defined(CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK) || \
!defined(CONFIG_FREERTOS_CHECK_STACKOVERFLOW_NONE)
#define OVERFLOW_TASK_STACK_SIZE 4096

static StaticTask_t s_overflow_task_tcb;
static StackType_t s_overflow_task_stack[OVERFLOW_TASK_STACK_SIZE];
static TaskHandle_t s_overflow_task_handle = NULL;

static void prv_trigger_stack_overflow(void) {
#if defined(CONFIG_FREERTOS_CHECK_STACKOVERFLOW_PTRVAL)
#if defined(CONFIG_FREERTOS_CHECK_STACKOVERFLOW_PTRVAL)
// General idea is to allocate a bunch of memory on the stack but not too much
// to hose FreeRTOS Then yield and the FreeRTOS stack overflow check (on task
// switch) should kick in due to stack pointer limits
Expand All @@ -60,11 +59,11 @@ static void prv_trigger_stack_overflow(void) {
stack_array[i] = i;
taskYIELD();
}
#else
#else
// The canary checks only look at the last bytes (lowest addresses) of the
// stack Execute a write over the last 32 bytes to trigger the watchpoint
memset(s_overflow_task_stack, 0, 32);
#endif // defined(CONFIG_FREERTOS_CHECK_STACKOVERFLOW_PTR)
#endif // defined(CONFIG_FREERTOS_CHECK_STACKOVERFLOW_PTR)
}

/**
Expand Down Expand Up @@ -107,9 +106,8 @@ static void prv_init_stack_overflow_test(void) {
};
ESP_ERROR_CHECK(esp_console_cmd_register(&test_stack_overflow_cmd));
}
#endif // defined(CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK) ||
// !defined(CONFIG_FREERTOS_CHECK_STACKOVERFLOW_NONE)
#endif // ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 3, 0)
#endif // defined(CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK) ||
// !defined(CONFIG_FREERTOS_CHECK_STACKOVERFLOW_NONE)

#if defined(CONFIG_HEAP_TASK_TRACKING)
// Print out per-task heap allocations. This is lifted from the example here:
Expand Down Expand Up @@ -173,12 +171,9 @@ void register_app(void) {
ESP_ERROR_CHECK(esp_console_cmd_register(&heap_task_stats_cmd));
#endif

// Only support the stack overflow test on esp-idf >= 4.3.0
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 3, 0)
#if defined(CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK) || \
!defined(CONFIG_FREERTOS_CHECK_STACKOVERFLOW_NONE)
#if defined(CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK) || \
!defined(CONFIG_FREERTOS_CHECK_STACKOVERFLOW_NONE)
prv_init_stack_overflow_test();
#endif // defined(CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK) ||
// !defined(CONFIG_FREERTOS_CHECK_STACKOVERFLOW_NONE)
#endif // ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 3, 0)
#endif // defined(CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK) ||
// !defined(CONFIG_FREERTOS_CHECK_STACKOVERFLOW_NONE)
}
2 changes: 1 addition & 1 deletion main/cmd_wifi.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! @file
//!
//! Copyright (c) Memfault, Inc.
//! See License.txt for details
//! See LICENSE for details
//!
//! Wifi-specific commands for the ESP32 console.

Expand Down
8 changes: 1 addition & 7 deletions main/cmd_wifi_legacy.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! @file
//!
//! Copyright (c) Memfault, Inc.
//! See License.txt for details
//! See LICENSE for details
//!
//! Version of cmd_wifi.c that uses the legacy wifi API, for ESP-IDF v3.

Expand Down Expand Up @@ -34,12 +34,6 @@ static char s_wifi_pass[WIFI_CREDS_MAX_SIZE];
static EventGroupHandle_t wifi_event_group;
const int CONNECTED_BIT = BIT0;

// this type changed in ESP-IDF v4.0, to 'nvs_handle_t'; add a backwards-compat
// typedef
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(4, 0, 0)
typedef nvs_handle nvs_handle_t;
#endif

int wifi_get_project_key(char *project_key, size_t project_key_len) {
// Configurable project key not supported, project key must be compiled in via
// CONFIG_MEMFAULT_PROJECT_KEY
Expand Down
2 changes: 1 addition & 1 deletion main/config/memfault_platform_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! @file
//!
//! Copyright (c) Memfault, Inc.
//! See License.txt for details
//! See LICENSE for details
//!
//! Platform overrides for the default configuration settings in the memfault-firmware-sdk.
//! Default configuration settings can be found in "memfault/config.h"
Expand Down
2 changes: 1 addition & 1 deletion main/led.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! @file
//!
//! Copyright (c) Memfault, Inc.
//! See License.txt for details
//! See LICENSE for details
//!
//! Module for controlling the RGB LED. Implementation varies depending on which
//! target board; the ESP32-WROVER has a 3-gpio LED, while the ESP32-S3-DevKitC
Expand Down
2 changes: 1 addition & 1 deletion main/led.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! @file
//!
//! Copyright (c) Memfault, Inc.
//! See License.txt for details
//! See LICENSE for details
//!
//! LED control module header.

Expand Down
Loading

0 comments on commit 6d19278

Please sign in to comment.