March 5, 2025

STM32F429 Discovery Kit - Which USB do we have?

The schematic shows OTG_FS_DP routed to PB15 and OTG_FS_DM routed to PB14.

The chip has two USB controllers. I wonder which this is?

The TRM has information about pins and alternate functions in the GPIO section (section 8). It says that setting 10 selects USB (either one). Also, setting 12 can select OTG_HS for certain pins. Now we need a table of pins.

The datasheet (on page 62) shows that PB14 has OTG_HS_DM available, and that PB15 has OTG_HS_DP available.

The TRM on page 65 has a table of addresses and shows:

0x5000_0000 is USB_OTG_FS (register map on page 1326)
0x4004_0000 is USB_OTG_HS (register map on page 1472)
Based on the pins the schematic shows connected to the connector, we have the "HS" usb controller available.

BSP and such

The Hydra usbF4 code from Arduino_STM32 has a file vcp/usb_bsp.c that contains some important hardware definitions. In particular, it references:
BOARD_USB_DM_PIN and BOARD_USB_DP_PIN
The reference is in code that I have commented out, but looking back to Arduino-STM33 I find these definitions in:
./STM32F4/variants/generic_f407v/generic_f407v.h:#define BOARD_USB_DM_PIN		PA11
./STM32F4/variants/generic_f407v/generic_f407v.h:#define USB_DM_PIN		BOARD_USB_DM_PIN // PA11
./STM32F4/variants/disco_f411/disco_f411.h:#define BOARD_USB_DM_PIN		PA11
./STM32F4/variants/arch_max/arch_max.h:#define BOARD_USB_DM_PIN		PA11
./STM32F4/variants/arch_max/arch_max.h:#define USB_DM_PIN		BOARD_USB_DM_PIN // PA11
./STM32F4/variants/discovery_f407/discovery_f4.h:#define BOARD_USB_DM_PIN		PA11
./STM32F4/variants/blackpill_f401/blackpill_f401.h:#define BOARD_USB_DM_PIN		PA11
No support for my 429 discovery board, but these files ought to be interesting to take a peek at. The pins themselves are defined like this:
enum {
PA0,PA1,PA2,PA3,PA4,PA5,PA6,PA7,PA8,PA9,PA10,PA11,PA12,PA13,PA14,PA15,
PB0,PB1,PB2,PB3,PB4,PB5,PB6,PB7,PB8,PB9,PB10,PB12=(PB10+2),PB13,PB14,PB15,
PC13=(32+13),PC14,PC15,
BOARD_NR_GPIO_PINS
};
This is interesting! A nameless enum that serves to define the entities within.

Experiments with Hydra

First of all, the serial port runs at 38400 baud -- no doubt something to do with the choice of baud rate clock that we can fix and bump up to 115200.

Nothing is happening on the USB at 0x5000_0000 (which works with the F411). The base address gets set in driver/usb_core.c as follows:

baseAddress                = USB_OTG_FS_BASE_ADDR;
And in driver/usb_regs.h we see:
#define USB_OTG_HS_BASE_ADDR                 0x40040000
#define USB_OTG_FS_BASE_ADDR                 0x50000000
I change usb_core.c to use the HS base address for the F429

In the file Hydra/gpio_411.c is the code that sets up the USB data pins. We should move the gpio_usb_init() routine down into the usbF4 directory.
It currently sets A11 for DM and A12 for DP
We want B14 for DM and B15 for DP


Feedback? Questions? Drop me a line!

Tom's Computer Info / tom@mmto.org