Page 1 of 1

How to change the USB instance?

Posted: Tue Apr 07, 2015 2:54 pm
by Tetraeder
Hallo again :) ,

I have changed the USB port configuration in /stmhal/usbd_conf.c for the USB_OTG_FS.

My Question is, in which file will set the variable ``hpcd->Instance``?
Or is decided by the driver, whether HighSpeed or FullSpeed?


Re: How to change the USB instance?

Posted: Tue Apr 07, 2015 3:31 pm
by blmorris
USB High-Speed (HS - 480 MHz) operation is not available on the pyboard. Supporting HS operation requires an external physical transceiver chip (known as a ULPI PHY) connected to the STM32F405 through an 8-bit parallel interface; if I recall correctly, the total number of required pins (with clock and signaling pins) can be 11, 12 or 13 depending on the configuration.
The processor's onboard USB PHY only supports FS (12 MHz) operation.


Re: How to change the USB instance?

Posted: Thu Apr 09, 2015 9:41 am
by Tetraeder
okay, so HS is not supported without an external transceiver.

For my understanding:
Therefore at the line 97 in /stmhal/usbd_conf.c is the HS-config for other targets how has USB-HighSpeed support, right?
The pyboard uses the FS-config starting at line 57 (stmhal/usbd_conf.c), declared in /stmhal/boards/BOARDNAME/stm32f4xx_hal_conf.h with

Code: Select all

#define USE_USB_FS
Why i asked i have a STM32F429i board and i want to use the USB_OTG at connector CN6 (Port_B Pin: 12,13,14,15) to get connection to the repl-prompt. I have changed the GPIO-clock, the pin-config, USB-clock and interrupts, but my changes takes no effect.
Has anyone tried this before?
Which files should I explore next?
It is at all possible?

My changes in /stmhal/usbd_conf.c

Code: Select all

if(hpcd->Instance == USB_OTG_FS)
    /* Configure USB FS GPIOs */
    GPIO_InitStruct.Pin = GPIO_PIN_14 | GPIO_PIN_15;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
    GPIO_InitStruct.Alternate = GPIO_AF12_OTG_HS_FS;
    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); 
	/* Configure VBUS Pin */
    // USB VBUS detect pin is B13
    GPIO_InitStruct.Pin = GPIO_PIN_13;
    GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
    // USB ID pin is B12
    GPIO_InitStruct.Pin = GPIO_PIN_12;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
    GPIO_InitStruct.Pull = GPIO_PULLUP;
    GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
    GPIO_InitStruct.Alternate = GPIO_AF12_OTG_HS_FS;
    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); 

    /* Enable USB HS Clocks */ 
    /* Set USBHS Interrupt priority */
    HAL_NVIC_SetPriority(OTG_HS_IRQn, 6, 0);
    /* Enable USBHS Interrupt */
Also changed the USB-config in mpconfigboard.h.

Thanks, Tetraeder :?

Re: How to change the USB instance?

Posted: Thu Apr 09, 2015 1:59 pm
by blmorris
Hi Tetraeder-
My last bit of advice may not have been entirely correct - I ran into this same issue some time ago, but I didn't remember until I started to look in to your problem.
There are actually two distinct USB controllers on the chip: One of them is a FS-only controller, with the D+ and D- data lines connected to PA12 and PA11. The other is a combined FS/HS controller, but the documentation often just calls it USB-HS.

In order to use the combined controller in HS mode, you need an external transceiver connected via the parallel ULPI interface. However, this controller also provides an FS-only interface, with the data pins connected on PB14 and PB15. This is the interface that you need for the STM32F429i, so you will need to configure the USB code to use the HS controller, but in FS mode.

Sorry for the confusion. It should be possible to get the USB on this board to work under MicroPython, and it would be a great board to support. Now that I found the mistake, I'll take another look at the usbd_conf.c file to see if there is anything else to pay attention to.

Another user tried to port MicroPython to the STM32F429i board: but based on that thread I suspect he got stuck on the same issue as you. That thread mentions the OpenMV project which uses the same processor, the STM32F429, but the schematics posted for that project indicate that it uses the USB controller on PA11/PA12, instead of the controller on PB14/P15.

Good luck, and let us know how it goes.

Re: How to change the USB instance?

Posted: Thu Apr 09, 2015 2:32 pm
by blmorris
One more thing - Firmware upgrade via DFU is only available on the PA11/12 USB port, not on the PB14/15 port - this appears to be true for all of the STM32F4xx processors. This is not a problem for the STM32F429i board, as it has separate hardware for firmware loading and debugging. This is probably one reason why Ibrahim chose the PA11/12 port for the OpenMV board (as well as consistency with the pyboard, it was probably the easiest way to go.)


Re: How to change the USB instance?

Posted: Fri Apr 10, 2015 9:16 am
by Tetraeder
Thanks for the quick answers, blmorris.

Exactly i will use the combined FS/HS (USB-HS) controller (CN6) in Full-Speed-Mode for the repl and CN1 for power supply / firmware upgrade (ST-Link/V2)
Currently running MicroPython at the F429i with many modules (LED,PWM,UART,... and a repl-prompt via UART).

I have also look in the source code from the OpenMV-Project and he uses the pins PA11/12. Unfortunately not what I need :cry: I might have a go rewire the board, in example CN6 on PA11/12 :D . No, that would be the last attempt. ;) Or i bypass the ST-Link/V2 and use the CN1...many options!

I try my best :idea:

If anyone has a solution, please let me know.

Re: How to change the USB instance?

Posted: Fri Apr 10, 2015 2:08 pm
by blmorris
My guess is that you were on the right track initially when you were trying to enable the USB_OTG_HS instance in /stmhal/usbd_conf.c
The trick is how to enable the HS instance while using the built-in Full Speed PHY (the USB signal pins on PB14 & PB15.)
I can't work on this myself right now - no board to test on - but the next place I would look is the STM32F429 discovery firmware package - it will be based on the same HAL code as MicroPython (or maybe a slightly different version number) but it will almost certainly provide a working example for configuring the USB port.

I don't think it will be necessary to rewire your board - it has to be possible to get the existing USB connection working in software.

Good Luck!

Re: How to change the USB instance?

Posted: Mon Apr 13, 2015 2:53 pm
by Tetraeder
Little update,...
The STM32F429 discovery firmware package included libraries for the USB_OTG_HS, this is the right track.

I try to integrate the libraries....i report back soon.