USB CDC sending data while closed

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

USB CDC sending data while closed

跳至解决方案
2,621 次查看
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

标记 (3)
0 项奖励
回复
1 解答
2,391 次查看
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 项奖励
回复
5 回复数
2,392 次查看
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 项奖励
回复
2,590 次查看
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 项奖励
回复
2,562 次查看
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 项奖励
回复
2,539 次查看
CarlosGarabito
NXP TechSupport
NXP TechSupport

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

0 项奖励
回复
2,528 次查看
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 项奖励
回复