How to change the USB instance?

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
Tetraeder
Posts: 53
Joined: Thu Mar 05, 2015 1:12 pm
Location: Germany

How to change the USB instance?

Post by Tetraeder » Tue Apr 07, 2015 2:54 pm

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?

thanks

blmorris
Posts: 348
Joined: Fri May 02, 2014 3:43 pm
Location: Massachusetts, USA

Re: How to change the USB instance?

Post by blmorris » Tue Apr 07, 2015 3:31 pm

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.

-Bryan

Tetraeder
Posts: 53
Joined: Thu Mar 05, 2015 1:12 pm
Location: Germany

Re: How to change the USB instance?

Post by Tetraeder » Thu Apr 09, 2015 9:41 am

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 */
    __GPIOB_CLK_ENABLE();
    
    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 */
#if defined(MICROPY_HW_USB_VBUS_DETECT_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);
#endif
	
#if defined(MICROPY_HW_USB_OTG_ID_PIN)
    // 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); 
#endif

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

Thanks, Tetraeder :?

blmorris
Posts: 348
Joined: Fri May 02, 2014 3:43 pm
Location: Massachusetts, USA

Re: How to change the USB instance?

Post by blmorris » Thu Apr 09, 2015 1:59 pm

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: http://forum.micropython.org/viewtopic.php?f=3&t=330 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.
-Bryan

blmorris
Posts: 348
Joined: Fri May 02, 2014 3:43 pm
Location: Massachusetts, USA

Re: How to change the USB instance?

Post by blmorris » Thu Apr 09, 2015 2:32 pm

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.)

-Bryan

Tetraeder
Posts: 53
Joined: Thu Mar 05, 2015 1:12 pm
Location: Germany

Re: How to change the USB instance?

Post by Tetraeder » Fri Apr 10, 2015 9:16 am

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.

blmorris
Posts: 348
Joined: Fri May 02, 2014 3:43 pm
Location: Massachusetts, USA

Re: How to change the USB instance?

Post by blmorris » Fri Apr 10, 2015 2:08 pm

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!
Bryan

Tetraeder
Posts: 53
Joined: Thu Mar 05, 2015 1:12 pm
Location: Germany

Re: How to change the USB instance?

Post by Tetraeder » Mon Apr 13, 2015 2:53 pm

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.

Post Reply