Skip to main content
Associate II
August 19, 2025
Solved

USB DCD on STM32H5 - HardFault after calling HAL_PCD_Start()

  • August 19, 2025
  • 3 replies
  • 1507 views

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.

 

 

Best answer by FBL

Hi @el_uho 

You should not return status = UX_SUCCESS; in USBD_STORAGE_Read, USBD_STORAGE_Write, or similar USBX MSC callbacks. Use instead: status = UX_STATE_NEXT;

Check this article How to implement USB mass storage device standalone.

3 replies

Technical Moderator
August 22, 2025

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.Best regards,FBL
el_uhoAuthor
Associate II
August 25, 2025

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.

el_uhoAuthor
Associate II
August 25, 2025

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...

 

Technical Moderator
August 29, 2025

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.Best regards,FBL
FBLBest answer
Technical Moderator
October 23, 2025

Hi @el_uho 

You should not return status = UX_SUCCESS; in USBD_STORAGE_Read, USBD_STORAGE_Write, or similar USBX MSC callbacks. Use instead: status = UX_STATE_NEXT;

Check this article How to implement USB mass storage device standalone.

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.Best regards,FBL
el_uhoAuthor
Associate II
October 27, 2025

This error is in Cube generated code, not user code.

Technical Moderator
October 27, 2025

Hi @el_uho 
The following section code should be implemented by user and not generated by MX code. 

/* USER CODE BEGIN 1 */
VOID USBX_Device_Process(VOID)
{
 ux_device_stack_tasks_run();
}
/* USER CODE END 1 */

 

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.Best regards,FBL