3

I am using Virtual COM Port (VCP) example code from http://blog.memsme.com/stm32f4-virtual-com-port-2/ on STM32F4 Discovery Board to have USB VCP. This code is originally by ST and used by many other people in their projects

Communication with the STM32F4 over VCP works fine from Windows. In Linux (Ubuntu 12.04 x86), if I send data to the port with

echo "aasfg" > /dev/ttyACM0

then, the MCU gets the data and everything works fine. I can receive the continuous data stream with

cat /dev/ttyACM0

However, if I send data with the simple Python script that uses pySerial

import serial
sercom = serial.Serial('/dev/ttyACM0')
sercom.write('asdf')

then I stop receiving data with the cat command, and following cat commands also don't receive any data. The MCU is constantly executing some USB interrupt routines, never returning to execute actual application code. I can receive data from VCP again after re-plugging the device.

The STM32 USB VCP code is probably not perfect, but it is used by many other people in many projects so it should be good enough. I am not able to debug that code. I suspect that sending data with pySerial does something with the port that the VCP driver (either on STM32 or PC) does not like and I would like to track it down and hopefully still use pySerial.

I executed

stty --file=/dev/ttyACM0 -a

before and after pyserial broke the communication. After breaking the VCP with pyserial, setting -clocal became clocal and setting min = 1 became min = 0. Are these relevant in VCP communication and could they hint how to fix VCP with pySerial?

user199309
  • 187
  • 1
  • 10
  • It could because you are not explicitly closing the serial port at the end of you python script. `sercom.close()`. If you don't close it could still look like the port is busy. – jramirez Oct 24 '13 at 20:38

1 Answers1

1

The serial port was actually fine. As I mentioned, the pySerial call changed the port parameters. The param min = 0 meant that cat /dev/ttyACM0 returned immediately, reconfiguring to min = 1 with stty made cat blocking and outputted the data as before.

user199309
  • 187
  • 1
  • 10