Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,78 @@ config MEMFAULT_APP_OVERRIDE_SOFTWARE_VERSION
Set this to override the built-in software version string from the
VERSION file. Primarily used for building in CI.

config WIFI_WATCHDOG_ENABLE
bool "Enable WiFi watchdog"
default y
depends on WIFI && MEMFAULT
help
Enable WiFi watchdog that monitors WiFi connectivity and reboots
if a known network is available but not connected for a configurable
period of time.

config WIFI_WATCHDOG_TIMEOUT_MINUTES
int "WiFi watchdog timeout in minutes"
default 5
depends on WIFI_WATCHDOG_ENABLE
help
Time in minutes to wait before triggering a reboot when WiFi
credentials are configured, a known network is detected, but
WiFi is not connected.

config WIFI_WATCHDOG_CHECK_INTERVAL_SECONDS
int "WiFi watchdog check interval in seconds"
default 30
depends on WIFI_WATCHDOG_ENABLE
help
Interval in seconds between WiFi watchdog checks.

config SNTP_TIME_SYNC_ENABLE
bool "Enable SNTP time synchronization"
default y
depends on SNTP && WIFI
help
Synchronizes the kernel real-time clock via an NTP server each time
a WiFi connection is established, and then periodically at the
interval set by SNTP_TIME_SYNC_RESYNC_INTERVAL_SECONDS.
Uses the Zephyr SNTP client (sntp_init/query/close) directly.

config SNTP_TIME_SYNC_SERVER
string "NTP server hostname"
default "pool.ntp.org"
depends on SNTP_TIME_SYNC_ENABLE
help
Hostname of the NTP server to query for time synchronization.

config SNTP_TIME_SYNC_RESYNC_INTERVAL_SECONDS
int "Periodic SNTP re-sync interval (seconds)"
default 21600 # 6 hours
depends on SNTP_TIME_SYNC_ENABLE
help
How often to re-sync the clock while WiFi is connected.
The initial sync is triggered immediately on WiFi connect.

choice HEARTBEAT_LED_TYPE
prompt "Select heartbeat LED variant"
default HEARTBEAT_LED_STRIP if $(dt_alias_enabled,led-strip)
default HEARTBEAT_LED_GPIO if $(dt_alias_enabled,heartbeat-led)

config HEARTBEAT_LED_STRIP
bool "WS2812 RGB LED strip"
depends on LED_STRIP
help
Enable heartbeat LED using a WS2812 RGB LED strip.
GREEN when WiFi is connected, RED otherwise.
Blinks at a 1-second interval.

config HEARTBEAT_LED_GPIO
bool "GPIO LED"
depends on GPIO
help
Enable heartbeat LED using a simple GPIO-driven LED.
Blinks at a 1-second interval unconditionally.

endchoice

endmenu

config MEMFAULT_BUILTIN_DEVICE_INFO_SOFTWARE_VERSION
Expand Down
44 changes: 44 additions & 0 deletions boards/esp32c3_devkitm.overlay
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,54 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/dt-bindings/led/led.h>

&wifi {
status = "okay";
};

&coretemp {
status = "okay";
};

/ {
aliases {
led-strip = &led_strip;
};
};

/* WS2812 RGB LED on GPIO8 via SPI2 */
&spi2 {
/* Workaround to support WS2812 driver */
line-idle-low;

led_strip: ws2812@0 {
compatible = "worldsemi,ws2812-spi";

/* SPI */
reg = <0>;
spi-max-frequency = <6400000>;

/* WS2812 */
chain-length = <1>;
spi-cpha;
spi-one-frame = <0xf0>;
spi-zero-frame = <0xc0>;
color-mapping = <LED_COLOR_ID_GREEN LED_COLOR_ID_RED LED_COLOR_ID_BLUE>;
};
};

&pinctrl {
spim2_default: spim2_default {
group2 {
/* WS2812 data on GPIO8 */
pinmux = <SPIM2_MOSI_GPIO8>;
};
};
};

/* Enable the ESP32-C3 RTC timer counter so it can be used for time persistence
* across soft resets via the counter API and __noinit RAM anchor. */
&rtc_timer {
status = "okay";
};
3 changes: 3 additions & 0 deletions boards/esp32c6_devkitc_esp32c6_hpcore.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Enable DMA for heartbeat LED
CONFIG_DMA=y
CONFIG_LED_STRIP=y
41 changes: 41 additions & 0 deletions boards/esp32c6_devkitc_esp32c6_hpcore.overlay
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,51 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/dt-bindings/led/led.h>

&wifi {
status = "okay";
};

&coretemp {
status = "okay";
};

/ {
aliases {
led-strip = &led_strip;
};
};

/* WS2812 RGB LED on GPIO8 via I2S */
&i2s_default {
group1 {
pinmux = <I2S_O_SD_GPIO8>;
};
};

i2s_led: &i2s {
status = "okay";

dmas = <&dma 3>;
dma-names = "tx";

led_strip: ws2812@0 {
compatible = "worldsemi,ws2812-i2s";

reg = <0>;
chain-length = <1>;
color-mapping = <LED_COLOR_ID_GREEN LED_COLOR_ID_RED LED_COLOR_ID_BLUE>;
reset-delay = <500>;
};
};

