cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103 USB Virtual COM Port usb unplug lock issue

justinwoolich
Associate III
Posted on March 08, 2014 at 15:51

Hi, I have a fairly standard implementation of the Virtual COM Port for the STM32F103. All i have implemented currently is the VCP code and an LED flashing in the main loop.

The board can be powered by either USB or External Power supply.

Everything works fine when powered by USB, i.e. VCP works and LED flashes in main routine. When i pull the USB cable while also powering the board by the external power supply the STM32 seems to lock up and the LED stops flashing (stays solid). As soon as i plug the USB back in the LED begins flashing again?!?!

Has anyone come across anything like this before? I really need the STM32 to continue to function as normal when powered by the external power supply with the USB either plugged in or not plugged in.

#usb-virtual-com-port
7 REPLIES 7
zzdz2
Associate II
Posted on March 08, 2014 at 21:22

Maybe some noise on usb data line, you can try to disable suspend and wakeup irqs.

It may help or not.

justinwoolich
Associate III
Posted on March 09, 2014 at 01:39

The STM32 locks up when the USB cable is unplugged so i dont think it would be noise on the USB lines?

tsuneo
Senior
Posted on March 09, 2014 at 14:58

While the device is plugged off, it goes to Suspend.

Are you working on STSW-STM32121 (STM32_USB-FS-Device_Lib_V4.0.0)? As the default behavior, this device stack drops the entire system into STOP mode, while USB is suspending. This feature is fine for bus-powered devices, to satisfy the suspend current requirement (less than 2.5mA) of the USB spec. But for self-powered devices, like your case, this feature is not always preferred. You may disable suspend/resume detection by dropping CNTR_SUSPM and CNTR_ESOFM from IMR_MSK() definition in usb_conf.h

STM32_USB-FS-Device_Lib_V4.0.0/Projects/Virtual_COM_Port/inc/usb_conf.h
/* IMR_MSK */
/* mask defining which events has to be handled */
/* by the device application software */
// #define IMR_MSK (CNTR_CTRM | CNTR_WKUPM | CNTR_SUSPM | CNTR_ERRM | CNTR_SOFM \
// | CNTR_ESOFM | CNTR_RESETM )
// Disable Suspend/Resume response completely
#define IMR_MSK (CNTR_CTRM | CNTR_WKUPM | CNTR_ERRM | CNTR_SOFM | CNTR_RESETM )

OR If you would still need suspend/resume detection, but you don't like STOP mode, modify Suspend() code in usb_pwr.c, so that it doesn't drop in to STOP mode

STM32_USB-FS-Device_Lib_V4.0.0/Projects/Virtual_COM_Port/src/usb_pwr.c
void Suspend(void)
{
...
// delete the code after this line
/*prepare entry in low power mode (STOP mode)*/
/* Select the regulator state in STOP mode*/
 ... 
}

Tsuneo
justinwoolich
Associate III
Posted on March 09, 2014 at 15:47

Hi thanks for your reply, yes i am using STM32_USB-FS-Device_Lib_V4.0.0 and what you say makes a lot of sense as it is very much like the device goes to sleep and resumes exactly where it was once the usb cable is plugged back in, i will test out the modification tomorrow and report back.

thanks!

1605mystery
Associate II
Posted on April 11, 2014 at 09:20

Hi,

Am also trying to port VCP project available with STM32_USB-FS-Device_Lib_V4.0.0 on STM32103XC.

Disabling Suspend / Resume works fine and helped in making USB to get into attached state for controller.

But after that it's not going to CONFIGURED STATE.

 

Did you face same issue after changing code as above?

What can be the possible issue for device not getting configured and getting detected on host pc.

Regards,

 

Omji Mishra

1605mystery
Associate II
Posted on April 14, 2014 at 08:30

Waiting for reply.

Can you guys plz reply

Amel NASRI
ST Employee
Posted on April 15, 2014 at 17:34

Same topic in

https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Virtual%20Com%20Port%20for%20STM32F103XC

.

-Mayla-

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.