From 195fa3d2e2dd2f107af019ddced8c7e2abe178a8 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Fri, 17 Apr 2026 17:17:55 +0200 Subject: [PATCH 1/2] usb: pass zephyr version in USB descriptor as iConfig This is step 1. for automatic flash of the loader if the version onboard is different from the one shipped with the core --- loader/CMakeLists.txt | 6 +++++- loader/prj.conf | 2 ++ west.yml | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/loader/CMakeLists.txt b/loader/CMakeLists.txt index 428885a70..c3325e7c6 100644 --- a/loader/CMakeLists.txt +++ b/loader/CMakeLists.txt @@ -37,6 +37,10 @@ target_sources_ifdef(CONFIG_USB_DEVICE_STACK_NEXT app PRIVATE FILE(GLOB app_sources *.c) target_sources(app PRIVATE ${app_sources}) -target_compile_definitions(app PUBLIC _XOPEN_SOURCE=700) + +zephyr_compile_definitions( + -D_XOPEN_SOURCE=700 + -DCONFIG_USB_CONFIGURATION_STRING_DESC=STRINGIFY\(BUILD_VERSION\) +) target_link_libraries(app PUBLIC blobs) diff --git a/loader/prj.conf b/loader/prj.conf index 20d861491..840a80f27 100644 --- a/loader/prj.conf +++ b/loader/prj.conf @@ -49,3 +49,5 @@ CONFIG_RTC=y CONFIG_RTC_ALARM=y CONFIG_RTC_UPDATE=y CONFIG_RTC_CALIBRATION=y + +CONFIG_USB_CONFIGURATION_STRING_DESC_ENABLE=y diff --git a/west.yml b/west.yml index e8b1b3103..f0d113174 100644 --- a/west.yml +++ b/west.yml @@ -21,7 +21,7 @@ manifest: projects: - name: zephyr remote: arduino - revision: zephyr-arduino-v4.2.0 + revision: zephyr-arduino-v4.2.0+iConfig import: name-allowlist: - cmsis From a47ee06bdd50dc1424b6c3179a3a0153f963cbfe Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Mon, 20 Apr 2026 16:08:29 +0200 Subject: [PATCH 2/2] wip: giga: use iConfiguration to automatically reflash the loader if needed Requires https://github.com/arduino/arduino-cli/pull/3171 and https://github.com/arduino/serial-discovery/pull/116 (and, transitively, https://github.com/bugst/go-serial/pull/215) TODO: * replace the shell script with a proper version check utility * check if other uploaders need different methods --- boards.txt | 1 + platform.txt | 4 ++++ .../check_loader_version.sh | 9 +++++++++ 3 files changed, 14 insertions(+) create mode 100755 variants/arduino_giga_r1_stm32h747xx_m7/check_loader_version.sh diff --git a/boards.txt b/boards.txt index 8a0b9dbf2..55bbb1c96 100644 --- a/boards.txt +++ b/boards.txt @@ -46,6 +46,7 @@ giga.upload.vid=0x2341 giga.upload.pid=0x0366 giga.upload.interface=0 giga.upload.use_1200bps_touch=true +giga.upload.use_pre_upload_check=true giga.upload.wait_for_upload_port=true giga.upload.native_usb=true giga.upload.maximum_size=1966080 diff --git a/platform.txt b/platform.txt index ee295bd0a..2fa9aa8c9 100644 --- a/platform.txt +++ b/platform.txt @@ -225,6 +225,10 @@ tools.stm32flash.erase.pattern="{path}/{cmd}" {serial.port} -e 1024 -b 2400 # DFU_UTIL # +tools.dfu-util.pre_cmd.linux={build.variant.path}/check_loader_version.sh +tools.dfu-util.pre_upload_check.pattern="{pre_cmd}" {upload.port.properties.configuration} +tools.dfu-util.pre_upload.pattern="{path}/{cmd}" --device ,{bootloader.vid}:{bootloader.pid} -D "{runtime.platform.path}/firmwares/{bootloader.file}" -a{bootloader.interface} --dfuse-address={bootloader.address} + upload.dfuse=--dfuse-address={upload.address}:leave bootloader.dfuse=--dfuse-address={bootloader.address}:leave diff --git a/variants/arduino_giga_r1_stm32h747xx_m7/check_loader_version.sh b/variants/arduino_giga_r1_stm32h747xx_m7/check_loader_version.sh new file mode 100755 index 000000000..af50bc1aa --- /dev/null +++ b/variants/arduino_giga_r1_stm32h747xx_m7/check_loader_version.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +DIR=$(dirname "$(readlink -f "$0")") +VERSION=$(grep "define BUILD_VERSION" ${DIR}/llext-edk/include/zephyr/include/generated/zephyr/version.h | cut -f3 -d " ") +if [ "$VERSION" != "$1" ]; then + echo "Loader version mismatch: expected $1, got $VERSION, reflashing loader" + exit 1 +fi +exit 0 \ No newline at end of file