&dma {
status = "okay";
};

/* Enable the ESP32-C6 RTC timer counter so it can be used for time persistence
* across soft resets via the counter API and __noinit RAM anchor. */
&rtc_timer {
status = "okay";
};
4 changes: 4 additions & 0 deletions boards/esp32s3_devkitc_esp32s3_procpu.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Enable external SPI RAM
CONFIG_SPI=y
CONFIG_ESP_SPIRAM=y

# Enable DMA for heartbeat LED
CONFIG_DMA=y
CONFIG_LED_STRIP=y
41 changes: 41 additions & 0 deletions boards/esp32s3_devkitc_esp32s3_procpu.overlay
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/dt-bindings/led/led.h>

&wifi {
status = "okay";
};
Expand All @@ -16,3 +18,42 @@
&psram0 {
size = <DT_SIZE_M(2)>;
};

/ {
aliases {
led-strip = &led_strip;
};
};

/* WS2812 RGB LED on GPIO38 via I2S0 */
&i2s0_default {
group1 {
pinmux = <I2S0_O_SD_GPIO38>;
};
};

i2s_led: &i2s0 {
status = "okay";

dmas = <&dma 3>;
dma-names = "tx";

led_strip: ws2812@0 {
compatible = "worldsemi,ws2812-i2s";

reg = <0>;
chain-length = <1>;
color-mapping = <LED_COLOR_ID_GREEN LED_COLOR_ID_RED LED_COLOR_ID_BLUE>;
reset-delay = <500>;
};
};

&dma {
status = "okay";
};

/* Enable the ESP32-S3 RTC timer counter so it can be used for time persistence
* across soft resets via the counter API and __noinit RAM anchor. */
&rtc_timer {
status = "okay";
};
3 changes: 3 additions & 0 deletions boards/esp32s3_devkitm_esp32s3_procpu.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Enable DMA + LED_STRIP for heartbeat LED
CONFIG_DMA=y
CONFIG_LED_STRIP=y
44 changes: 44 additions & 0 deletions boards/esp32s3_devkitm_esp32s3_procpu.overlay
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,54 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/dt-bindings/led/led.h>

&wifi {
status = "okay";
};

&coretemp {
status = "okay";
};

/* Enable the ESP32-S3 RTC timer counter so it can be used for time persistence
* across soft resets via the counter API and __noinit RAM anchor. */
&rtc_timer {
status = "okay";
};

/ {
aliases {
led-strip = &led_strip;
};
};

/* WS2812 RGB LED on GPIO48 via SPI3 */
&spi3 {
/* Workaround to support WS2812 driver */
line-idle-low;

led_strip: ws2812@0 {
compatible = "worldsemi,ws2812-spi";

/* SPI */
reg = <0>;
spi-max-frequency = <6400000>;

/* WS2812 */
chain-length = <1>;
spi-cpha;
spi-one-frame = <0xf0>;
spi-zero-frame = <0xc0>;
color-mapping = <LED_COLOR_ID_GREEN LED_COLOR_ID_RED LED_COLOR_ID_BLUE>;
};
};

&pinctrl {
spim3_default: spim3_default {
group2 {
/* WS2812 data on GPIO48 */
pinmux = <SPIM3_MOSI_GPIO48>;
};
};
};
1 change: 1 addition & 0 deletions boards/esp_wrover_kit_procpu.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CONFIG_HEARTBEAT_LED_GPIO=y
12 changes: 12 additions & 0 deletions boards/esp_wrover_kit_procpu.overlay
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
&wifi {
status = "okay";
};

/* Enable the ESP32 RTC timer counter so it can be used for time persistence
* across soft resets via the counter API and __noinit RAM anchor. */
&rtc_timer {
status = "okay";
};

/ {
aliases {
heartbeat-led = &red_led;
};
};
11 changes: 11 additions & 0 deletions config/memfault_metrics_heartbeat_config.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Define the WiFi scan result count max metric
// This tracks the maximum number of WiFi scan results seen during each heartbeat period
MEMFAULT_METRICS_KEY_DEFINE(wifi_scan_result_count_max, kMemfaultMetricType_Unsigned)

// Number of successful SNTP time synchronizations in this heartbeat period
MEMFAULT_METRICS_KEY_DEFINE(sntp_sync_count, kMemfaultMetricType_Unsigned)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: sntp_sync_successful_count would be a bit more specific here (granted, I might not think this if I wasn't biased with sync_success/ sync_failure device vitals 😅)


// Clock error corrected by the most recent SNTP sync (seconds, signed).
// Only recorded when the system clock was already valid (> 2023) before the
// sync, so the initial 1970-epoch → real-time jump is excluded.
MEMFAULT_METRICS_KEY_DEFINE(sntp_sync_delta_seconds, kMemfaultMetricType_Signed)
2 changes: 2 additions & 0 deletions config/memfault_reboot_reason_user_config.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Wi-Fi Watchdog is not desirable, but should not impact stability score.
MEMFAULT_EXPECTED_REBOOT_REASON_DEFINE(WifiWatchdog)
Loading