cancel
Showing results for 
Search instead for 
Did you mean: 

USB initialisation and deinitialisation

brians
Associate II
Posted on March 13, 2017 at 17:13

I am using USB CDC both for bootloader and in the loaded application with the IAR toolset and the CubeMX Middleware/HALlibrary.  Turning off the USB & Timer interrupts before the jump it jumps cleanly and runs the application, except that the USB will not restart (USBD_Start). I am using the normal start USBD start sequence.  If I load the application and run it at the same address all is fine and USB initialises runs as expected.  Is there a prescribed way to turn off USB in the boot loader and re-start it in an application?

22 REPLIES 22
zdravko
Associate II
Posted on July 25, 2017 at 10:07

I have absolutely the same problem. I have a bootloader and I'm using the usb to update the firmware, once it's ready it should restart and switch all interrupts to the new location where the application resides. However the usb is no longer working, and the communication failes. The user need to hard reset the whole device, after which the usb is reinitialized and the communication is reestablished. This is not very nice and professional so I'm really looking for a solution to the problem or at leas some kind of understanding what is going on and what causes the problem. Please contribute!

Posted on July 25, 2017 at 19:03

Hello!!

You wrote 'Turning off the USB'  How you turn off the USB?

Do you disconnect it from PC( by MCU soft) before you turn it off?

howard n2wx
Senior
Posted on July 25, 2017 at 21:23

Is there a hardwired pullup on the USB D+ line?  If manually removing and reinstalling it after the app restart fixes things then you'll need to switch the pullup in and out of the link with a GPIO pin

Posted on July 25, 2017 at 22:23

This is the point!!

You can use Soft disconnect feature

This can be done by HAL_PCD_DevConnect(..); or HAL_PCD_DevDisconnect(..)!

when not use HW pullup.!

Posted on July 26, 2017 at 16:18

Thank you very much for your contribution!

first there is no hardware pullup i.e. the stm32f gpio pull-up is used. Second I added DCD_DevDisconnect(&USB_OTG_dev);

DCD_DevConnect(&USB_OTG_dev);

after the USBD_Init function (I'm not using Cube). That however didn't solve the problem. Interestingly the device manager is able to find the device, but somehow I can't open a socket and connect to it as a serial port. I still need to plug it in and out manually.

Another intersting point to mention is that I can open a socket and communicate with the device after a reset from the RESET button of the stm32f0 disco, which I'm using as a debugger through the SWD.

I mean that the device manager is finding the device and mapping it to COM30, though the Hyper Terminal is not finding it in the COM port list even after a thousand time refreshment (See the attachment).

________________

Attachments :

2017-07-26 16_48_17-D__Old_Desktop_hterm.png : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HyTd&d=%2Fa%2F0X0000000b9U%2Fh81g6iwJE.qRXcip7kl9QUaeihyCDyHurEZY.ryKwKI&asPdf=false
Posted on July 26, 2017 at 18:34

Hello!!

For the second matter

go to hardware managment ,

right click to usbcom device

properties

goto the port properties or adjust tab (i have Greek windows)

click advanced button

change your port name from 30 to under  8   to be compatible with hyperterminal (try the realterm or terraterm)

I m in a hurry now ..

I will respond to the first part of issue  later.

regards

Posted on July 26, 2017 at 21:46

Hello again.

a typical procedure is

0690X00000603ycQAA.jpg

in case you don't disconnect (by software) the port before do some change, the pc suposes that usb is connected and with no activity.

After a reset , give some time (few millisecs .. try 10,20....) to MCU before make the USB initialisation .(preferably initialise it after all other peripherals.)

when the device is powered from bus introduce also some delay before try to initialise.

I use all theese methods  with no any kind of problem at all, I can press the reset like machinegun!!  with no any issue.

Some terminals have another issue.

When disconnect and reconnect USB device, stops working!!! (teraterm not!!) 

Posted on July 26, 2017 at 21:51

georgiev.zdravko wrote:

I mean that the device manager is finding the device and mapping it to COM30, though the Hyper Terminal is not finding it in the COM port list even after a thousand time refreshment (See the attachment).

Check out putty as a hyperterm replacement:

https://www.chiark.greenend.org.uk/~sgtatham/putty/

It can reach the funky COM port assignments

Posted on July 27, 2017 at 10:24

Vangelis,

thank you very much for your contribution. There are two things which I think are misunderstood. The first thing is that I can press the RESET like machingegun too, because the COM port is not available before the pressing of RESET, after that it's working. The next thing is that I'm switching from application to bootloader via a hyperterm software, where the hyperterm is sending a command to the stm32f105 and then smt32f105 is calling NVIC_SystemReset() to switch to the bootloader and that's it! No deinitializations, no disconect nothing. In the bootloader everything is again initialized and USB is DCD_DevConnect(...)-ed. The device manager blinks and refinds the device, though the hyperterm is not able to find the COM part, no matter if it's 1, 10, 20, 30, any number. After RESET it's working! It's working too if I plug out and then in the usb cable.