Author Topic: STM32F411 USB module step by step  (Read 8111 times)

0 Members and 3 Guests are viewing this topic.

Online Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 5330
  • Country: nl
Re: STM32F411 USB module step by step
« Reply #25 on: July 25, 2025, 04:23:18 pm »
Getting USB to work on any microcontroller from just reading documentation and writing your own code is  much more likely to drive you stark raving mad then get you to something that works. And this is regardless to what uC you use. USB is a quite complicated protocol and there are many details which all have to be dust right before anything works. From the initial startup, to "registering" your uC on the USB bus, and getting descriptors and endpoints for higher level protocols.

I have dabbed a little toe in this once. I compiled and flashed the serial demo from Satoshinm. It is a bridge that uses an STM32F103 to create 3 UART's, and the project is on github. I flashed it, saw my Linux box recognised three serial ports, and I started a few terminal emulators and echoed data back from one port to another by adding some jumpers on the breadboard with the good old Blue Pill (From back when they were still real). But that was in 2018, and after that... I got distracted.
 
The following users thanked this post: peter-h

Offline peter-h

  • Super Contributor
  • ***
  • Posts: 6002
  • Country: gb
  • Doing electronics since the 1960s...
Re: STM32F411 USB module step by step
« Reply #26 on: July 26, 2025, 07:33:01 am »
I spent weeks of my life making the Cube IDE STM USB code to work properly, with flow control in the VCP.

And some aspects were never resolved e.g. when implementing MSC (removable storage device) how do you handle the FLASH programming time? The host performs a 512 byte sector write which takes 15ms to program. The supposed correct way - some sort of SCSI device emulation - is to return a Busy status, which the host will poll (at 1kHz, IIRC) but this doesn't actually work (with Windows), and it turns out that all FLASH sticks just hang in there for the programming time. That seems to have the best compatibility across host operating systems. So I just hang for the 15ms in the ISR...

I posted a lot of detail on this a few years ago.
Z80 Z180 Z280 Z8 S8 8031 8051 H8/300 H8/500 80x86 90S1200 32F417
 
The following users thanked this post: grantb5

Offline paulca

  • Super Contributor
  • ***
  • Posts: 6386
  • Country: gb
Re: STM32F411 USB module step by step
« Reply #27 on: July 26, 2025, 10:33:21 am »
I spent weeks of my life making the Cube IDE STM USB code to work properly, with flow control in the VCP.

And some aspects were never resolved e.g. when implementing MSC (removable storage device) how do you handle the FLASH programming time? The host performs a 512 byte sector write which takes 15ms to program. The supposed correct way - some sort of SCSI device emulation - is to return a Busy status, which the host will poll (at 1kHz, IIRC) but this doesn't actually work (with Windows), and it turns out that all FLASH sticks just hang in there for the programming time. That seems to have the best compatibility across host operating systems. So I just hang for the 15ms in the ISR...

I posted a lot of detail on this a few years ago.


Welcome to the "Wizard of Oz" effect of modern "consumer" electronics.

The fantasy:  Datasheets and technical manuals.
The reality: Dirty unfinished, but cheap hacks and the consumer has no idea.

Anyone can build an electronic circuit, but it takes an electronics engineer to make one that barely work, but can no longer be budget squeezed into any more dirty hacks and still work.
« Last Edit: July 26, 2025, 10:36:53 am by paulca »
"What could possibly go wrong?"
Current Open Projects:  68000 Self Build computer + OS.
 

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 17785
  • Country: fr
Re: STM32F411 USB module step by step
« Reply #28 on: July 26, 2025, 03:26:47 pm »
I spent weeks of my life making the Cube IDE STM USB code to work properly, with flow control in the VCP.

And some aspects were never resolved e.g. when implementing MSC (removable storage device) how do you handle the FLASH programming time? The host performs a 512 byte sector write which takes 15ms to program. The supposed correct way - some sort of SCSI device emulation - is to return a Busy status, which the host will poll (at 1kHz, IIRC) but this doesn't actually work (with Windows), and it turns out that all FLASH sticks just hang in there for the programming time. That seems to have the best compatibility across host operating systems. So I just hang for the 15ms in the ISR...

I posted a lot of detail on this a few years ago.

Yep. As a more or less general rule, never consider any code provided by MCU vendors as production-ready. It very, very rarely is.

Did you consider switching to TinyUSB? Maybe not perfect, but I think it's already eons better than the USB "middleware" provided by ST.
 

Offline peter-h

  • Super Contributor
  • ***
  • Posts: 6002
  • Country: gb
  • Doing electronics since the 1960s...
Re: STM32F411 USB module step by step
« Reply #29 on: July 26, 2025, 05:21:22 pm »
I did but by then I had the ST version pretty well working.

I think the main problem is that ST has no contact with users, other than huge automotive customers with direct accounts. In the 1980s I had direct accounts with a few firms (e.g. Zilog) and saw just how differently that works. The ST forum is almost totally dysfunctional, with a few dedicated individuals helping people (but mostly with one-liners), with some very clever but extremely rude people (the famous "Piranha" being one) not helping anybody except by accident or by posting "treasure hunt" clues, and with with ST employees on it having no apparent influence in the company. And of course most commercial (as opposed to hobby or academic) users are just leechers who never feed back working code, so most of the stuff supplied with e.g. Cube IDE will never be ready to use. Exceptions were FatFS and FreeRTOS.

« Last Edit: July 27, 2025, 08:44:44 pm by peter-h »
Z80 Z180 Z280 Z8 S8 8031 8051 H8/300 H8/500 80x86 90S1200 32F417
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf