From 8255b2a672be805d42f405f62b105a3fe44802d6 Mon Sep 17 00:00:00 2001 From: Eduard Iten Date: Mon, 7 Jul 2025 13:49:03 +0200 Subject: [PATCH] Add firmware_node app - Step 1: Shell with reset command - Create new Zephyr app for firmware management - Target: weact_stm32g431_core board - Features: Shell interface with custom reset command - Tested on Zephyr 4.1.99 - Flash usage: 55,400 bytes (42.27% of 128KB) - RAM usage: 12,864 bytes (39.26% of 32KB) - Black Magic Probe flash runner support --- software/apps/firmware_node/CMakeLists.txt | 8 +++++ software/apps/firmware_node/README.md | 34 +++++++++++++++++++ .../boards/weact_stm32g431_core.conf | 2 ++ software/apps/firmware_node/prj.conf | 10 ++++++ software/apps/firmware_node/src/main.c | 28 +++++++++++++++ software/apps/firmware_node/sysbuild.cmake | 12 +++++++ 6 files changed, 94 insertions(+) create mode 100644 software/apps/firmware_node/CMakeLists.txt create mode 100644 software/apps/firmware_node/README.md create mode 100644 software/apps/firmware_node/boards/weact_stm32g431_core.conf create mode 100644 software/apps/firmware_node/prj.conf create mode 100644 software/apps/firmware_node/src/main.c create mode 100644 software/apps/firmware_node/sysbuild.cmake diff --git a/software/apps/firmware_node/CMakeLists.txt b/software/apps/firmware_node/CMakeLists.txt new file mode 100644 index 0000000..bf7491b --- /dev/null +++ b/software/apps/firmware_node/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.20) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) + +project(firmware_node LANGUAGES C) +zephyr_include_directories(../../include) +add_subdirectory(../../lib lib) +target_sources(app PRIVATE src/main.c) diff --git a/software/apps/firmware_node/README.md b/software/apps/firmware_node/README.md new file mode 100644 index 0000000..acc6bb2 --- /dev/null +++ b/software/apps/firmware_node/README.md @@ -0,0 +1,34 @@ +# Firmware Node Application + +This Zephyr application provides firmware management capabilities for the irrigation system. + +**Tested on Zephyr 4.1.99** + +## Features + +### Step 1: Shell with Reset Command +- Shell interface with custom "reset" command +- Warm reboot functionality + +### Planned Features +- MCUboot support with partition manager +- Firmware version display +- MCUmgr support for OTA updates + +## Building + +```bash +west build -p auto -b weact_stm32g431_core apps/firmware_node -- -DBOARD_FLASH_RUNNER=blackmagicprobe +``` + +## Flashing + +```bash +west flash +``` + +## Usage + +Connect to the device via serial console and use the shell: +- `reset` - Reboot the system +- `help` - Show available commands diff --git a/software/apps/firmware_node/boards/weact_stm32g431_core.conf b/software/apps/firmware_node/boards/weact_stm32g431_core.conf new file mode 100644 index 0000000..790634b --- /dev/null +++ b/software/apps/firmware_node/boards/weact_stm32g431_core.conf @@ -0,0 +1,2 @@ +# Board specific configuration for weact_stm32g431_core +# This file can be used for board-specific overrides if needed diff --git a/software/apps/firmware_node/prj.conf b/software/apps/firmware_node/prj.conf new file mode 100644 index 0000000..7609528 --- /dev/null +++ b/software/apps/firmware_node/prj.conf @@ -0,0 +1,10 @@ +# Enable Console and printk for logging +CONFIG_CONSOLE=y +CONFIG_LOG=y + +# Enable Shell +CONFIG_SHELL=y +CONFIG_REBOOT=y + +# Enable the reset command +CONFIG_KERNEL_SHELL=y diff --git a/software/apps/firmware_node/src/main.c b/software/apps/firmware_node/src/main.c new file mode 100644 index 0000000..9750811 --- /dev/null +++ b/software/apps/firmware_node/src/main.c @@ -0,0 +1,28 @@ +#include +#include +#include +#include + +LOG_MODULE_REGISTER(firmware_node, LOG_LEVEL_DBG); + +static int cmd_reset(const struct shell *shell, size_t argc, char **argv) +{ + ARG_UNUSED(argc); + ARG_UNUSED(argv); + + shell_print(shell, "Rebooting system..."); + k_msleep(100); // Give time for message to be sent + sys_reboot(SYS_REBOOT_WARM); + + return 0; +} + +SHELL_CMD_REGISTER(reset, NULL, "Reset the system", cmd_reset); + +int main(void) +{ + LOG_INF("Firmware Node starting up"); + LOG_INF("Shell with reset command available"); + + return 0; +} diff --git a/software/apps/firmware_node/sysbuild.cmake b/software/apps/firmware_node/sysbuild.cmake new file mode 100644 index 0000000..53e3311 --- /dev/null +++ b/software/apps/firmware_node/sysbuild.cmake @@ -0,0 +1,12 @@ +# Enable MCUboot +set(SB_CONFIG_BOOTLOADER_MCUBOOT y) + +# MCUboot configuration +set(SB_CONFIG_MCUBOOT_BOOTLOADER_MODE_OVERWRITE_ONLY y) +set(SB_CONFIG_MCUBOOT_SIGNATURE_KEY_FILE "bootloader/mcuboot/root-rsa-2048.pem") +set(SB_CONFIG_MCUBOOT_GENERATE_UNSIGNED_IMAGE y) +set(SB_CONFIG_MCUBOOT_GENERATE_CONFIRMED_IMAGE y) + +# Enable USB CDC ACM for MCUboot console +set(SB_CONFIG_MCUBOOT_USB_SUPPORT y) +set(SB_CONFIG_MCUBOOT_SERIAL y)