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
Posted on August 03, 2017 at 13:33

Hello again .

With this fuction you can check if your device is connected and configured. I hope to helps you to find a solution.

// ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯

char USB_FS_DeviceIsConfigured()

{

if(hUsbDeviceFS.dev_state == USBD_STATE_CONFIGURED)

return 1;

else

return 0;

}

// ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯ ♯
MDS
Associate III
Posted on August 03, 2017 at 13:43

I just noticed that you said 'After then USBD_Init I'm just saying...'. USBD_Init connects the pull-up and should start enumeration. Calling USBD_Init when the USB is connected will not do much for you. It is not good the disconnect again and then reconnect right away without enough delay.

Try USBD_Deinit wait at least 500 to 1000 ms and then call USBD_Init. This should bring up the USB like unplugging the plugging the cable. This must be done after the host closes the interface. In my code, I use the interrupt pipe to drop my control lines to the host and then wait up to 5 seconds for the host to drop its control lines. Windows will do this, but Linux may not, that is why I wait up to 5 seconds. With Windows, when my code sees the host drop its control lines, the port is closed and I start my re-enumeration procedure.

Posted on September 27, 2017 at 21:36

Therefore the question is how to make the windows cycle power the USB or issue USB bus reset, and can this be done from the stm32f105 side?

My new solution is to reset the USB OTG FS by

RCC_AHBPeriphResetCmd(RCC_AHBPeriph_OTG_FS,

ENABLE

);

RCC_AHBPeriphResetCmd(RCC_AHBPeriph_OTG_FS,

DISABLE

);

Then it is possible to reset the USB

by pulling USBDP low shortly. (A pullup resistor is needed for this to work, most boards have it.)

GPIO_InitTypeDef

GPIO_InitStructure;

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,

ENABLE

);

GPIO_InitStructure.

GPIO_Pin

= GPIO_Pin_12;

GPIO_InitStructure.

GPIO_Mode

=

GPIO_Mode_Out_OD

;

GPIO_InitStructure.

GPIO_Speed

=

GPIO_Speed_2MHz

;

GPIO_Init(GPIOA, &GPIO_InitStructure);

GPIO_WriteBit(GPIOA, GPIO_Pin_12,

Bit_RESET

);

delay_ms(15);

Then I initialize the USB OTG FS again and use it.

Works well on my STM32F105.