USB CDC sending data while closed

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

USB CDC sending data while closed

Jump to solution
1,068 Views
Therry
Contributor II

Hello,

I'm new to developing with USB. I new using the LPCXpresso55S28 Board and with the help of the SDK (version 2.13.0) i manage to get USB CDC working. I have only one question.

Our applications pushes data over the USB. When the serial port is closed (not disconnected) the data is buffer en when the port is opened again old data is received and then the new data. For example:

Msg1
Msg2
Msg3
- port closed
wait some time
- port opened
Msg4 <- buffer message i don't want
Msg10
Msg11
Msg12

I was wondering if it is possible to either detect if a port is closed so the MCU application can stop sending without the use of hardware flow control. Or clear the buffered message when the port is opened again.

With kind regards,
Therry

Tags (3)
0 Kudos
1 Solution
838 Views
Therry
Contributor II

For future reference:

I solved my case. What I did is adding a timeout when writing to the USB “USB_DeviceCdcAcmSend()”. This timeout was canceled when the event “kUSB_DeviceCdcEventSendResponse” happens and no data needs to be send.

If the timeout was triggered the function “USB_DeviceCancel()”is called to remove the data from the buffer.

View solution in original post

0 Kudos
5 Replies
839 Views
Therry
Contributor II

For future reference:

I solved my case. What I did is adding a timeout when writing to the USB “USB_DeviceCdcAcmSend()”. This timeout was canceled when the event “kUSB_DeviceCdcEventSendResponse” happens and no data needs to be send.

If the timeout was triggered the function “USB_DeviceCancel()”is called to remove the data from the buffer.

0 Kudos
1,037 Views
CarlosGarabito
NXP TechSupport
NXP TechSupport

Hello @Therry , in the SDK there are several examples with the use of the USB CDC and the send msg, it is only a matter of reading the README documents to understand the project, on the other hand, you can find more information in the community on this topic, it is only a question of interpreting it for your project and the MCU you have, I leave some links that may be useful for you.

 

 

https://community.nxp.com/t5/LPCware-Archive-Content/LPC-USB-Serial-I-O-Library/ta-p/1129296

 

https://community.nxp.com/t5/Kinetis-Microcontrollers/How-to-detect-if-USB-connected/m-p/626039

 

https://community.nxp.com/t5/i-MX-RT/imx-rt1061-USB-device-connection-detect/m-p/1330851

 

https://community.nxp.com/t5/i-MX-RT/What-is-the-best-way-to-detect-attaching-and-detaching-of-an-us...

 

https://community.nxp.com/t5/MCUXpresso-SDK/USB-HID-Gereric-buffer-issue/m-p/811496

 

Have a good day

0 Kudos
1,009 Views
Therry
Contributor II

Dear @CarlosGarabito ,

Thank you for your reply.

I checked the information you send but couldn't find a a solution for my problem. The problems you provided are about physical disconnecting the USB. I'm looking for a detection of a logical connection (opening and closing the COM port)

With kind regards,
Therry Angenent

0 Kudos
986 Views
CarlosGarabito
NXP TechSupport
NXP TechSupport

Hi @Therry well, we don't have any examples of such programs in our SDK, an apology.

0 Kudos
975 Views
Therry
Contributor II

Dear @CarlosGarabito , Is there a way to clear the send buffer when the COM port is logically opened? For example when the event kUSB_DeviceCdcEventSetLineCoding is received.

0 Kudos