Why OTG_HS USB/USBX Host on STM32U5A9x just does not work?
While investigating for the firth evening in the row why OTH_HS USB on STM32U5A9x does not work I reviewed USB registers. There are quite few of them and in HAL some are them are named differently than in RM0456 (details here), but that is not the root problem.
According to RM0456, section 15.2.3 "Configuring the OTG_HS PHY (only for STM32U59x/5Ax/5Fx/5Gx)" the following register fields should be set:
- SYSCFG.OTGHSPHYCR.CLKSEL (IP clock speed selection)
- SYSCFG.OTGHSPHYTUNER2.COMPDISTUNE
- SYSCFG.OTGHSPHYTUNER2.SQRXTUNE
- then OTH_HS IP can be enabled by setting SYSCFG.OTGHSPHYCR.EN=1
I realized that after when MX_USB_OTG_HS_HCD_Init() was called, the above two register values had still zero values.
Within MX_USB_OTG_HS_HCD_Init() function SYSCFG.OTGHSPHYTUNER2.COMPDISTUNE and SYSCFG.OTGHSPHYTUNER2.SQRXTUNE are not set while they probably should be since the recommended values differ from default ones (RM0456, 15.3.13).
Certainly, setting SYSCFG.OTGHSPHYCR.CLKSEL to a non-zero default value is a must (RM0456, 15.3.12).
The above got me thinking. Was the RCC.APB3ENR.SYSCFGEN set in the first place? It turned out that it was not.
Probably this is another serious CubeMX bug. I seriously doubt anyone succeeded trying to configure USB on STM32U5A or STM32U59 with CubeMX yet. Was it ever tested?
In short: it seems that CubeMX generated code does not call HAL_SYSCFG_SetOTGPHYDisconnectThreshold() and HAL_SYSCFG_SetOTGPHYSquelchThreshold() while it should and does not enable APB3ENR.SYSCFGEN clock first.