cancel
Showing results for 
Search instead for 
Did you mean: 

USB Host MCU Middleware on STM32U545

SamMiddleton
Associate II

Hi. I'm having trouble using the old USB Host Middleware to read a USB stick with a STM32U545.

I've tried to follow this article, doing my best to adapt it for the host middleware and also using the "FatFs_USBDisk" example project for the F767 Nucleo board and a usbh_conf.c/.h written by a coworker for another U545 project which supposedly worked at least once.

My code fails in Enumeration when the MCU tries to get the device descriptor - The MCU sends a SETUP packet and a DATA0 packet with 0 bytes (instead of the expected 8) and the stick sends an ACK. The MCU then sends an IN packet and the stick sends a NACK. The IN & NACK are then repeated for many frames until the stick sends a STALL instead.

Can anyone help me identify where the bug is and how to fix it?

Thanks.

2 REPLIES 2
FBL
ST Employee

Hi @SamMiddleton 

First, to clarify, MCU can't send an IN packet as host! It should be an OUT packet.

You can follow the initialization provided in this example without diving into USBX staff. Then you can follow examples here to initialize your stack, framework etc. You should be cautious because USB controller is different, even for STM32U545 compared to U575 itself. Make sure to properly initialize the controller and check your hardware setup as provided in U545-nucleo board.

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.


Hi @FBL

I have tried all day to get either example you gave working on the hardware I have available.

I have a NUCLEO-U575ZI-Q, but the USB Host example only has config for EWARM, not STM32CubeIDE.
I did my best to copy the code into a new cube project and get it compiling, but the guidance on how to mod the board to provide VBUS is minimal. I tried supplying 5V to the 'USB_5V' test point, but when I insert a USB stick, I don't see DP or DM go high (probing both sides of SB40 and SB41). Where is the best place to inject VBUS?

I have attempted to port the NUCLEO-U545RE-Q example to my U545CE board, but I have no experience with ThreadX and I am getting a wild variety of hard faults.

Also, you seem to have gotten your USB protocol layers confused. A successful IN transaction consists of the host sending an IN packet, the device sending a DATAx packet and the host sending an ACK packet.

To elaborate on what I got before: I followed the "FatFs_USBDisk" for the F767 from the Example selector, with my best attempt at porting it to the U545. When I plug in a USB stick, I get the following on the UART:

USB Device Connected
USB Device Reset Completed
ERROR: Control error: Get Device Descriptor request failed
USB Device Connected
USB Device Reset Completed
ERROR: Control error: Get Device Descriptor request failed
USB Device Connected
USB Device Reset Completed
ERROR: Control error: Get Device Descriptor request failed
USB Device Connected
USB Device Reset Completed
ERROR: Control error: Get Device Descriptor request failed
Control error, Device not Responding Please unplug the Device.

By placing breakpoints, I can see the code prepare a SETUP request that looks sensible in USBH_GetDescriptor.

This should cause a Control Transfer, which consists of 3 stages/transactions - setup, data & status.
The setup transaction should be a SETUP packet & 8-byte DATA0 packet from the host and an ACK packet from the device. I see a 0-byte DATA0 packet, but the device still ACKs.
The host then tries to move to the data stage, which should be an IN transaction, so it sends an IN packet, but the device can't know what data it's expected to provide because the setup transaction contained no data, so it NACKs for a while then STALLs

I can tell what packets are being sent because I scoped the DP & DM lines and wrote my own decoder.