March 19, 2025

Black Pill boards - F411 USB -- try USB on the F407

I have several Olimex boards with F4xx chips:
P405 with one USB connector (old Square device connector)
P407 with USB host and USB otg connectors (the HS is the otg)
E407 with two mini-USB device connectors
I selected the E407 to work with because it has both the FS and HS usb devices wired to what look like identical ports.

The board needs a 6-16 (maybe 6-24) volt supply on a barrel connector (beware, the P407 must only have a 5 volt supply!). I soldered some headers to give access to the serial port pins. I found the pins in the JTAG connector to connect a ST-Link SWD port to.

Then the work was in the Hydra source. The E407 uses unusual GPIO pins for UART1, so I had to make some changes in gpio_411.c and serial.c. The E407 uses a 12 Mhz crystal, so I needed to make changes in rcc_411.c After this the board runs Hydra with serial display at 115200 baud.

After this, I connected a USB cable to the USB connector closes to the ethernet (this is USB FS) and it immediately enumerated as it should and linux set it up as /dev/ttyACM0. It works perfectly.

Now I would like to try the other USB (HS) connector. It is also a min-USB and the schematic shows that it is wired exactly the same as the FS connector.

The USB drive I use in Hydra will not support two USB ports at the same time. This is something I will need to fix, but for now I need to edit source to select one or the other and then recompile. I do that, add some printf statements, recompile, and reboot. I see:

Initialize HS usb core with IRQ 77
USB init HS core: 40040000
USB base address: 40040000
I plug in the USB cable and see this in the linux logs:
Mar 19 16:34:07 trona kernel: usb 4-1.6: new full-speed USB device number 35 using ehci-pci
Mar 19 16:34:07 trona kernel: usb 4-1.6: device descriptor read/64, error -32
Mar 19 16:34:07 trona kernel: usb 4-1.6: device descriptor read/64, error -32
....
....
Mar 19 16:34:09 trona kernel: usb 4-1-port6: unable to enumerate USB device
I check a variety of things. I make sure that I enable to clock for the HS USB in rcc_411.c. Then I take a look at nvic.c. Aha!! I find a limit on the number of IRQ set to 68. This is correct for the F411, but we want to use IRQ 77 on the F405, F407, and F429. We can get values all the way to 90 with the F429. I fix this.

I doublecheck the pins for HS usb. The are PB14 (DM) and PB15 (DP) as they should be.

Now we get one HS interrupt on reboot, but not when I plug/unplug.

Initialize HS usb core with IRQ 77
USB init HS core: 40040000
HS interrupt
OTG ISR called
OTG ISR status: 00001000
We get the status as follows:
v = USB_OTG_READ_REG32(&pdev->regs.GREGS->GINTSTS);
v &= USB_OTG_READ_REG32(&pdev->regs.GREGS->GINTMSK);
This is a USB reset interrupt.
Feedback? Questions? Drop me a line!

Tom's Computer Info / tom@mmto.org