Skip to content

stm32/tinyusb_port: Add missing USB_HS_PHYC_PLL1_PLLSEL constants.#19201

Open
dpgeorge wants to merge 1 commit into
micropython:masterfrom
dpgeorge:stm32-add-missing-usb-phyc-constants
Open

stm32/tinyusb_port: Add missing USB_HS_PHYC_PLL1_PLLSEL constants.#19201
dpgeorge wants to merge 1 commit into
micropython:masterfrom
dpgeorge:stm32-add-missing-usb-phyc-constants

Conversation

@dpgeorge
Copy link
Copy Markdown
Member

@dpgeorge dpgeorge commented May 8, 2026

Summary

Add missing constants needed by TinyUSB's synopsys/dwc2 driver. They are not available in the current version of stm32lib used in this repository.

Follow up to #18933, which accidentally broke the build of PYBD_SF3.

Testing

Built PYBD_SF3 board. Prior to this PR it would not build. Now it builds.

Note that TinyUSB isn't used by this board, but the TinyUSB files are nevertheless compiled for it.

Trade-offs and Alternatives

Could update stm32lib to have a newer STM32F7xx CMSIS, but that's a lot more work.

Generative AI

I did not use generative AI tools when creating this PR.

These are needed by TinyUSB's synopsys/dwc2 driver, and are not available
in the current version of stm32lib used in this repository.

Signed-off-by: Damien George <damien@micropython.org>
@dpgeorge dpgeorge marked this pull request as ready for review May 8, 2026 02:22
@dpgeorge
Copy link
Copy Markdown
Member Author

dpgeorge commented May 8, 2026

@andrewleech FYI

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 8, 2026

Code size report:

Reference:  esp8266: Remove obsolete --verify option from ESP8266. [e496000]
Comparison: stm32/tinyusb_port: Add missing USB_HS_PHYC_PLL1_PLLSEL constants. [merge of 690dcbf]
  mpy-cross:    +0 +0.000% 
   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
      esp32:    +0 +0.000% ESP32_GENERIC
     mimxrt:    +0 +0.000% TEENSY40
        rp2:    +0 +0.000% RPI_PICO_W
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:    +0 +0.000% VIRT_RV32

@andrewleech
Copy link
Copy Markdown
Contributor

Oh whoops - is this different to the PYBD_SF6 ? I did test on that on earlier version of my PR.

@dpgeorge
Copy link
Copy Markdown
Member Author

dpgeorge commented May 8, 2026

The SF3 has built-in USB HS PHY, whereas the SF2/SF6 require an external HS PHY (and so use USB HS in FS mode).

@andrewleech
Copy link
Copy Markdown
Contributor

andrewleech commented May 8, 2026

Ah right, that makes sense. To check for similar issues I did a build of all 79 stm32 boards without TinyUSB and again clean with CFLAGS_EXTRA=-DMICROPY_HW_TINYUSB_STACK=1. All 79 pass without TinyUSB. With it forced on, 70/79 pass - the 9 failures all look pre-existing:

Board Cause
ESPRUINO_PICO Flash overflow
NUCLEO_L073RZ Flash overflow
NUCLEO_L432KC Flash overflow
B_L072Z_LRWAN1 Flash overflow
NUCLEO_F091RC MCU has no TinyUSB driver
NUCLEO_U5A5ZJ_Q MCU has no TinyUSB driver
NUCLEO_WL55 MCU has no TinyUSB driver
WEACTSTUDIO_MINI_STM32U585 MCU has no TinyUSB driver
PYBD_SF3 Missing tusb_time_millis_api

PYBD_SF3 passes the no-TinyUSB build so the fix works. The tusb_time_millis_api failure is because SF3 is the only board with USB_HS_PHYC that gets far enough to link - the PHYC init in dwc2_stm32.h calls tusb_time_delay_ms_api which pulls in the unresolved extern. Fix would be adding to shared/tinyusb/mp_usbd.c:

+uint32_t tusb_time_millis_api(void) {
+    return mp_hal_ticks_ms();
+}
+
 #endif // MICROPY_HW_ENABLE_USBDEV

@dpgeorge
Copy link
Copy Markdown
Member Author

dpgeorge commented May 8, 2026

Thanks for testing the build.

It looks like tusb_time_delay_ms_api() is the function needed by TinyUSB. Implementing only tusb_time_millis_api() would lead to the default implementation of tusb_time_delay_ms_api() which is a busy loop. And I'd rather not waste power for 2ms if it can be avoided. So I think it's better to implement tusb_time_delay_ms_api() directly, eg on stm32 using HAL_Delay(ms).

@andrewleech
Copy link
Copy Markdown
Contributor

Raised #19213 for the tusb_time_delay_ms_api fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants