cancel
Showing results for 
Search instead for 
Did you mean: 

VCP - closing COM port causes MCU enter the interrupt loop

konoppo
Associate II
Posted on August 09, 2012 at 15:40

Hi!

   I've got another problem with my STM32F207ZE and the USB VCP. My application (on STM) is running and LEDs are blinking :). It send by USB (VCP) to PC some text. When I close port in terminal on the PC the program continue to works, but after few minutes it enter an ''ISR loop''. It sequentially enters OTG_HS_EP1_IN_IRQHandler(). Program goes to USBD_OTG_EP1IN_ISR_Handler() than calls 

DCD_WriteEmptyTxFifo(pdev, 1); 

CLEAR_IN_EP_INTR(1, emptyintr);

After exit from ISR it enter it again, and again, and again... my application looks like halted. When I connect again my COM port on the PC - the application continues to work. 

What can I do with it? How to detect, that port is ''closed'' and not to send the data to it? Any idea? I'm sure that i'm not the first who have this problem. The application is USB-OTG-Example's based. 

Best regards

Konoppo

#stm32-vcp-usb
4 REPLIES 4
Posted on August 09, 2012 at 17:37

Any idea? I'm sure that i'm not the first who have this problem. The application is USB-OTG-Example's based.

 

They are just examples, often simplified ones and with sharp corners. You will no doubt have to invest some time and effort to understand and debug them to get to a commercial grade solution.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
konoppo
Associate II
Posted on August 10, 2012 at 09:12

Hi

Thanks for reply. I know, that the are only examples and I want to modify them, but I believe I can use it as a base. My problem is that I have no idea how to detect the disconnection of the port. I tried to find any relation but I can't. I don't want to get a ready-to-use source code, but only a brilliant idea how to simply and reliably detect such a situation. 

Best regards

Konoppo

Posted on August 10, 2012 at 15:47

I'm not sure if it is even appropriate for a USB device to be trying to understand if a COMx port is opened/closed by an application.

My general experience with COM ports is that if you're not actively reading data (ReadFile) then the data is lost, and is not accumulated in an ever expanding buffer. I think you just need to have a finite buffer, and lose old data as it overflows. And recognize when that situation occurs.

I guess if you want to see how other devices do this you could get a SiLab or Prolific USB-to-Serial adapter and review with a bus analyzer.

You could also instrument the STM32's USB code and output diagnostic or telemetry from a physical serial port to a terminal.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
tyronexj
Associate II
Posted on March 21, 2013 at 13:50

Hi Konoppo,

I met with the same problem.

I close port or disconnect the usb line while the device is sending data. Then it died in USBD_OTG_EP1IN_ISR_Handler(); DCD_WriteEmptyTxFifo(pdev, 1); 

CLEAR_IN_EP_INTR(1, emptyintr);

Have you found the solution to this problem?

Thanks in advance!

Regards,

Tyrone