This sample app is based on the Zephyr samples/net/wifi
example. It
demonstrates a Zephyr + ESP32 integration with the Memfault SDK. It has been
tested on the following boards:
esp32s3_devkitm/esp32s3/procpu
(default board)esp32c3_devkitm
*
* _NOTE: Currently does not have support for data upload. Export chunks to memfault with mflt export
and upload via the chunks debug log.
The Memfault Zephyr integration guide is an excellent reference, and documents how the Memfault SDK was added to the base example app:
https://docs.memfault.com/docs/mcu/zephyr-guide
To try out this example app:
-
Set up the Zephyr prerequisites: https://docs.zephyrproject.org/latest/develop/getting_started/index.html
-
Create a zephyr workspace and set it up with this project:
mkdir zephyr-workspace cd zephyr-workspace west init -m https://github.com/memfault/zephyr-esp32-example west update
-
Build the example app:
west build zephyr-esp32-example --sysbuild
--sysbuild
will build the MCUboot image as well, which will also get flashed in the following step. To run sysbuild by default, you can configure your workspace withwest config --local build.sysbuild True
. -
Flash the example app:
west flash
-
Open a serial console and interact with the sample app shell. For example using PySerial:
# select the correct serial port for your system pyserial-miniterm --raw /dev/serial/by-id/usb-Silicon_Labs_CP2102N_USB_to_UART_Bridge_Controller_1cd857b4d5a0eb11bf35cdacdf749906-if00-port0 115200 uart:~$ mflt get_device_info [00:09:21.911,000] <inf> mflt: S/N: DEMOSERIAL [00:09:21.911,000] <inf> mflt: SW type: zephyr-app [00:09:21.911,000] <inf> mflt: SW version: 0.0.1727a85c [00:09:21.911,000] <inf> mflt: HW version: esp32c3_devkitm # connect wifi uart:~$ wifi connect -s "<ssid>" -k <key type> -p "<pw>" # test memfault export over uart uart:~$ mflt export MC:CAKnAgIDAQpqemVwaHlyLWFwcAltMS4wLjArZDU5MmRhOAZvZXNwMzJjM19kZXZraXRtC0Z1sxH2/usEogEABQAISg==:
The payload to upload to Memfault is:
build/zephyr-esp32-example/zephyr/zephyr.signed.confirmed.bin
This file is set as "confirmed", so it won't revert after 1 boot cycle (not safe against bootloops!). See the Zephyr documentation for details.
Follow the normal Memfault OTA workflow:
- build and flash an image with a version like
0.0.1
(see theVERSION
file for setting an application version). - rebuild with a newer version,
0.0.2
- upload the
zephyr.signed.confirmed.bin
file to a Memfault Release named0.0.2
. - deploy the
0.0.2
release to the cohort with the device (default
unless changed) - on the device shell, connect wifi with
wifi connect <ssid> <pw>
, and trigger the OTA withmflt get_latest_release
- when the device reboots, confirm the new version is set with
mflt get_device_info
Note
If this error occurs when applying the new image:
[00:10:07.255,000] <dbg> mflt: memfault_platform_log: Error requesting upgrade, rv=-14
[00:10:07.260,000] <err> mflt: Error upgrading firmware, rv=-1
It may be necessary to run mcuboot erase 2
one time before running the test,
to wipe the secondary slot so it's ready to receive the new image.