2025-08-13 4:32 PM
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.
Solved! Go to Solution.
2025-12-22 11:19 AM
Hi. My problem was that I didn't have the APB2 clock >= 12MHz. This is mentioned in a single line in the reference manual in the middle of "Structure and usage of packet buffers"...
2025-08-14 2:58 AM - edited 2025-08-14 3:00 AM
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.
2025-08-14 9:01 PM
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.
2025-12-21 8:40 PM
Hi, did you find a working example for U545 to read/write data to a USB Pen Drive?
2025-12-22 11:19 AM
Hi. My problem was that I didn't have the APB2 clock >= 12MHz. This is mentioned in a single line in the reference manual in the middle of "Structure and usage of packet buffers"...
2025-12-24 7:13 AM - edited 2025-12-24 9:50 AM
Sorry it's been a while and I didn't see you reply.
Would you attach your full software setup? I will try to replicate on my NUCLEO-U545RE-Q. It's possible that we we have an issue in classic core MW (from ST library to be addressed and reported) If I cannot replicate it means there must be an issue with your hardware setup.
@SamMiddleton wrote: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.
This must be a misunderstanding! I meant the host never "sends an IN packet" as data. As you know, there is big difference between IN token and IN data transfer.
If you consider solving your initial issue by increasing APB2 clock >= 12MHz, please select your comment as best answer.
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.
2025-12-24 7:39 AM
Hi, Thanks for the response.
After increasing the APB2 clock from 4MHz to 48MHz, I could get one connect and disconnect indication. The next connect/disconnect is not detected. Also file operations do not work - I need to do some more debugging.
I am using the sample code from the link below, modified for U545.
https://github.com/ST-TOMAS-Examples-USB/u5a5_usbx_host_msc_standalone
Even though I require Stand-alone operation without ThreadX, I decided to create an application using ThreadX so I could get familiar with the USBX/FILEX classes. I referenced \STM32Cube\Repository\STM32Cube_FW_U5_V1.8.0\Projects\STM32U575I-EV\Applications\USBX\Ux_Host_MSC
and replicated the U575 settings in CUBEMX for U545.
I observed that in CUBEMX, under "USBX Mode and Configuration"->"UX Host FS"->"Host Class FS"->"MSC" is disabled.
I am testing using the NUCLEO-U545RE-Q and intend to use the same IC with production boards to be interchangeable with F105/F405.
If possible, can you confirm if you could finally get the USB stick working with U545.
That way I would know if I should continue working with the U545 or wait till support is available.
I have tried to query ST and hopefully they will also clarify the status of USB HOST MSC with U545.
2025-12-24 9:56 AM
Hi @NFern.1
This is because you need to enable FileX in CubeMX.
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.
2025-12-25 7:09 PM
Thanks @FBL , on enabling FileX in CubeMX the Host Class FS -> MSC option is now enabled.
2025-12-25 9:50 PM - edited 2026-01-11 8:28 PM
That behavior usually means the control IN stage is never properly primed.
On STM32U545, common causes are:
Using the wrong USB core. The U545 needs USB OTG HS with internal FS PHY, not the legacy FS core.
EP0 set to 64 bytes too early. It must stay at 8 bytes until the first device descriptor read succeeds Port Solutions.
Buffer alignment or DCache issues. Control buffers must be aligned and cache cleaned or DCache temporarily disabled.
VBUS sensing or power not configured correctly.
Check those first. In most U5 cases, switching to the CubeU5 USB Host stack or fixing EP0 and cache handling resolves it.