cancel
Showing results for 
Search instead for 
Did you mean: 

Loop in USB_IRQHandler if unplugged

frederic23
Associate II
Posted on August 29, 2016 at 22:49

Hi,

I'm using the USB port in CDC with STM32F072 device. I'm using the F0 STM32Cube package version 1.5.0

At power up, if the device in not USB connected to a host, it goes in infinite loop in the USB_IRQHandler function and stall the main application execution: the LSOF ans ERR flag in the FNR register always pop-up. If I connect the device to host, the device is successfully detected and main application run as well. If I disconnect, no infinite loop in USB_IRQHandler function...

An idea to solve this problem?
6 REPLIES 6
sherman
Associate II
Posted on August 30, 2016 at 20:00

Hello Frederic,

Can you post the main.c and USB_IRQHandler() code?  Also, how are you verifying that it is stuck in the loop?

Walid FTITI_O
Senior II
Posted on September 01, 2016 at 11:38

Hi Frederic,

Try to share your main code  to see if you have missed in the software ?

Have you used CubeMx to generate your initialization code ? Have you upgraded your ST-Link firmware ?

Wich STM32F0 board you are using ? Is VBUS pin connected ? Is Vbus_sensing enabled ?

-Hannibal-
frederic23
Associate II
Posted on September 01, 2016 at 17:58

Hi all,

thanks for your replies. Yes I use files generated by CubeMX, I use a custom board and no dedicated Vbus pin is available on STM32F072 (I use it as a self-powered slave device)

 I give an update: Finally, the main issue is the STM32F072 always handling a ESOF and ERR flag interrupt if device is unplugged. I just disable (comment) the handling of theses flag in the ''HAL_PCD_Init'' init function and ''HAL_PCD_IRQHandler'' interrupt handler (in stm32f0xx_hal_pcd) because no callback management is done for these event. I should'nt modify an HAL layer file but this workaround solve this problem....

==> init:

  /*set wInterrupt_Mask global variable*/

  wInterrupt_Mask = USB_CNTR_CTRM |

                    USB_CNTR_WKUPM |

                    USB_CNTR_SUSPM |

                    //USB_CNTR_ERRM |     // This line commented solve problem of USB_IRQHandler loop if device in unplugged at bootup...

                    //USB_CNTR_ESOFM |    // Idem...

                    USB_CNTR_RESETM;

  /*Set interrupt mask*/

  hpcd->Instance->CNTR = wInterrupt_Mask;

==> handler:

if (__HAL_PCD_GET_FLAG (hpcd, USB_ISTR_WKUP))

{

    hpcd->Instance->CNTR &= ~(USB_CNTR_LPMODE);

    /*set wInterrupt_Mask global variable*/

    wInterrupt_Mask = USB_CNTR_CTRM |

                      USB_CNTR_WKUPM |

                      USB_CNTR_SUSPM |

                      //USB_CNTR_ERRM |     // This line commented solve problem of USB_IRQHandler loop if device in unplugged at bootup...

                      //USB_CNTR_ESOFM |    // Idem...

                      USB_CNTR_RESETM;

    /*Set interrupt mask*/

    hpcd->Instance->CNTR = wInterrupt_Mask;

    HAL_PCD_ResumeCallback(hpcd);

    __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_WKUP);

  }

Fred

Walid FTITI_O
Senior II
Posted on September 01, 2016 at 18:42

Hi Frederic,

I think that is related to a bug found on CubeMx recently. USB host power switch was wrongly active low by CubeMx instead to be active high. It is already reported in this [DEAD LINK /public/STe2ecommunities/mcu/Lists/STM32Java/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/STM32Java/CubeMX%20bug%20USB%20devices%20wrongly%20enable%20host%20power%20switch%20on%20Discovery%20boards&FolderCTID&currentviews=74]thread.

So try to upgared the CubeMx tool to the last version 4.16.1 which work with the last STM32CubeF0 version V1.6.0. It should be fixed there.

-Hannibal-

frederic23
Associate II
Posted on September 01, 2016 at 22:17

Ok, I upgrade CubeMX and give you a feedback soon.

Fred
prueba2
Associate II
Posted on December 01, 2016 at 21:54

Hi Frederic.

Thanks for your comments. It's works perfect!

I'm using STM32F070CB.

Thanks !!