From 7dac8c2bd1f08f7b7223305ddf4421edd82a681f Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Wed, 6 Aug 2025 10:42:49 +0200 Subject: [PATCH 1/6] Restore Debug menu functionality Completes https://github.com/arduino/ArduinoCore-zephyr/commit/c89521ccb9fe94075c3102dc15e40dc24d10d594 for all the boards --- boards.txt | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/boards.txt b/boards.txt index ff52cb7e..d4bcd7f8 100644 --- a/boards.txt +++ b/boards.txt @@ -10,9 +10,7 @@ giga.build.compiler_path={runtime.tools.arm-zephyr-eabi-0.16.8.path}/bin/ giga.menu.debug.false=Standard giga.menu.debug.true=Debug - -giga.menu.debug.false.postbuild_debug= -giga.menu.debug.true.postbuild_debug=-debug +giga.menu.debug.true.build.zsk_args.debug=-debug giga.build.zephyr_target=arduino_giga_r1//m7 giga.build.zephyr_args=--shield arduino_giga_display_shield @@ -74,9 +72,7 @@ nano33ble.build.compiler_path={runtime.tools.arm-zephyr-eabi-0.16.8.path}/bin/ nano33ble.menu.debug.false=Standard nano33ble.menu.debug.true=Debug - -nano33ble.menu.debug.false.postbuild_debug= -nano33ble.menu.debug.true.postbuild_debug=-debug +nano33ble.menu.debug.true.build.zsk_args.debug=-debug nano33ble.build.zephyr_target=arduino_nano_33_ble//sense nano33ble.build.zephyr_args= @@ -136,9 +132,7 @@ ek_ra8d1.build.compiler_path={runtime.tools.arm-zephyr-eabi-0.16.8.path}/bin/ ek_ra8d1.menu.debug.false=Standard ek_ra8d1.menu.debug.true=Debug - -ek_ra8d1.menu.debug.false.postbuild_debug= -ek_ra8d1.menu.debug.true.postbuild_debug=-debug +ek_ra8d1.menu.debug.true.build.zsk_args.debug=-debug ek_ra8d1.build.zephyr_target=ek_ra8d1 ek_ra8d1.build.zephyr_args= @@ -192,9 +186,7 @@ frdm_mcxn947.build.compiler_path={runtime.tools.arm-zephyr-eabi-0.16.8.path}/bin frdm_mcxn947.menu.debug.false=Standard frdm_mcxn947.menu.debug.true=Debug - -frdm_mcxn947.menu.debug.false.postbuild_debug= -frdm_mcxn947.menu.debug.true.postbuild_debug=-debug +frdm_mcxn947.menu.debug.true.build.zsk_args.debug=-debug frdm_mcxn947.build.zephyr_target=frdm_mcxn947//cpu0 frdm_mcxn947.build.zephyr_args= @@ -243,9 +235,7 @@ portentah7.build.compiler_path={runtime.tools.arm-zephyr-eabi-0.16.8.path}/bin/ portentah7.menu.debug.false=Standard portentah7.menu.debug.true=Debug - -portentah7.menu.debug.false.postbuild_debug= -portentah7.menu.debug.true.postbuild_debug=-debug +portentah7.menu.debug.true.build.zsk_args.debug=-debug portentah7.build.zephyr_target=arduino_portenta_h7@1.0.0//m7 portentah7.build.zephyr_args= @@ -307,9 +297,7 @@ frdm_rw612.build.compiler_path={runtime.tools.arm-zephyr-eabi-0.16.8.path}/bin/ frdm_rw612.menu.debug.false=Standard frdm_rw612.menu.debug.true=Debug - -frdm_rw612.menu.debug.false.postbuild_debug= -frdm_rw612.menu.debug.true.postbuild_debug=-debug +frdm_rw612.menu.debug.true.build.zsk_args.debug=-debug frdm_rw612.build.zephyr_target=frdm_rw612 frdm_rw612.build.zephyr_args= @@ -357,9 +345,7 @@ niclasense.build.compiler_path={runtime.tools.arm-zephyr-eabi-0.16.8.path}/bin/ niclasense.menu.debug.false=Standard niclasense.menu.debug.true=Debug - -niclasense.menu.debug.false.postbuild_debug= -niclasense.menu.debug.true.postbuild_debug=-debug +niclasense.menu.debug.true.build.zsk_args.debug=-debug niclasense.build.zephyr_target=arduino_nicla_sense_me niclasense.build.zephyr_args= @@ -481,9 +467,7 @@ opta.build.compiler_path={runtime.tools.arm-zephyr-eabi-0.16.8.path}/bin/ opta.menu.debug.false=Standard opta.menu.debug.true=Debug - -opta.menu.debug.false.postbuild_debug= -opta.menu.debug.true.postbuild_debug=-debug +opta.menu.debug.true.build.zsk_args.debug=-debug opta.build.zephyr_target=arduino_opta//m7 opta.build.zephyr_args= From 45128fd8c5e63276f9b9ed96359b993429abf1cb Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Thu, 3 Apr 2025 12:38:43 +0200 Subject: [PATCH 2/6] usb: refactor USBD_NEXT and implement 1200bps touch --- cores/arduino/SerialUSB.h | 15 +++++++-- cores/arduino/USB.cpp | 69 +++++++++++++-------------------------- cores/arduino/main.cpp | 2 +- 3 files changed, 37 insertions(+), 49 deletions(-) diff --git a/cores/arduino/SerialUSB.h b/cores/arduino/SerialUSB.h index be1377f8..47acf009 100644 --- a/cores/arduino/SerialUSB.h +++ b/cores/arduino/SerialUSB.h @@ -8,6 +8,11 @@ #include +#if defined(CONFIG_USB_DEVICE_STACK_NEXT) +#include +extern "C" struct usbd_context *usbd_init_device(usbd_msg_cb_t msg_cb); +#endif + namespace arduino { class SerialUSB_ : public ZephyrSerial { @@ -25,12 +30,18 @@ class SerialUSB_ : public ZephyrSerial { protected: uint32_t dtr = 0; uint32_t baudrate; - void _baudChangeHandler(); static void _baudChangeDispatch(struct k_timer *timer); + static void _baudChangeHandler(const struct device *dev, uint32_t rate); private: - struct k_timer baud_timer; bool started = false; + +#if defined(CONFIG_USB_DEVICE_STACK_NEXT) + struct usbd_context *_usbd; + int enable_usb_device_next(); + static void usbd_next_cb(struct usbd_context *const ctx, const struct usbd_msg *msg); + static int usb_disable(); +#endif }; } // namespace arduino diff --git a/cores/arduino/USB.cpp b/cores/arduino/USB.cpp index 60f5fc7a..ab697c85 100644 --- a/cores/arduino/USB.cpp +++ b/cores/arduino/USB.cpp @@ -24,62 +24,47 @@ void __attribute__((weak)) _on_1200_bps() { NVIC_SystemReset(); } -void arduino::SerialUSB_::_baudChangeHandler() -{ - uart_line_ctrl_get(uart, UART_LINE_CTRL_BAUD_RATE, &baudrate); - if (baudrate == 1200) { - usb_disable(); - _on_1200_bps(); - } -} - -static void _baudChangeHandler(const struct device *dev, uint32_t rate) +void arduino::SerialUSB_::_baudChangeHandler(const struct device *dev, uint32_t rate) { (void)dev; // unused if (rate == 1200) { + k_sleep(K_MSEC(100)); usb_disable(); + k_sleep(K_MSEC(10)); _on_1200_bps(); } } #if defined(CONFIG_USB_DEVICE_STACK_NEXT) -extern "C" { - #include - struct usbd_context *usbd_init_device(usbd_msg_cb_t msg_cb); +int arduino::SerialUSB_::usb_disable() { + return usbd_disable(Serial._usbd); } -struct usbd_context *_usbd; - -int usb_disable() { - return usbd_disable(_usbd); -} - -static void usbd_next_cb(struct usbd_context *const ctx, const struct usbd_msg *msg) +void arduino::SerialUSB_::usbd_next_cb(struct usbd_context *const ctx, const struct usbd_msg *msg) { - if (usbd_can_detect_vbus(ctx)) { - if (msg->type == USBD_MSG_VBUS_READY) { - usbd_enable(ctx); - } - - if (msg->type == USBD_MSG_VBUS_REMOVED) { - usbd_disable(ctx); - } - } + if (usbd_can_detect_vbus(ctx)) { + if (msg->type == USBD_MSG_VBUS_READY) { + usbd_enable(ctx); + } + + if (msg->type == USBD_MSG_VBUS_REMOVED) { + usbd_disable(ctx); + } + } - if (msg->type == USBD_MSG_CDC_ACM_LINE_CODING) { + if (msg->type == USBD_MSG_CDC_ACM_LINE_CODING) { uint32_t baudrate; - uart_line_ctrl_get(ctx->dev, UART_LINE_CTRL_BAUD_RATE, &baudrate); - _baudChangeHandler(nullptr, baudrate); - } + uart_line_ctrl_get(Serial.uart, UART_LINE_CTRL_BAUD_RATE, &baudrate); + Serial._baudChangeHandler(nullptr, baudrate); + } } -static int enable_usb_device_next(void) +int arduino::SerialUSB_::enable_usb_device_next(void) { int err; - //_usbd = usbd_init_device(usbd_next_cb); - _usbd = usbd_init_device(nullptr); + _usbd = usbd_init_device(arduino::SerialUSB_::usbd_next_cb); if (_usbd == NULL) { return -ENODEV; } @@ -94,22 +79,14 @@ static int enable_usb_device_next(void) } #endif /* defined(CONFIG_USB_DEVICE_STACK_NEXT) */ -void arduino::SerialUSB_::_baudChangeDispatch(struct k_timer *timer) { - arduino::SerialUSB_* dev = (arduino::SerialUSB_*)k_timer_user_data_get(timer); - dev->_baudChangeHandler(); -} - - void arduino::SerialUSB_::begin(unsigned long baudrate, uint16_t config) { if (!started) { #ifndef CONFIG_USB_DEVICE_STACK_NEXT usb_enable(NULL); #ifndef CONFIG_CDC_ACM_DTE_RATE_CALLBACK_SUPPORT - k_timer_init(&baud_timer, SerialUSB_::_baudChangeDispatch, NULL); - k_timer_user_data_set(&baud_timer, this); - k_timer_start(&baud_timer, K_MSEC(100), K_MSEC(100)); + #warning "Can't read CDC baud change, please enable CONFIG_CDC_ACM_DTE_RATE_CALLBACK_SUPPORT" #else - cdc_acm_dte_rate_callback_set(usb_dev, ::_baudChangeHandler); + cdc_acm_dte_rate_callback_set(usb_dev, SerialUSB_::_baudChangeHandler); #endif #else enable_usb_device_next(); diff --git a/cores/arduino/main.cpp b/cores/arduino/main.cpp index 9359e745..533a3077 100644 --- a/cores/arduino/main.cpp +++ b/cores/arduino/main.cpp @@ -23,7 +23,7 @@ void __attribute__((weak))initVariant(void) { int main(void) { -#if (DT_NODE_HAS_PROP(DT_PATH(zephyr_user), cdc_acm) && CONFIG_USB_CDC_ACM) +#if (DT_NODE_HAS_PROP(DT_PATH(zephyr_user), cdc_acm) && (CONFIG_USB_CDC_ACM || CONFIG_USBD_CDC_ACM_CLASS)) Serial.begin(115200); #endif From 064bc7ed25fe018c7abe54c8edb9d4e60637d961 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Thu, 3 Apr 2025 12:39:19 +0200 Subject: [PATCH 3/6] usb: optimize 1200bps wait for IDE2 --- boards.txt | 11 +++++++---- platform.txt | 3 ++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/boards.txt b/boards.txt index d4bcd7f8..14b4f605 100644 --- a/boards.txt +++ b/boards.txt @@ -38,12 +38,13 @@ giga.upload.vid=0x2341 giga.upload.pid=0x0366 giga.upload.interface=0 giga.upload.use_1200bps_touch=true -giga.upload.wait_for_upload_port=true +giga.upload.wait_for_upload_port=false giga.upload.native_usb=true giga.upload.maximum_size=1966080 giga.upload.maximum_data_size=523624 giga.upload.address=0x080E0000 +giga.upload.wait_for_device=-w giga.upload.maximum_size=786432 giga.upload.maximum_data_size=523624 @@ -263,12 +264,13 @@ portentah7.upload.vid=0x2341 portentah7.upload.pid=0x035b portentah7.upload.interface=0 portentah7.upload.use_1200bps_touch=true -portentah7.upload.wait_for_upload_port=true +portentah7.upload.wait_for_upload_port=false portentah7.upload.native_usb=true portentah7.upload.maximum_size=1966080 portentah7.upload.maximum_data_size=523624 portentah7.upload.address=0x080E0000 +portentah7.upload.wait_for_device=-w portentah7.upload.maximum_size=786432 portentah7.upload.maximum_data_size=523624 @@ -449,7 +451,7 @@ portentac33.upload.native_usb=true portentac33.upload.maximum_size=1966080 portentac33.upload.maximum_data_size=523624 portentac33.upload.address=0x100000 -portentac33.upload.dfuse=-Q +portentac33.upload.dfuse=-Q -w portentac33.bootloader.tool=dfu-util portentac33.bootloader.tool.default=dfu-util @@ -495,12 +497,13 @@ opta.upload.vid=0x2341 opta.upload.pid=0x0364 opta.upload.interface=0 opta.upload.use_1200bps_touch=true -opta.upload.wait_for_upload_port=true +opta.upload.wait_for_upload_port=false opta.upload.native_usb=true opta.upload.maximum_size=1966080 opta.upload.maximum_data_size=523624 opta.upload.address=0x080E0000 +opta.upload.wait_for_device=-w opta.upload.maximum_size=786432 opta.upload.maximum_data_size=523624 diff --git a/platform.txt b/platform.txt index fe897070..78946bbd 100644 --- a/platform.txt +++ b/platform.txt @@ -220,12 +220,13 @@ tools.stm32flash.erase.pattern="{path}/{cmd}" {serial.port} -e 1024 -b 2400 upload.dfuse=--dfuse-address={upload.address}:leave bootloader.dfuse=--dfuse-address={bootloader.address}:leave +upload.wait_for_device= tools.dfu-util.path={runtime.tools.dfu-util.path} tools.dfu-util.cmd=dfu-util tools.dfu-util.upload.params.verbose=-d tools.dfu-util.upload.params.quiet= -tools.dfu-util.upload.pattern="{path}/{cmd}" --device ,{upload.vid}:{upload.pid} -D "{build.path}/{build.project_name}.{upload.extension}" -a{upload.interface} {upload.dfuse} +tools.dfu-util.upload.pattern="{path}/{cmd}" --device ,{upload.vid}:{upload.pid} -D "{build.path}/{build.project_name}.{upload.extension}" -a{upload.interface} {upload.dfuse} {upload.wait_for_device} tools.dfu-util.bootloader.params.verbose=-d tools.dfu-util.bootloader.params.quiet= From 07090373c544063b8f297bc0e990025c92084cc1 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Mon, 5 May 2025 17:36:17 +0200 Subject: [PATCH 4/6] wip: usb_next other fixes --- loader/CMakeLists.txt | 5 +++++ loader/llext_exports.c | 2 +- loader/main.c | 22 ++++++++++++++++++- .../arduino_giga_r1_stm32h747xx_m7.conf | 11 ++++++---- .../arduino_nano_33_ble_nrf52840_sense.conf | 11 +++++----- .../variant.cpp | 4 +--- .../arduino_opta_stm32h747xx_m7.conf | 13 +++++++---- .../arduino_portenta_h7_stm32h747xx_m7.conf | 13 +++++++---- .../frdm_mcxn947_mcxn947_cpu0.conf | 11 ++++++---- .../frdm_rw612_rw612/frdm_rw612_rw612.conf | 11 +++++----- 10 files changed, 72 insertions(+), 31 deletions(-) diff --git a/loader/CMakeLists.txt b/loader/CMakeLists.txt index c62b3b3a..9cecfe1f 100644 --- a/loader/CMakeLists.txt +++ b/loader/CMakeLists.txt @@ -16,6 +16,11 @@ project(app LANGUAGES C CXX) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/blobs) +# for USB device stack NEXT +target_sources_ifdef(CONFIG_USB_DEVICE_STACK_NEXT app PRIVATE + ${CMAKE_CURRENT_LIST_DIR}/../cores/arduino/usb_device_descriptor.c +) + FILE(GLOB app_sources *.c) target_sources(app PRIVATE ${app_sources}) diff --git a/loader/llext_exports.c b/loader/llext_exports.c index b1e73347..61c8c980 100644 --- a/loader/llext_exports.c +++ b/loader/llext_exports.c @@ -243,4 +243,4 @@ FORCE_EXPORT_SYM(__aeabi_dcmpge); #if defined (CONFIG_CPP) FORCE_EXPORT_SYM(__cxa_pure_virtual); -#endif \ No newline at end of file +#endif diff --git a/loader/main.c b/loader/main.c index 643da9d7..1d4ecf32 100644 --- a/loader/main.c +++ b/loader/main.c @@ -33,11 +33,31 @@ struct sketch_header_v1 { #define SKETCH_FLAG_LINKED 0x02 #define TARGET_HAS_USB_CDC_SHELL \ - DT_NODE_HAS_PROP(DT_PATH(zephyr_user), cdc_acm) && CONFIG_SHELL && CONFIG_USB_DEVICE_STACK + DT_NODE_HAS_PROP(DT_PATH(zephyr_user), cdc_acm) && CONFIG_SHELL && (CONFIG_USB_DEVICE_STACK || CONFIG_USB_DEVICE_STACK_NEXT) #if TARGET_HAS_USB_CDC_SHELL const struct device *const usb_dev = DEVICE_DT_GET(DT_PHANDLE_BY_IDX(DT_PATH(zephyr_user), cdc_acm, 0)); +#if CONFIG_USB_DEVICE_STACK_NEXT +#include +struct usbd_context *usbd_init_device(usbd_msg_cb_t msg_cb); +int usb_enable(usb_dc_status_callback status_cb) +{ + int err; + struct usbd_context *_usbd = usbd_init_device(NULL); + if (_usbd == NULL) { + return -ENODEV; + } + if (!usbd_can_detect_vbus(_usbd)) { + err = usbd_enable(_usbd); + if (err) { + return err; + } + } + return 0; +} +#endif + static int enable_shell_usb(void) { bool log_backend = CONFIG_SHELL_BACKEND_SERIAL_LOG_LEVEL > 0; diff --git a/variants/arduino_giga_r1_stm32h747xx_m7/arduino_giga_r1_stm32h747xx_m7.conf b/variants/arduino_giga_r1_stm32h747xx_m7/arduino_giga_r1_stm32h747xx_m7.conf index 8ad58579..7b67630a 100644 --- a/variants/arduino_giga_r1_stm32h747xx_m7/arduino_giga_r1_stm32h747xx_m7.conf +++ b/variants/arduino_giga_r1_stm32h747xx_m7/arduino_giga_r1_stm32h747xx_m7.conf @@ -1,13 +1,15 @@ -CONFIG_USB_DEVICE_STACK=y +CONFIG_USB_DEVICE_STACK_NEXT=y CONFIG_USB_DEVICE_PRODUCT="Arduino GIGA R1" CONFIG_USB_DEVICE_MANUFACTURER="Arduino" CONFIG_USB_DEVICE_VID=0x2341 CONFIG_USB_DEVICE_PID=0x0066 -CONFIG_USB_CDC_ACM=y -CONFIG_USB_CDC_ACM_RINGBUF_SIZE=512 -CONFIG_UART_LINE_CTRL=y +CONFIG_USBD_CDC_ACM_CLASS=y CONFIG_CDC_ACM_DTE_RATE_CALLBACK_SUPPORT=y +CONFIG_USBD_CDC_ACM_LOG_LEVEL_ERR=y +CONFIG_UDC_DRIVER_LOG_LEVEL_ERR=y +CONFIG_USBD_LOG_LEVEL_ERR=y +CONFIG_UART_LINE_CTRL=y CONFIG_LLEXT_STORAGE_WRITABLE=n CONFIG_SHARED_MULTI_HEAP=y @@ -61,6 +63,7 @@ CONFIG_BT_CTLR_ADV_EXT=y CONFIG_BT_CTLR_ADV_PERIODIC=y CONFIG_BT_CTLR_DTM_HCI=y CONFIG_CYW4343W_MURATA_1DX=y + CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048 CONFIG_BT_RX_STACK_SIZE=4096 CONFIG_BT_HCI_TX_STACK_SIZE=4096 diff --git a/variants/arduino_nano_33_ble_nrf52840_sense/arduino_nano_33_ble_nrf52840_sense.conf b/variants/arduino_nano_33_ble_nrf52840_sense/arduino_nano_33_ble_nrf52840_sense.conf index 787e6dc9..5ff5ea15 100644 --- a/variants/arduino_nano_33_ble_nrf52840_sense/arduino_nano_33_ble_nrf52840_sense.conf +++ b/variants/arduino_nano_33_ble_nrf52840_sense/arduino_nano_33_ble_nrf52840_sense.conf @@ -16,17 +16,18 @@ CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048 # Host number of completed commands does not follow normal flow control. CONFIG_BT_BUF_CMD_TX_COUNT=10 - -CONFIG_USB_DEVICE_STACK=y +CONFIG_USB_DEVICE_STACK_NEXT=y CONFIG_USB_DEVICE_PRODUCT="Arduino Nano 33 BLE" CONFIG_USB_DEVICE_MANUFACTURER="Arduino" CONFIG_USB_DEVICE_VID=0x2341 CONFIG_USB_DEVICE_PID=0x035A -CONFIG_USB_CDC_ACM=y -CONFIG_USB_CDC_ACM_RINGBUF_SIZE=512 -CONFIG_UART_LINE_CTRL=y +CONFIG_USBD_CDC_ACM_CLASS=y CONFIG_CDC_ACM_DTE_RATE_CALLBACK_SUPPORT=y +CONFIG_USBD_CDC_ACM_LOG_LEVEL_ERR=y +CONFIG_UDC_DRIVER_LOG_LEVEL_ERR=y +CONFIG_USBD_LOG_LEVEL_ERR=y +CONFIG_UART_LINE_CTRL=y CONFIG_ADC=y CONFIG_PWM=y diff --git a/variants/arduino_nano_33_ble_nrf52840_sense/variant.cpp b/variants/arduino_nano_33_ble_nrf52840_sense/variant.cpp index de0de2f7..8f290c7c 100644 --- a/variants/arduino_nano_33_ble_nrf52840_sense/variant.cpp +++ b/variants/arduino_nano_33_ble_nrf52840_sense/variant.cpp @@ -12,11 +12,9 @@ void initVariant(void) { GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), pin_enable_gpios); if (gpio_is_ready_dt(&enable_sensors)) { gpio_flags_t flags = enable_sensors.dt_flags | GPIO_OUTPUT_HIGH | GPIO_ACTIVE_HIGH | NRF_GPIO_DRIVE_H0H1; - Serial.println((uint32_t)flags, HEX); - + gpio_pin_configure(enable_sensors.port, enable_sensors.pin, flags); gpio_pin_set(enable_sensors.port, enable_sensors.pin, HIGH); - //Serial.println("### Sensor pin enabled ###"); delay(500); } diff --git a/variants/arduino_opta_stm32h747xx_m7/arduino_opta_stm32h747xx_m7.conf b/variants/arduino_opta_stm32h747xx_m7/arduino_opta_stm32h747xx_m7.conf index 8aac2859..d3aec9e6 100644 --- a/variants/arduino_opta_stm32h747xx_m7/arduino_opta_stm32h747xx_m7.conf +++ b/variants/arduino_opta_stm32h747xx_m7/arduino_opta_stm32h747xx_m7.conf @@ -1,13 +1,18 @@ -CONFIG_USB_DEVICE_STACK=y +CONFIG_USB_DEVICE_STACK_NEXT=y CONFIG_USB_DEVICE_PRODUCT="Arduino Opta" CONFIG_USB_DEVICE_MANUFACTURER="Arduino" CONFIG_USB_DEVICE_VID=0x2341 CONFIG_USB_DEVICE_PID=0x0064 -CONFIG_USB_CDC_ACM=y -CONFIG_USB_CDC_ACM_RINGBUF_SIZE=512 -CONFIG_UART_LINE_CTRL=y +# Get rid of old USB stack +CONFIG_BOARD_SERIAL_BACKEND_CDC_ACM=n + +CONFIG_USBD_CDC_ACM_CLASS=y CONFIG_CDC_ACM_DTE_RATE_CALLBACK_SUPPORT=y +CONFIG_USBD_CDC_ACM_LOG_LEVEL_ERR=y +CONFIG_UDC_DRIVER_LOG_LEVEL_ERR=y +CONFIG_USBD_LOG_LEVEL_ERR=y +CONFIG_UART_LINE_CTRL=y CONFIG_LLEXT_STORAGE_WRITABLE=n diff --git a/variants/arduino_portenta_h7_stm32h747xx_m7/arduino_portenta_h7_stm32h747xx_m7.conf b/variants/arduino_portenta_h7_stm32h747xx_m7/arduino_portenta_h7_stm32h747xx_m7.conf index d8242394..94c12e4b 100644 --- a/variants/arduino_portenta_h7_stm32h747xx_m7/arduino_portenta_h7_stm32h747xx_m7.conf +++ b/variants/arduino_portenta_h7_stm32h747xx_m7/arduino_portenta_h7_stm32h747xx_m7.conf @@ -1,13 +1,18 @@ -CONFIG_USB_DEVICE_STACK=y +CONFIG_USB_DEVICE_STACK_NEXT=y CONFIG_USB_DEVICE_PRODUCT="Arduino Portenta H7" CONFIG_USB_DEVICE_MANUFACTURER="Arduino" CONFIG_USB_DEVICE_VID=0x2341 CONFIG_USB_DEVICE_PID=0x005b -CONFIG_USB_CDC_ACM=y -CONFIG_USB_CDC_ACM_RINGBUF_SIZE=512 -CONFIG_UART_LINE_CTRL=y +# Get rid of old USB stack +CONFIG_BOARD_SERIAL_BACKEND_CDC_ACM=n + +CONFIG_USBD_CDC_ACM_CLASS=y CONFIG_CDC_ACM_DTE_RATE_CALLBACK_SUPPORT=y +CONFIG_USBD_CDC_ACM_LOG_LEVEL_ERR=y +CONFIG_UDC_DRIVER_LOG_LEVEL_ERR=y +CONFIG_USBD_LOG_LEVEL_ERR=y +CONFIG_UART_LINE_CTRL=y CONFIG_LLEXT_STORAGE_WRITABLE=n diff --git a/variants/frdm_mcxn947_mcxn947_cpu0/frdm_mcxn947_mcxn947_cpu0.conf b/variants/frdm_mcxn947_mcxn947_cpu0/frdm_mcxn947_mcxn947_cpu0.conf index cd131438..98d11e08 100644 --- a/variants/frdm_mcxn947_mcxn947_cpu0/frdm_mcxn947_mcxn947_cpu0.conf +++ b/variants/frdm_mcxn947_mcxn947_cpu0/frdm_mcxn947_mcxn947_cpu0.conf @@ -5,17 +5,20 @@ CONFIG_BUILD_NO_GAP_FILL=y CONFIG_FLASH=y #CONFIG_USB_DC_NXP_EHCI=y -CONFIG_USB_DEVICE_STACK=y +CONFIG_USB_DEVICE_STACK_NEXT=y CONFIG_USB_DEVICE_PRODUCT="Freedom MCXN947" CONFIG_USB_DEVICE_MANUFACTURER="NXP" CONFIG_USB_DEVICE_VID=0x2341 CONFIG_USB_DEVICE_PID=0x0078 CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=n -CONFIG_USB_CDC_ACM=y -CONFIG_USB_CDC_ACM_RINGBUF_SIZE=512 -CONFIG_UART_LINE_CTRL=y +CONFIG_USBD_CDC_ACM_CLASS=y CONFIG_CDC_ACM_DTE_RATE_CALLBACK_SUPPORT=y +CONFIG_USBD_CDC_ACM_LOG_LEVEL_ERR=y +CONFIG_UDC_DRIVER_LOG_LEVEL_ERR=y +CONFIG_USBD_LOG_LEVEL_ERR=y +CONFIG_UART_LINE_CTRL=y + CONFIG_USB_MCUX_THREAD_STACK_SIZE=4096 CONFIG_LLEXT_STORAGE_WRITABLE=n diff --git a/variants/frdm_rw612_rw612/frdm_rw612_rw612.conf b/variants/frdm_rw612_rw612/frdm_rw612_rw612.conf index 7a8f3cc5..14103227 100644 --- a/variants/frdm_rw612_rw612/frdm_rw612_rw612.conf +++ b/variants/frdm_rw612_rw612/frdm_rw612_rw612.conf @@ -4,18 +4,19 @@ CONFIG_BUILD_OUTPUT_HEX=y CONFIG_FLASH=y #CONFIG_USB_DC_NXP_EHCI=y -CONFIG_USB_DEVICE_STACK=y +CONFIG_USB_DEVICE_STACK_NEXT=y CONFIG_USB_DEVICE_PRODUCT="Freedom RW612" CONFIG_USB_DEVICE_MANUFACTURER="NXP" CONFIG_USB_DEVICE_VID=0x2341 CONFIG_USB_DEVICE_PID=0x0079 CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=n -CONFIG_USB_CDC_ACM=y -CONFIG_USB_CDC_ACM_RINGBUF_SIZE=512 -CONFIG_UART_LINE_CTRL=y +CONFIG_USBD_CDC_ACM_CLASS=y CONFIG_CDC_ACM_DTE_RATE_CALLBACK_SUPPORT=y -CONFIG_USB_MCUX_THREAD_STACK_SIZE=4096 +CONFIG_USBD_CDC_ACM_LOG_LEVEL_ERR=y +CONFIG_UDC_DRIVER_LOG_LEVEL_ERR=y +CONFIG_USBD_LOG_LEVEL_ERR=y +CONFIG_UART_LINE_CTRL=y CONFIG_LLEXT_STORAGE_WRITABLE=y CONFIG_STACK_USAGE=n From 94974e68b746edb4138db424d64d6f1ad9c5c445 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Tue, 5 Aug 2025 15:22:50 +0200 Subject: [PATCH 5/6] stm32h7: restore 1200bps functionality by enabling Backup area access --- cores/arduino/USB.cpp | 1 + loader/fixups.c | 10 ++++++++++ .../arduino_giga_r1_stm32h747xx_m7.conf | 2 ++ .../arduino_giga_r1_stm32h747xx_m7.overlay | 5 +++++ 4 files changed, 18 insertions(+) diff --git a/cores/arduino/USB.cpp b/cores/arduino/USB.cpp index ab697c85..0735043a 100644 --- a/cores/arduino/USB.cpp +++ b/cores/arduino/USB.cpp @@ -56,6 +56,7 @@ void arduino::SerialUSB_::usbd_next_cb(struct usbd_context *const ctx, const str if (msg->type == USBD_MSG_CDC_ACM_LINE_CODING) { uint32_t baudrate; uart_line_ctrl_get(Serial.uart, UART_LINE_CTRL_BAUD_RATE, &baudrate); + printf("Baud rate changed to %d\n", baudrate); Serial._baudChangeHandler(nullptr, baudrate); } } diff --git a/loader/fixups.c b/loader/fixups.c index cf5e60cd..c6b90e61 100644 --- a/loader/fixups.c +++ b/loader/fixups.c @@ -39,6 +39,16 @@ SYS_INIT(disable_bootloader_mpu, PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEFAU SYS_INIT(disable_mpu_rasr_xn, PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT); #endif +#if defined(CONFIG_SOC_STM32H747XX_M7) +void enable_bkp_access(void) +{ + /* Enable access to the backup domain */ + // HAL_PWR_EnableBkUpAccess(); + SET_BIT(PWR->CR1, PWR_CR1_DBP); +} +SYS_INIT(enable_bkp_access, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT); +#endif + #if defined(CONFIG_BOARD_ARDUINO_GIGA_R1) && defined(CONFIG_VIDEO) #include #include diff --git a/variants/arduino_giga_r1_stm32h747xx_m7/arduino_giga_r1_stm32h747xx_m7.conf b/variants/arduino_giga_r1_stm32h747xx_m7/arduino_giga_r1_stm32h747xx_m7.conf index 7b67630a..d1ed70c5 100644 --- a/variants/arduino_giga_r1_stm32h747xx_m7/arduino_giga_r1_stm32h747xx_m7.conf +++ b/variants/arduino_giga_r1_stm32h747xx_m7/arduino_giga_r1_stm32h747xx_m7.conf @@ -67,3 +67,5 @@ CONFIG_CYW4343W_MURATA_1DX=y CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048 CONFIG_BT_RX_STACK_SIZE=4096 CONFIG_BT_HCI_TX_STACK_SIZE=4096 + +CONFIG_RTC=y diff --git a/variants/arduino_giga_r1_stm32h747xx_m7/arduino_giga_r1_stm32h747xx_m7.overlay b/variants/arduino_giga_r1_stm32h747xx_m7/arduino_giga_r1_stm32h747xx_m7.overlay index 1bce0bdf..96d151df 100644 --- a/variants/arduino_giga_r1_stm32h747xx_m7/arduino_giga_r1_stm32h747xx_m7.overlay +++ b/variants/arduino_giga_r1_stm32h747xx_m7/arduino_giga_r1_stm32h747xx_m7.overlay @@ -333,6 +333,11 @@ }; }; +&rtc { + clocks = <&rcc STM32_CLOCK_BUS_APB4 0x00010000>, + <&rcc STM32_SRC_LSE RTC_SEL(1)>; + status = "okay"; +}; &flash0 { partitions { From f7adde8bb298a662da2663e19602d0e03771f4c7 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Wed, 6 Aug 2025 10:45:45 +0200 Subject: [PATCH 6/6] Temportarily restore USB_DEVICE_STACK for selected targets --- .../arduino_nano_33_ble_nrf52840_sense.conf | 10 ++++------ .../arduino_opta_stm32h747xx_m7.conf | 13 ++++--------- .../arduino_portenta_h7_stm32h747xx_m7.conf | 13 ++++--------- 3 files changed, 12 insertions(+), 24 deletions(-) diff --git a/variants/arduino_nano_33_ble_nrf52840_sense/arduino_nano_33_ble_nrf52840_sense.conf b/variants/arduino_nano_33_ble_nrf52840_sense/arduino_nano_33_ble_nrf52840_sense.conf index 5ff5ea15..c1885ec8 100644 --- a/variants/arduino_nano_33_ble_nrf52840_sense/arduino_nano_33_ble_nrf52840_sense.conf +++ b/variants/arduino_nano_33_ble_nrf52840_sense/arduino_nano_33_ble_nrf52840_sense.conf @@ -16,18 +16,16 @@ CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048 # Host number of completed commands does not follow normal flow control. CONFIG_BT_BUF_CMD_TX_COUNT=10 -CONFIG_USB_DEVICE_STACK_NEXT=y +CONFIG_USB_DEVICE_STACK=y CONFIG_USB_DEVICE_PRODUCT="Arduino Nano 33 BLE" CONFIG_USB_DEVICE_MANUFACTURER="Arduino" CONFIG_USB_DEVICE_VID=0x2341 CONFIG_USB_DEVICE_PID=0x035A -CONFIG_USBD_CDC_ACM_CLASS=y -CONFIG_CDC_ACM_DTE_RATE_CALLBACK_SUPPORT=y -CONFIG_USBD_CDC_ACM_LOG_LEVEL_ERR=y -CONFIG_UDC_DRIVER_LOG_LEVEL_ERR=y -CONFIG_USBD_LOG_LEVEL_ERR=y +CONFIG_USB_CDC_ACM=y +CONFIG_USB_CDC_ACM_RINGBUF_SIZE=512 CONFIG_UART_LINE_CTRL=y +CONFIG_CDC_ACM_DTE_RATE_CALLBACK_SUPPORT=y CONFIG_ADC=y CONFIG_PWM=y diff --git a/variants/arduino_opta_stm32h747xx_m7/arduino_opta_stm32h747xx_m7.conf b/variants/arduino_opta_stm32h747xx_m7/arduino_opta_stm32h747xx_m7.conf index d3aec9e6..8aac2859 100644 --- a/variants/arduino_opta_stm32h747xx_m7/arduino_opta_stm32h747xx_m7.conf +++ b/variants/arduino_opta_stm32h747xx_m7/arduino_opta_stm32h747xx_m7.conf @@ -1,18 +1,13 @@ -CONFIG_USB_DEVICE_STACK_NEXT=y +CONFIG_USB_DEVICE_STACK=y CONFIG_USB_DEVICE_PRODUCT="Arduino Opta" CONFIG_USB_DEVICE_MANUFACTURER="Arduino" CONFIG_USB_DEVICE_VID=0x2341 CONFIG_USB_DEVICE_PID=0x0064 -# Get rid of old USB stack -CONFIG_BOARD_SERIAL_BACKEND_CDC_ACM=n - -CONFIG_USBD_CDC_ACM_CLASS=y -CONFIG_CDC_ACM_DTE_RATE_CALLBACK_SUPPORT=y -CONFIG_USBD_CDC_ACM_LOG_LEVEL_ERR=y -CONFIG_UDC_DRIVER_LOG_LEVEL_ERR=y -CONFIG_USBD_LOG_LEVEL_ERR=y +CONFIG_USB_CDC_ACM=y +CONFIG_USB_CDC_ACM_RINGBUF_SIZE=512 CONFIG_UART_LINE_CTRL=y +CONFIG_CDC_ACM_DTE_RATE_CALLBACK_SUPPORT=y CONFIG_LLEXT_STORAGE_WRITABLE=n diff --git a/variants/arduino_portenta_h7_stm32h747xx_m7/arduino_portenta_h7_stm32h747xx_m7.conf b/variants/arduino_portenta_h7_stm32h747xx_m7/arduino_portenta_h7_stm32h747xx_m7.conf index 94c12e4b..d8242394 100644 --- a/variants/arduino_portenta_h7_stm32h747xx_m7/arduino_portenta_h7_stm32h747xx_m7.conf +++ b/variants/arduino_portenta_h7_stm32h747xx_m7/arduino_portenta_h7_stm32h747xx_m7.conf @@ -1,18 +1,13 @@ -CONFIG_USB_DEVICE_STACK_NEXT=y +CONFIG_USB_DEVICE_STACK=y CONFIG_USB_DEVICE_PRODUCT="Arduino Portenta H7" CONFIG_USB_DEVICE_MANUFACTURER="Arduino" CONFIG_USB_DEVICE_VID=0x2341 CONFIG_USB_DEVICE_PID=0x005b -# Get rid of old USB stack -CONFIG_BOARD_SERIAL_BACKEND_CDC_ACM=n - -CONFIG_USBD_CDC_ACM_CLASS=y -CONFIG_CDC_ACM_DTE_RATE_CALLBACK_SUPPORT=y -CONFIG_USBD_CDC_ACM_LOG_LEVEL_ERR=y -CONFIG_UDC_DRIVER_LOG_LEVEL_ERR=y -CONFIG_USBD_LOG_LEVEL_ERR=y +CONFIG_USB_CDC_ACM=y +CONFIG_USB_CDC_ACM_RINGBUF_SIZE=512 CONFIG_UART_LINE_CTRL=y +CONFIG_CDC_ACM_DTE_RATE_CALLBACK_SUPPORT=y CONFIG_LLEXT_STORAGE_WRITABLE=n