2016-08-29 01:49 PM
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?2016-08-30 11:00 AM
Hello Frederic,
Can you post the main.c and USB_IRQHandler() code? Also, how are you verifying that it is stuck in the loop?2016-09-01 02:38 AM
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-2016-09-01 08:58 AM
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); } Fred2016-09-01 09:42 AM
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¤tviews=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-2016-09-01 01:17 PM
Ok, I upgrade CubeMX and give you a feedback soon.
Fred2016-12-01 12:54 PM
Hi Frederic.
Thanks for your comments. It's works perfect!I'm using STM32F070CB.Thanks !!