I am designing an IoT project with RF transceiver and OpenWRT. The RF transceiver has onboard STM32 micro, and it can be access in Windows as 'COMx'. I plan to use serial and socket module in Python to build a quick solution. But the device doesn't go well in Linux anyway.
The test code is very simple.
#!/usr/bin/env python
import serial
#ser = serial.Serial('COM12',9600,timeout=0.3)
ser = serial.Serial('/dev/ttyACM0',9600,timeout=0.3)
while True:
l = ser.readline()
print(l)
I tested the code in Windows, Ubuntu, Raspiberry-Pi, and OpenWRT. It works fine in Windows. However in Linux, the readline() only prints one leading character, and the rest readline() calls get None returned.
Here is my hardware configuration summary: In OpenWRT, the Python is 2.7.3, pyserial is 2.4. and My CDC/ACM code are from ST's STM32F103/F072 HAL SDK. You can find the reference code from mbed
After Python, I tried lua's io.open, and shell programming for serial with cat/echo commands. I am pretty sure that my device (mbed CDC) doesn't run well in Linux.
I also tested MicroPython (based upon STM32F4XX HAL), built-in CDC in STLINKV2 (STM32F103) and Keil RTX USB CDC demo (STM32F103). The first two works well in Windows/Linux, Keil doesn't.
Currently I am trying to usbmon to debug and find root cause, since USB stack is quite complex and firmware is hard to debug in real-time, I need some experienced in such cross-domain development.
Here is my usbmon log:
f3e3f9c0 857391360 S Ii:1:004:1 -115:2 16 <
f3f2e180 857391559 S Co:1:004:0 s 21 22 0003 0000 0000 0
f3f2e180 857414072 C Co:1:004:0 0 0
f3e3fa80 857414467 S Bi:1:004:2 -115 128 <
f3e3fb40 857414547 S Bi:1:004:2 -115 128 <
f3e3ff00 857414595 S Bi:1:004:2 -115 128 <
f3e3fe40 857414636 S Bi:1:004:2 -115 128 <
f3e3f900 857414676 S Bi:1:004:2 -115 128 <
f3e3f780 857414716 S Bi:1:004:2 -115 128 <
f3e3f6c0 857417325 S Bi:1:004:2 -115 128 <
f3e3f600 857417399 S Bi:1:004:2 -115 128 <
f3e3fc00 857417435 S Bi:1:004:2 -115 128 <
f3e3fcc0 857417469 S Bi:1:004:2 -115 128 <
f3e3f540 857417502 S Bi:1:004:2 -115 128 <
f3e3f480 857417533 S Bi:1:004:2 -115 128 <
f3e3f3c0 857417565 S Bi:1:004:2 -115 128 <
f3e3f300 857417594 S Bi:1:004:2 -115 128 <
f3e3f240 857417622 S Bi:1:004:2 -115 128 <
f3e3f180 857417650 S Bi:1:004:2 -115 128 <
f3e3f9c0 1138689644 S Ii:1:004:1 -115:2 16 <
f51fd6c0 1138692116 S Co:1:004:0 s 21 22 0003 0000 0000 0
f51fd6c0 1138703025 C Co:1:004:0 0 0
f3e3fa80 1138703444 S Bi:1:004:2 -115 128 <
f3e3fb40 1138703524 S Bi:1:004:2 -115 128 <
f3e3ff00 1138703570 S Bi:1:004:2 -115 128 <
f3e3fe40 1138703610 S Bi:1:004:2 -115 128 <
f3e3f900 1138703652 S Bi:1:004:2 -115 128 <
f3e3f780 1138703692 S Bi:1:004:2 -115 128 <
f3e3f6c0 1138703817 S Bi:1:004:2 -115 128 <
f3e3f600 1138703865 S Bi:1:004:2 -115 128 <
f3e3fc00 1138703906 S Bi:1:004:2 -115 128 <
f3e3fcc0 1138703947 S Bi:1:004:2 -115 128 <
f3e3f540 1138703987 S Bi:1:004:2 -115 128 <
f3e3f480 1138704026 S Bi:1:004:2 -115 128 <
f3e3f3c0 1138704066 S Bi:1:004:2 -115 128 <
f3e3f300 1138704106 S Bi:1:004:2 -115 128 <
f3e3f240 1138704147 S Bi:1:004:2 -115 128 <
f3e3f180 1138704188 S Bi:1:004:2 -115 128 <
f6c65840 1138704450 S Bo:1:004:2 -115 13 = 48656c6c 6f20776f 726c640d 0a
f6c65cc0 1138704878 S Bo:1:004:2 -115 13 = 48656c6c 6f20776f 726c640d 0a
f6c65d80 1138704970 S Bo:1:004:2 -115 13 = 48656c6c 6f20776f 726c640d 0a
f6c65600 1138705045 S Bo:1:004:2 -115 13 = 48656c6c 6f20776f 726c640d 0a
f6c65240 1138705117 S Bo:1:004:2 -115 13 = 48656c6c 6f20776f 726c640d 0a
f6c65000 1138705189 S Bo:1:004:2 -115 13 = 48656c6c 6f20776f 726c640d 0a
f6c659c0 1138705261 S Bo:1:004:2 -115 13 = 48656c6c 6f20776f 726c640d 0a
f6c65b40 1138705333 S Bo:1:004:2 -115 13 = 48656c6c 6f20776f 726c640d 0a
f6c656c0 1138705459 S Bo:1:004:2 -115 13 = 48656c6c 6f20776f 726c640d 0a
f6c65300 1138705515 S Bo:1:004:2 -115 13 = 48656c6c 6f20776f 726c640d 0a
f6c65f00 1138705559 S Bo:1:004:2 -115 13 = 48656c6c 6f20776f 726c640d 0a
f6c65900 1138705603 S Bo:1:004:2 -115 13 = 48656c6c 6f20776f 726c640d 0a
f6c65780 1138705646 S Bo:1:004:2 -115 13 = 48656c6c 6f20776f 726c640d 0a
Above logging is made up of two sessions, one for reading only, the latter one is for writing "Hello World\r\n" only. It seems no output from USB for bulkin.
Update for More OS
After receiving message from author of the STM32F103C8T6_USBSerial, I tried some latest Linux disto, including Ubuntu 15.04 desktop. The firmware works well with gtkterm and stty/cat/echo and other tools. Now, the problem comes complex in a matrix:
- STM32F103C8T6_USBSerial works in Ubuntu 15.04 desktop, failed in Ubuntu 12.04/14.04 desktop and OpenWRT.
- Other firmware works in almost all Linux disto.
Now, it is a compatibility problem. The firmware works for latest OS, failed in elder versions. Now I have to focus on how to locate the root cause.