STMicroelectronics / x-cube-azrtos-l4

X-CUBE-AZRTOS-L4 (Azure RTOS Software Expansion for STM32Cube) provides a full integration of Microsoft Azure RTOS in the STM32Cube environment for the STM32L4 series of microcontrollers.
https://www.st.com/en/embedded-software/x-cube-azrtos-l4.html
Other
8 stars 5 forks source link

USB PMA Buffers are not initialised correctly, causing USB enumeration to fail #2

Open hepr-skylotec opened 2 years ago

hepr-skylotec commented 2 years ago

Using:

While trying to get UsbX working all different setups would fail. Hardware is known good as the built in ST Bootloader enumerates correctly and works perfectly to flash over USB from Windows.

I finally tracked it down to the Buffer Descriptor table in PMA Memory not being correcly initialised by the UsbX STM adaptation layer in x-cube-azrtos-l4/tree/main/Middlewares/ST/usbx/common/usbx_stm32_device_controllers/

A "dumb" workaround by calling HAL_PCDEx_PMAConfig() before starting the stack makes enumeration work.

E.g. for a CDC class use the following works.

  HAL_PCDEx_PMAConfig(&hpcd_USB_FS, 0x00 , PCD_SNG_BUF, 0x18);
  HAL_PCDEx_PMAConfig(&hpcd_USB_FS, 0x80 , PCD_SNG_BUF, 0x58);
  HAL_PCDEx_PMAConfig(&hpcd_USB_FS, 0x81 , PCD_SNG_BUF, 0xC0);
  HAL_PCDEx_PMAConfig(&hpcd_USB_FS, 0x01 , PCD_SNG_BUF, 0x110);
  HAL_PCDEx_PMAConfig(&hpcd_USB_FS, 0x82 , PCD_SNG_BUF, 0x100);

But this should really be fixed in ux_dcd_stm32_initialize() or ux_dcd_stm32_initialize_complete()

Without any reasonable PMA configuration USB will always fail and be completely unusable.

AYEDMSTM commented 2 years ago

Hi @h-actsafe

Can you please take a look at this example of PMA config with Ux_Device_CDC_ACM developed on G0 [STM32G0C1E-EV] https://github.com/STMicroelectronics/x-cube-azrtos-g0/blob/2b77e6fa7dd42cd60a959cff12abc8c3055dc543/Projects/STM32G0C1E-EV/Applications/USBX/Ux_Device_CDC_ACM/USBX/App/app_usbx_device.c#L273

Best Regards. Mohamed