Skip to content

Commit 08f141c

Browse files
committed
Address review feedback (tick handling, reset handler, config & docs)
Addresses PR review comments: - Fix WB55 Nucleo-64 wording in boards_txt_additions.txt - Add build.enable_usb override to prevent duplicate STM32 core USB stack - Correct README path to boards_txt_additions.txt - Fix CFG_TUSB_RHPORT0_MODE to include speed bits - Update TINYUSB_NEED_POLLING_TASK comment to reflect actual scheduling mechanism - Rework HAL_IncTick() override to avoid hard-coded +1 tick increment - Replace naked Reset_Handler C implementation with safe assembly wrapper + C handler No functional changes beyond the requested fixes and clarifications.
1 parent 07a4c12 commit 08f141c

4 files changed

Lines changed: 21 additions & 17 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Note: For ESP32 port, version before v3.0 requires all descriptors must be speci
5050
The following are cores without built-in support
5151

5252
- **[stm32duino/Arduino_Core_STM32](https://github.com/stm32duino/Arduino_Core_STM32)**
53-
- Still WIP. Fully functional but with limited number of MCUs supported so far (F1xx, F4xx, some G4xx & WB55). Requires lines added to stm32duino boards.txt which can be found in /ports/stm32/boards_txt_additions.txt.
53+
- Still WIP. Fully functional but with limited number of MCUs supported so far (F1xx, F4xx, some G4xx & WB55). Requires lines added to stm32duino boards.txt which can be found in src/arduino/ports/stm32/boards_txt_additions.tx
5454

5555
- **mbed_rp2040**
5656
- It is still possible to use TinyUSB but with some limits such as:

src/arduino/ports/stm32/Adafruit_TinyUSB_stm32.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -147,16 +147,12 @@ void serialEventRun(void)
147147
yield();
148148
}
149149

150-
// HAL_IncTick() is called every 1 ms from the SysTick_Handler ISR.
151-
// The STM32 HAL defines it as __weak, so we override it here.
152-
// We call the HAL's own uwTick increment, then set the flag for yield().
153-
extern "C" void HAL_IncTick(void)
150+
// Hook into the HAL SysTick callback instead of overriding HAL_IncTick().
151+
// This preserves the HAL's own tick behaviour (including configurable
152+
// tick frequency) while still giving us a reliable 1 ms-ish pump for
153+
// tud_task().
154+
extern "C" void HAL_SYSTICK_Callback(void)
154155
{
155-
// Keep the HAL tick counter running (normally done by the weak default).
156-
extern __IO uint32_t uwTick;
157-
uwTick += 1U;
158-
159-
// Signal yield() to run tud_task() at the next thread-context opportunity.
160156
_tusb_task_pending = true;
161157
}
162158

src/arduino/ports/stm32/dfu_boot_stm32wb.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,21 @@ static void dfu_boot_check(void)
3838
}
3939
}
4040

41+
// Minimal naked wrapper that sets SP and branches to the C reset handler.
4142
__attribute__((naked, used))
4243
void Reset_Handler(void)
4344
{
4445
__asm volatile (
45-
"ldr r0, =_estack \n"
46-
"mov sp, r0 \n"
46+
"ldr r0, =_estack \n"
47+
"mov sp, r0 \n"
48+
"b Reset_Handler_C \n"
4749
);
50+
}
51+
52+
// Standard C reset handler: performs DFU check, system init, and
53+
// data/BSS initialisation before entering main().
54+
static void Reset_Handler_C(void)
55+
{
4856
dfu_boot_check();
4957
SystemInit();
5058
{

src/arduino/ports/stm32/tusb_config_stm32.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#define TUSB_CONFIG_STM32_H_
2727

2828
// USB Port
29-
#define CFG_TUSB_RHPORT0_MODE OPT_MODE_DEVICE
29+
#define CFG_TUSB_RHPORT0_MODE (OPT_MODE_DEVICE | OPT_MODE_FULL_SPEED)
3030
#define CFG_TUSB_RHPORT0_SPEED OPT_FULL_SPEED
3131
#define CFG_TUSB_RHPORT1_MODE OPT_MODE_NONE
3232

@@ -80,10 +80,10 @@
8080

8181
// TINYUSB_NEED_POLLING_TASK is intentionally NOT defined here.
8282
//
83-
// The STM32 port implements yield() to call tud_task() automatically
84-
// whenever the Arduino core calls yield() (e.g. inside delay(), and at
85-
// the bottom of every loop() iteration on cores that wrap loop() with
86-
// a yield() call). This means TinyUSB is serviced without any explicit
83+
// The STM32 port implements the STM32 port implementation
84+
// relies on a HAL tick hook plus serialEventRun() to ensure
85+
// tud_task() runs even when the core doesn’t call yield() from loop().
86+
// This means TinyUSB is serviced without any explicit
8787
// TinyUSBDevice.task() call in the sketch's loop().
8888
//
8989
// Sketches that still contain the legacy polling guard:

0 commit comments

Comments
 (0)