REPL Pyboard over serial not USB

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
tsjoiner
Posts: 22
Joined: Tue Sep 05, 2017 3:09 pm
Location: Alberta Beach, Alberta, Canada

REPL Pyboard over serial not USB

Post by tsjoiner » Tue Oct 24, 2017 3:08 pm

I'm working on a project that requires I communicate with my Pyboard over a serial port (tx, rx) not the built in USB.
I hope to have access to REPL, rshell functionality and perhaps DFU-util. I have had success with an ESP32-dev_board because it has tx and rx pins exposed behind usb-serial chip. Looking at the schematic for Pyboard all the USB stuff is handled by the MCU. Please tell me this can be done as I need good quality Pyboard hardware for this project.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: REPL Pyboard over serial not USB

Post by Roberthh » Tue Oct 24, 2017 4:00 pm

That's possible. Look in the manual for uos.dupterm().http://docs.micropython.org/en/latest/p ... os.dupterm

User avatar
tsjoiner
Posts: 22
Joined: Tue Sep 05, 2017 3:09 pm
Location: Alberta Beach, Alberta, Canada

Re: REPL Pyboard over serial not USB

Post by tsjoiner » Fri Oct 27, 2017 1:22 am

Many thanks to Roberthh for some direction here. I put this code in my boot.py and rebooted - instant results.

Code: Select all

import pyb
import uos
from pyb import UART

uart = UART(6)
uart.init(baudrate=115200, bits=8, parity=None, stop=1)
uos.dupterm(uart)
This may be crude but I'm pleased the Pyboard USB connection is now duplicated on UART 6.
Enter REPL from Raspberry Pi over serial adapter in picocom:

Code: Select all

$ picocom -b115200 /dev/ttyUSB0
Enter
>>>

User avatar
tsjoiner
Posts: 22
Joined: Tue Sep 05, 2017 3:09 pm
Location: Alberta Beach, Alberta, Canada

Re: REPL Pyboard over serial not USB

Post by tsjoiner » Sat Oct 28, 2017 12:32 am

Ran in to a small snag. It seems REPL can't break out of a while loop using ctrl-c. REPL is not responding to keyboard interrupt. Is this something to do with sys.stdin perhaps? What if anything can be done to remedy this?

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: REPL Pyboard over serial not USB

Post by pythoncoder » Sat Oct 28, 2017 5:27 am

Might this issue be with picocom? I've used rshell with several targets over a serial interface and not encountered this.
Peter Hinch
Index to my micropython libraries.

User avatar
tsjoiner
Posts: 22
Joined: Tue Sep 05, 2017 3:09 pm
Location: Alberta Beach, Alberta, Canada

Re: REPL Pyboard over serial not USB

Post by tsjoiner » Sun Oct 29, 2017 11:20 pm

Thank you pythoncoder, the issue does not seem to be with picocom. I tested rshell and it connects to the pyboard over serial no problem I can enter REPL and ctrl-x out of REPL. Ctrl-a, ctrl-b, ctrl-d and ctrl-e work as expected in REPL but ctrl-c will not break or interrupt a running loop. Also, I have attached an LED indicator to the UART rx pin and see it flash on keyboard strokes including ctrl-c. The message appears to arrive at the rx pin but is ignored somehow. Perhaps I have initiated the UART incorrectly.

Pyboard: MicroPython v1.9.2 on 2017-08-23; PYBLITEv1.0 with STM32F411RE.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: REPL Pyboard over serial not USB

Post by Roberthh » Mon Oct 30, 2017 7:24 am

This is just to confirm the issue, that Ctrl-C on dupterm does not interrupt code. A first glance into the code shows, that, in contrast to USB, Ctrl-C for UART is indeed not handled by the interrupt routine, but only when getting characters form the buffer.
This is an open issue since two years: https://github.com/micropython/micropython/issues/1568

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: REPL Pyboard over serial not USB

Post by pythoncoder » Mon Oct 30, 2017 8:25 am

Ah, apologies - this issue is specific to dupterm. My testing was on devices where the interface is serial only rather than USB.
Peter Hinch
Index to my micropython libraries.

User avatar
tsjoiner
Posts: 22
Joined: Tue Sep 05, 2017 3:09 pm
Location: Alberta Beach, Alberta, Canada

Re: REPL Pyboard over serial not USB

Post by tsjoiner » Mon Oct 30, 2017 8:55 pm

Thank you both. The apollogies are all mine to make because RT*M. Issue #1568 describes the same problem :oops:

EasyRider
Posts: 94
Joined: Wed Dec 30, 2015 8:17 am

Re: REPL Pyboard over serial not USB

Post by EasyRider » Sat Apr 07, 2018 10:08 am

Bumping this thread.

Looking for solution to Pyboard Repl over UART, where Ctrl-C break doesn't work.
Been a recognized problem for a long time.
https://github.com/micropython/micropython/issues/1568

Need to have REPL access to remote pyboards via wireless minicom UART terminal, have this working but without CTRL-C program break.

Is there a non blocking equivalent of scanning for keyboard key-press?
sys.stdin.read(1), this is blocking waiting for keypress

Post Reply