This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

PySerial write times out when communicating with USB CDC ACM

Hi,

I'm trying to integrate the USB CDC ACM example into a project that I'm currently running on an NRF52840 DK with SDK 16.0. My PC is running windows 10 and python 3.7


I want this project to be able to send and receive binary data to/from a PC. The basic functionality is:

  • PC sends command to start streaming data over USB
  • NRF52840 streams data to PC
  • PC sends command to stop streaming data over USB
  • NRF52840 stops streaming data to PC


So far I have the NRF52840 receiving data from the PC sent using real term

I can send as many commands as I would like and the NRF52840 receives them. I see debug output like this:

00> APP_USBD_CDC_ACM_USER_EVT_PORT_OPEN
00> Bytes waiting: 8
00> RX: size: 1char: 32
00> RX: size: 1char: 01
00> RX: size: 1char: 00
00> RX: size: 1char: 03
00> RX: size: 1char: 55
00> RX: size: 1char: FF
00> RX: size: 1char: 00
00> RX: size: 1char: 7C
00> RX: size: 1char: AD
00> RX done
00> Bytes waiting: 8
00> RX: size: 1char: 32
00> RX: size: 1char: 01
00> RX: size: 1char: 00
00> RX: size: 1char: 03
00> RX: size: 1char: 55
00> RX: size: 1char: FF
00> RX: size: 1char: 00
00> RX: size: 1char: 7C
00> RX: size: 1char: AD
00> RX done
00> APP_USBD_CDC_ACM_USER_EVT_PORT_CLOSE

The issue comes when trying to send data using a python script that is running PySerial. Previously this script has been used with a USB-Serial converter to achieve the same functionality. Unfortunately the NRF52840 seems to only sometime receive the start streaming command and the write for the stop streaming command always times out (5 second timeout).

My trace looks something like this when using the python script (this is showing 2 attempts)

00> APP_USBD_CDC_ACM_USER_EVT_PORT_OPEN
00> APP_USBD_CDC_ACM_USER_EVT_PORT_CLOSE
00> APP_USBD_CDC_ACM_USER_EVT_PORT_OPEN
00> Bytes waiting: 8
00> RX: size: 1char: 32
00> RX: size: 1char: 01
00> RX: size: 1char: 00
00> RX: size: 1char: 03
00> RX: size: 1char: 55
00> RX: size: 1char: FF
00> RX: size: 1char: 00
00> RX: size: 1char: 7C
00> RX: size: 1char: AD
00> RX done
00> APP_USBD_CDC_ACM_USER_EVT_PORT_CLOSE

you can see the first time that the port closes straight away and the second time I manage to get the start command through before the port closes. I am not seeing any exceptions on the python script (except for the timeout)

I see the same write timeout if I use my script to send data to the USB CDC ACM example too (but i can't see trace statements because I can't get the logging to work over serial or RTT)

What could be causing this?

Parents Reply Children
No Data
Related