STM32N6: USB `phy_init` hangs the bus by writing `USBPHYC_CR` while `OTG1PHYCTL` is held in reset
embassy rev: 528ac3826668e2df6c428c59179b127e05dd7ef5 Hardware: NUCLEO-N657X0-Q (MB1940), development boot, code in AXISRAM2, probe-rs 0.31 + ST-LINK
Symptom
On the first Bus::poll of USB1_OTG_HS (Bus::init -> common_init -> phy_init), the core stalls. The debug AP answers SwdApWait and then SwdApFault, and the core cannot be halted until a hardware reset (--connect-under-reset). Nothing after common_init runs.
Cause
phy_init (embassy-stm32/src/usb/otg.rs) asserts syscfgotghsphy1rst (RCC_AHB5RSTR bit 23, OTG1PHYCTLRST in CMSIS) together with otgphy1rst, then calls OTG1PHYCTL.cr().modify(...). The PHY controller's registers do not respond while bit 23 is asserted.
Reproduced from the debugger in the same state: reading USBPHYC_CR (0x4803FC00) fails with "Cannot access memory". After releasing bit 23 it reads 0x00010015.
ST's order (STM32CubeN6, Projects/NUCLEO-N657X0-Q/Applications/USBX/Ux_Device_CDC_ACM/.../usb_otg.c, HAL_PCD_MspInit + RESET_USB_MACRO):
- Enable the OTG1 and OTGPHY1 clocks.
- Force reset of OTG1PHYCTL (bit 23), OTG1 and OTGPHY1.
- ❗️Release OTG1PHYCTL, wait ~1 ms.
- Write
USBPHYC_CR(FSEL, CMN, …). - Release OTGPHY1, wait ~1 ms.
- Release OTG1.
Possible fix
In phy_init, release syscfgotghsphy1 before touching OTG1PHYCTL.cr(), keeping otgphy1 in reset only around the write. The same applies to USB2 / OTG2PHYCTL.
With the reordered sequence (our own wrapper around embassy-usb-synopsys-otg), the core leaves reset: GSNPSID = 0x4F54411A, CID = 0x5000, and configure_as_device / config_v5 complete. Enumeration is not verified yet (separate USB-C attach issue on our board).
Note. USBPHYC_CR resets to FSEL = 20 MHz. A debugger write of FSEL = 24 MHz in the window above did not stick. I worked around it by feeding the PHY a 20 MHz reference, so the CPU-side FSEL write is unverified.
Source: embassy-rs/embassy