2023-07-05 11:04 AM - edited 2023-07-05 02:50 PM
I configured USB_OTG_FS on STM32H745I-DISCO board using STM32CubeIDE.
Here are my settings:
My `MX_USB_HOST_Init()` function is called in `DefaultTask`.
It completes without errors.
`USBH_UserProcess()` is called whenever a USB disk is inserted to the port, with `HOST_USER_CONNECTION`.
Then, in only one of like 10 different pendrives - I get `HOST_USER_CLASS_ACTIVE` state, then everything works, I can use any format on the USB disk. Via FatFs library. I tested it with FAT32 and ExFAT. Both seem to work perfectly without any issues.
But I just can't buy another pendrive that works with that. 10 other pendrives don't work. I get `HOST_USER_CONNECTION` and that's it. Nothing. The device is not detected as mass storage device. What's especially infuriating, that it happens also with exactly the same looking pendrives. They have the same capacity, same speed, even the same look, branding and all. TBH: I have 3 pendrives that work with H745. 2 of them were bought together, in one batch, the other one is a random one found in a drawer. 7 others are various bunch. Some of them are bought to be the same model as the working ones - unfortunately despite looking exactly the same, they don't work. Some of them are just similar "16GB / USB2.0". They are all recognized both by Windows and Linux. They are all formatted identically, as only one MBR partition, FAT32. Partition tools report even the same sector sizes and all partition description fields. The working USB can be formatted as FAT32, ExFAT, not formatted at all, deleted partition table - no matter what, it is detected as mass storage device. The others just don't work at all. USB host detects when they are inserted, but the MSC class initialization fails.
What's weird, I could swear a year ago I had it working with various pendrives. Then I upgraded the firmware a couple of times, but I haven't noticed anything breaking because I was using always the same pendrive for tests. Now when I try 10 different ones, only 3 / 10 work.
So I just created a new project on STM32H747I-DISCO. I configured the board to use external USB chip. My first test with a random pendrive - everything works. I get `HOST_USER_CLASS_ACTIVE` - so I try if it would work with different pendrives. And SURPRISE: it doesn't. I couldn't even make it work with the same as before. It turned out it was a fluke or something, because now on H747 USB doesn't work at all. I get `HOST_USER_CONNECTION` and the host hangs. After resetting the device it detects insertion, but no `CLASS_ACTIVE`.
What's wrong with this USB host? How should I proceed with trying to fix it? My guess is there is a bug in USB Host firmware / middleware released by ST for H745 (and probably for H747 too). I'm not sure, but I think I had it working once, but now, when I create new, empty projects - it's just it. Nothing on H747. On H745 I can work with just 1 type of pendrive, all others don't work.
I'm looking for an advice on how to debug that problem. I don't see any code parts of the USB host even run. What should I check first? How to even start debugging this? On "supported" USB stick a lot is happening. The data is transferred between MCU and USB, a lot of driver functions called. The problem is - it all happens as the host detects the device is connected. But this doesn't happen. Some sticks just seem like disconnect in the same moment they are connected. Others seem dead - like completely nothing happens. But they of course work with PC and phone.
Solved! Go to Solution.
2023-07-06 08:15 AM
OK, here's silly me. I tested everything in software, not even looking at the schematic:
What is U23 doing here? I haven't check that chip online, but it looks like a kind of power supply for USB host. With PA5 MCU pin on EN (I'm guessing "enable"). So I threw him "1" to see what would happen. And guess what - every single USB stick and memory card on my table works perfectly. So - my guess is the single one SanDisk that worked without it just got VBUS from GPIO, it didn't need much current to run so by a twisted chance it was enough for it to work. All others probably needed more current to operate (at least in peaks) so they died during the initialization.
2023-07-05 11:32 AM - edited 2023-07-05 11:35 AM
wrong? i dont know. :) but i have usb sticks (all, i tested, 1GB up to 64GB exfat) working ok.
on H743 , so probably same usb module.
i set port speed to medium, to reduce reflections:
try this.
2023-07-05 01:39 PM
Do you use the most recent H7 firmware pack? I use 1.11.0.
BTW, I changed PA11 and PA12 pins setup, it didn't help.
I observe on my "unsupported" stick I get disconnect signal on the very host start. Some other "unsupported" sticks seem to spam "connect" over and over again.
BTW, can you try if it works with SD card reader? My PC and Android phone sees it as a normal USB disk. My H745 "sees" it as "unsupported".
2023-07-05 03:00 PM - edited 2023-07-05 03:03 PM
> can you try if it works with SD card reader?
i dont understand -- if sdio is working ? -> yes, i have sdcard 4 bit mode at 50MHz running, no problem.
its an audio player, plays wav/flac/mp3 from sdcard/usbstick/radio (internet radio from ESP8266 by spi transfer).
my system is cubeIDE 1.10.1 , cubemx 6.6.1 , gnutools 2.0.0.2021 (not newest, but on my old linux system i had to install "back" an older gnu toolchain, because newer cannot run (missing new clib))
what could be helping, is if you get swo /swv data console working and see the debug messages from usb-host, looks like :
USB Device Reset Completed
PID: 5678h
VID: ffffh
Address (#1) assigned.
Manufacturer : USB
Product : Disk 2.0
Serial Number : 4939231172302356854
Enumeration done.
This device has only 1 configuration.
Default configuration set.
Switching to Interface (#0)
Class : 8h
SubClass : 6h
Protocol : 50h
MSC class started.
Number of supported LUN: 1
LUN #0:
Inquiry Vendor : VendorCo
Inquiry Product : ProductCode
Inquiry Version : 2.00
MSC Device ready
MSC Device capacity : 2785017344 Bytes
Block number : 122879999
Block Size : 512
USB stick -> mount
2023-07-05 10:35 PM - edited 2023-07-06 12:53 AM
my post from yesterday - needs some moderator, to be allowed. i write dangerous or things suspected of being terrorist. loosing interest, to write in this forum... hello moderator - thats dangerous also ??
btw, i get it now: >> can you try if it works with SD card reader?
sdcard in usb-card reader...right? i put 64BG card in old reader, voila, working without problem.
so - your problem has other reason.
this is debug msg on swo :
2023-07-06 03:57 AM - edited 2023-07-06 04:40 AM
Here's my SWV configuration:
It shows nothing in any view.
I also tried to find the "USB Device Connected" text, I put a breakpoint there. The line is not called when the completely not working stick is used. It is called on some of the semi-working ones.
My guess something wrong happens before even USB Host starts. The sticks (not working ones) seem to behave randomly. I mean - some of them try to disconnect on start. One disconnects, reconnects, then even starts MSC class, then fails miserably when trying to mount the filesystem. One of them just doesn't trigger anything. Like no connection attempt, no disconnection. Their behavior changes to other random pattern of connection / disconnection when I change the USB clock to something other than 48MHz. However, my only working stick works when the frequency is set to 48-50MHz, doesn't work with any other frequency. When it doesn't work - it triggers the connection event all the time when it's inserted (like in a loop). When it's not physically present - no events, when it's present, I get connection attempts one after another.
2023-07-06 04:39 AM
to get swv running was a long game...many hours.
1. swo is connected on your board ?
2. you set it in Cube... ?
3. you set core frequ. wrong - then its not working.
here my set: (with open ocd, but that should not be important)
in cube:
2023-07-06 05:50 AM
I've managed to redefine USBH debug function to output logs to my custom logger.
Here's what I got from SD card reader:
2023-07-06 06:35 AM - edited 2023-07-06 06:49 AM
>I've managed to redefine USBH debug function to output
cool ! :)
for me your debug output shows "normal" (same as mine) messages, until "ready" should come, block size etc.
no idea, why .
and (from crystal) 48MHz should be used, < 1% tol.
but other story, about doing nothing or repeat connect-error-connect- reminds me on a st-link, that got some static discharge by a colleague at company. doing similar game, but no more connect "right" .
so your chips have 2 usb ports, maybe you can try other, never used port - and be careful, not have any static and touch it... just an idea, if you shure, you never give them any discharge, forget this.
another problem: int priority - i just show you my working setting , i use no dma template, this i never got working:
i have sdcard and 2x usb host running, 1 usb msc (memory stick) and 1x usb audio host (not working, but STM has no working example, so difficult to make it run) and no dma on all, because problem with d-cache on H7 cpus.
test : switch off d-cache (dont enable it ) - makes any difference ?
2023-07-06 08:15 AM
OK, here's silly me. I tested everything in software, not even looking at the schematic:
What is U23 doing here? I haven't check that chip online, but it looks like a kind of power supply for USB host. With PA5 MCU pin on EN (I'm guessing "enable"). So I threw him "1" to see what would happen. And guess what - every single USB stick and memory card on my table works perfectly. So - my guess is the single one SanDisk that worked without it just got VBUS from GPIO, it didn't need much current to run so by a twisted chance it was enough for it to work. All others probably needed more current to operate (at least in peaks) so they died during the initialization.