Serial echo hangs? I must be crazy...

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
User avatar
dbc
Posts: 78
Joined: Fri Aug 28, 2015 11:02 pm
Location: Sunnyvale, CA

Serial echo hangs? I must be crazy...

Postby dbc » Sun Jul 16, 2017 5:55 pm

I'm experience strange hangs with Pyboard v1.1 running

Code: Select all

>>> sys.implementation
(name='micropython', version=(1, 9, 1))


I'm working on a robot with a RasPi3 for ROS/Linux and a PyBoard for the hard realtime. I'm using serial to connect the two. Now first off the RasPi3 serial port is well known to be sub-standard, and I've stolen the Bluetooth UART from the RasPi to reroute it to the I/O header pins as that is supposed to be a better UART, at least it has a deeper buffer. In any case, that is one of the UART's that I'm using as the PyBoard's peer. I've also tried with an FTDI serial USB cable.

I've written a little loopback code shown below, just to see if I can get data from the RasPi to the PyBoard and back again without corruption. Strangely, the PyBoard seems to occasionally go out to lunch, drop off the USB console connection and block storage mount point, and require a hard reset. The symptoms are exactly that of some kind of lock race in the PyBoards serial driver allowing a buffer overflow to scribble everywhere in SRAM, at least that is where my suspicion would turn first. On the other hand, the PyBoard serial driver is very old, very well-exercised functionality, so I would expect it to be very robust by now. Anyway, my code is below. Am I missing something obvious? The code should just be a software implementation of a piece of wire....

Code: Select all

from pyb import UART

def run(s=115200):
    uart = UART(1, s)
    while True:
        ch = uart.readchar()
        if ch < 0:
            continue
        uart.writechar(ch)

User avatar
pythoncoder
Posts: 1635
Joined: Fri Jul 18, 2014 8:01 am

Re: Serial echo hangs? I must be crazy...

Postby pythoncoder » Mon Jul 17, 2017 7:59 am

Well ch < 0 occurs on timeout. What is the default timeout? I'd try

Code: Select all

def run(s=115200):
    uart = UART(1, s)
    while True:
        if uart.any():
            ch = uart.readchar()
            uart.writechar(ch)


Which is not to excuse a crash...
Peter Hinch

User avatar
dbc
Posts: 78
Joined: Fri Aug 28, 2015 11:02 pm
Location: Sunnyvale, CA

Re: Serial echo hangs? I must be crazy...

Postby dbc » Mon Jul 17, 2017 4:19 pm

Yes, that's a cleaner way to code it. I'll make the excuse that I was in a hurry to get quick and dirty diagnostics going. The code on the other side when I was seeing crashes is somewhat suspect, and I've redone that now but only have it working with an FTDI cable with hard-wired loopback. Next step is to replace the jumper wire jammed into the FTDI cable with the PyBoard software loopback.

The PyBoard crash still smells suspicious, though. If I can replicate the crash with my new host-side diagnostic then I'll have more faith in the symptom. Then it would be an interesting test to try both the time-out version and the uart.any() version of the software loopback to see if it makes a difference. Maybe the time-out has a lock race. But until I test with my new host-side driver I'm going to hold off on blaming the PyBoard too much.


Return to “The MicroPython pyboard”

Who is online

Users browsing this forum: No registered users and 1 guest