cancel
Showing results for 
Search instead for 
Did you mean: 

USB DCD on STM32H5 - HardFault after calling HAL_PCD_Start()

el_uho
Associate II

As the title says.

I am using STM32H523RCT6 with no RTOS (no ThreadX) and USBX in Standalone mode.

The code is basically:

MX_USB_PCD_Init();

MX_USBX_Device_Init();

HAL_PCD_Start(&hpcd_USB_DRD_FS);

 

Which executes, but as soon as the USB_DRD_FS_IRQHandler is called, I run into a hard fault. The trace is:

USB_DRD_FS_IRQHandler()

HAL_PCD_IRQHandler

HAL_PCD_ResetCallback

_ux_dcd_stm32_initialize_complete

at

/* Create the default control endpoint attached to the device.

Once this endpoint is enabled, the host can then send a setup packet

The device controller will receive it and will call the setup function

module. */

dcd -> ux_slave_dcd_function(dcd, UX_DCD_CREATE_ENDPOINT,

(VOID *) &device -> ux_slave_device_control_endpoint);

the USB_FNR register shows LSOF 0x3 as well as the LCK and RXDP bit set and the USB_ISTR has the bits ESOF, SOF, RST_DCON and SUSP set.

Please help, I've already lost way too much time on this.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

I got it working.

This is one of the posts that helped: https://community.st.com/t5/stm32-mcus-embedded-software/usbx-device-msc-in-standalone-mode/m-p/819314/highlight/true#M65478 

where the 

_ux_device_class_storage_disk_wait

function must me modified -> this should be addressed by ST, since the error is in MX-generated code.

Additionally, this thread helped: https://community.st.com/t5/stm32-mcus/how-to-implement-usbx-in-standalone-mode/ta-p/614435 because the call to 

ux_device_stack_tasks_run();

was missing in my code - shouldn't this call be somehow generated by MX?

 

Additionally, I had to modify the

UINT MX_USBX_Device_Init(VOID)

function to include

MX_USB_PCD_Init();

HAL_PCDEx_PMAConfig(&hpcd_USB_DRD_FS, 0x00, PCD_SNG_BUF, 0x40);
HAL_PCDEx_PMAConfig(&hpcd_USB_DRD_FS, 0x80, PCD_SNG_BUF, 0x80);
HAL_PCDEx_PMAConfig(&hpcd_USB_DRD_FS, USBD_MSC_EPOUT_ADDR, PCD_SNG_BUF, 0xC0);
HAL_PCDEx_PMAConfig(&hpcd_USB_DRD_FS, USBD_MSC_EPIN_ADDR, PCD_SNG_BUF, 0x2C0);

_ux_dcd_stm32_initialize((ULONG)USB_DRD_FS, (ULONG)&hpcd_USB_DRD_FS);

HAL_PCD_Start(&hpcd_USB_DRD_FS);

in this particular order...

 

View solution in original post

6 REPLIES 6
FBL
ST Employee

Hi @el_uho 

Do you reproduce using promotional boards (like NUCLEO-H563ZI, NUCLEO-H533RE) ? If so, do you reproduce starting with example firmware provided? If not, check your hardware setup and compare with schematics provided.

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.


el_uho
Associate II

Hi!

No, I tried using this example: https://github.com/STMicroelectronics/STM32CubeH5/tree/main/Projects/STM32H573I-DK/Applications/USBX/Ux_Device_MSC and removing the ThreadX stuff because I'm not using RTOS.

 

I am using a custom hardware that is proven to be working (CDC virtual com port works).

 

I got past the Hard Fault now by piecing together some code from the example that I was missing (code from the USBX_APP_Device_Init() function and app_ux_device_thread_entry code) and am now facing a "Device not recognized, failed to get device descriptors" error when attaching to PC. 

The USBD_ChangeFunction(ULONG Device_State) is called multiple times after attaching to the Host PC but with unknown states (not present in ux_api.h File) like 0xF4 and 0xF3 and 0xF0.

I got it working.

This is one of the posts that helped: https://community.st.com/t5/stm32-mcus-embedded-software/usbx-device-msc-in-standalone-mode/m-p/819314/highlight/true#M65478 

where the 

_ux_device_class_storage_disk_wait

function must me modified -> this should be addressed by ST, since the error is in MX-generated code.

Additionally, this thread helped: https://community.st.com/t5/stm32-mcus/how-to-implement-usbx-in-standalone-mode/ta-p/614435 because the call to 

ux_device_stack_tasks_run();

was missing in my code - shouldn't this call be somehow generated by MX?

 

Additionally, I had to modify the

UINT MX_USBX_Device_Init(VOID)

function to include

MX_USB_PCD_Init();

HAL_PCDEx_PMAConfig(&hpcd_USB_DRD_FS, 0x00, PCD_SNG_BUF, 0x40);
HAL_PCDEx_PMAConfig(&hpcd_USB_DRD_FS, 0x80, PCD_SNG_BUF, 0x80);
HAL_PCDEx_PMAConfig(&hpcd_USB_DRD_FS, USBD_MSC_EPOUT_ADDR, PCD_SNG_BUF, 0xC0);
HAL_PCDEx_PMAConfig(&hpcd_USB_DRD_FS, USBD_MSC_EPIN_ADDR, PCD_SNG_BUF, 0x2C0);

_ux_dcd_stm32_initialize((ULONG)USB_DRD_FS, (ULONG)&hpcd_USB_DRD_FS);

HAL_PCD_Start(&hpcd_USB_DRD_FS);

in this particular order...

 

Hi @el_uho 

Would you share your firmware to check with you in standalone mode.

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.


el_uho
Associate II

Hi,

no, I can't publicly share the code. The USB part is woven into some proprietary code that cannot be shared. 

FBL
ST Employee

Hi @el_uho 

Thank you for bringing this to our attention. I have tracked this internally for fix. (216585 internal ticket number just for internal tracking). 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.