cancel
Showing results for 
Search instead for 
Did you mean: 

USB-Host with STM32U5 and ThreadX

AWack
Senior

Hi,

I try to get the USB-Host running with USBX. Hardware is a custom board with TCPP02 and STM32U575.

Init process is running, but I never get an interrupt (ux_host_event_callback) when plugging in a USB stick. Any idea?

ioc file and schematic are attached.

Best regards,

Achim

5 REPLIES 5
FBL
ST Employee

Hello @AWack 

When initializing host USBX stack , did you use ux_host_event_callback? You can refer to this example.

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

Yes, I initialize this function as in your example...

Is this callback triggered by the CC1/2 lines? (I´m using USB-C)

 

Hi, don´t know why, but when I started debugging again this morning, the interrupt was fired. But then in void HAL_HCD_Connect_Callback(HCD_HandleTypeDef *hhcd) I get a hard fault in this call: hcd_stm32 = (UX_HCD_STM32*)hcd -> ux_hcd_controller_hardware;

After this hard fault hcd_stm32 has the following content:

AWack_0-1777278034251.png

 

FBL
ST Employee

Hi @AWack 

The ux_host_event_callback is normally triggered by the USB interrupt. This interrupt is not expected to fire if the USB stick is not detected, or if it is not properly recognized/processed, as this is not related to the CC lines.

The function is registered to handle USB events, but based on your description, it appears that it is not being called initially.

Could you please check whether App_ThreadX_Init() is called before or after MX_USBX_Host_Init()? It should be after MX_USBX_Host_Init()  even though CubeMX is still generating it in the opposite order..

There may be a timing issue where the USB host interrupt fires before the USBX host objects are fully initialized.

Also, please ensure that the byte pool buffer is cleared before initialization:

	memset(ux_host_byte_pool_buffer, 0, UX_HOST_APP_MEM_POOL_SIZE);

 

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

Hi FBL,

Indeed the order is mixed up by CubeMX. I´ve now corrected it, but still get an hard fault when plugging the USB-Stick :(

In my main.c the following MX Inits are done:

MX_GPIO_Init();
MX_GPDMA1_Init();
MX_ADC1_Init();
MX_FDCAN1_Init();
MX_I2C2_Init();
MX_TIM1_Init();
MX_UCPD1_Init();
MX_USART2_UART_Init();
MX_USB_OTG_FS_HCD_Init();
MX_ICACHE_Init();
/* Call PreOsInit function */
USBPD_PreInitOs();
/* USER CODE BEGIN 2 */
HAL_HCD_Start(&hhcd_USB_OTG_FS);
/* USER CODE END 2 */

MX_ThreadX_Init();

The user code 2 I´ve added. Without this no interrupt is fired.

Attached also my corrected app_azure_rtos.c according your hints.