machine/stm32: add OTG FS USB driver for F4/F7#5404
Conversation
c4c2e31 to
5e806ae
Compare
STM32F4 and F7 share the same OTG FS IP but have no USB driver in TinyGo. This adds a full device-mode driver covering CDC, HID, and MSC with working examples. - OTG FS has 4 physical EPs (0–3); virtual indices 4–7 fold onto them via physEP() so the existing machine/usb API is unchanged - F4 bypasses VBUS sensing via GCCFG.NOVBUSSENS; F7 uses the USB voltage regulator + GOTGCTL B-valid override instead - STM32F7 PLL_Q changed 2→9 to produce the 48 MHz clock required by USB/RNG/SDMMC; CK48MSEL cleared to select main PLL as source - HID and MSC descriptors remapped at init() to physical endpoint addresses (EP2/EP1 for HID, EP2/EP3 for MSC) - usb-storage example replaced machine.Flash with a FAT12 RAM disk so the host mounts without reformatting - MSC sendCSW sets queuedBytes before state transition to fix a missed byte-count on the status phase
5e806ae to
3aaf8e5
Compare
|
Hello @digitalentity thank you very much for working on this. I would suggest breaking this into a few different PRs so that it is easier to review the changes. For example:
Very importantly, at present we do not have any code in the You should figure out how to isolate your changes so that platform code does not end up in that package or sub-packages. Probably after you split off the non-platform specific changes, this will be a lot easier to achieve. |
|
Hey, thanks for the review.
The HID and MSC descriptor remap stems from the fact that STM32 has only 4 EPs and the TinyGo system currently assumes 8. I see three possible options:
I suggest we do the (2). This comes with some risk of breaking existing applications that use USB though. |
Perhaps some of the serious USB people like @sago35 @mikesmitty and others of course can offer their feedback on this question. If option number 2 is practical on all platforms that sounds like the best choice, but I have not looked into that question yet. |
|
This I think |
|
On Option 2 - EPs are bidirectional, nothing is preventing us from doing mix & match - with 4 EPs (effectively 8 unidirectional streams) we can fit HID (2), MSC (2) and CDC (3) into the same device in principle. |
STM32F4 and F7 share the same OTG FS IP but have no USB driver in TinyGo. This adds a full device-mode driver covering CDC, HID, and MSC with working examples.
Tested on CDC, HID and MSC examples.
CDC example, echo verified to work:
HID example:
MSC example, RAM disk verified to handle write/read correctly:
Fixes #4751