Where to get crash information/Serial REPL?

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.
Post Reply
User avatar
dvansteenwegen
Posts: 3
Joined: Mon Sep 28, 2020 8:56 am
Location: Ghent, Belgium JO11UB
Contact:

Where to get crash information/Serial REPL?

Post by dvansteenwegen » Tue Oct 27, 2020 12:45 pm

Hi,

I'm somewhat used to writing Python, but still make stupid mistakes from time to time (ok, not from time to time, rather often).
When writing for a pc you run the script and if there's an issue, you get the exception log printed to the sceen/STDOUT.

How do I get that in the PyBoard?
From https://docs.micropython.org/en/latest/ ... /repl.html (ESP8266 related) I found:
The REPL is always available on the UART0 serial peripheral, which is connected to the pins GPIO1 for TX and GPIO3 for RX. The baudrate of the REPL is 115200.
Does the PyBoard have some pins that work as something similar to STOUT/STDERR?

Where can I get information on what goes wrong if I upload a script that has issues?

I remember I read somewhere on this forum that someone made his "main" script as a separate module. He would call it from the REPL and only when he was finished, he would convert it to main.py. However, I wonder if there isn't a better way?

User avatar
jimmo
Posts: 2015
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Where to get crash information/Serial REPL?

Post by jimmo » Wed Oct 28, 2020 12:51 am

When your pyboard is plugged into your PC by USB, stdin/stdout is available over the virtual UART over the USB. On Linux you'll see this as /dev/ttyACM0, and on Windows you'll see a COM port (e.g. COM5). Look in device manager to see the list of COM ports. You can use a tool like PuTTY or miniterm to access the COM port.

You can also make the REPL available over a real UART (either as a build configuration or at runtime via dupterm), but doing it over the virtual USB port is easier.
dvansteenwegen wrote:
Tue Oct 27, 2020 12:45 pm
I remember I read somewhere on this forum that someone made his "main" script as a separate module. He would call it from the REPL and only when he was finished, he would convert it to main.py. However, I wonder if there isn't a better way?
I guess what you're describing could be achieved by removing main.py from the device, and renaming it to "app.py" or something, then at the REPL (available via the UART), you can write "import app" to run your program.

User avatar
dvansteenwegen
Posts: 3
Joined: Mon Sep 28, 2020 8:56 am
Location: Ghent, Belgium JO11UB
Contact:

Re: Where to get crash information/Serial REPL?

Post by dvansteenwegen » Wed Oct 28, 2020 8:38 am

I realize I can get a serial port over USB, but that doesn't really give me any output in case of a crash, does it?
I can get a REPL on it by pressing CTRL + C (I think, not sure of the exact combination atm), but then the main.py isn't running any more.
If I restart the board, the USB device needs to re-initialize, so the serial port gets closed. By the time I've reopened the serial port, my application has been running for ages (in the life of a python script, at least).

Any pointers on where I could find how to set up a dedicated output port on a uart?
[EDIT] a quick search for dupterm examples leads me to http://docs.micropython.org/en/v1.9.3/w ... /repl.html, that should do the trick. I'll try that first.

Thanks!

User avatar
dvansteenwegen
Posts: 3
Joined: Mon Sep 28, 2020 8:56 am
Location: Ghent, Belgium JO11UB
Contact:

Re: Where to get crash information/Serial REPL?

Post by dvansteenwegen » Wed Oct 28, 2020 9:16 am

For anyone trying the same/simiilar thing:


place the following in boot.py:

Code: Select all

import uos
import pyb
termrep = pyb.UART(3,38400)
uos.dupterm(termrep)
print('\n\r*** boot.py finished ***\n\r')
That last line can de omitted, of course.
The key was to import pyb as well. In the REPL I could get by without doing that import, but it seems to be required in the boot.py.

This effectively duplicates the output that you'd get on a terminal window when running your scripts on a PC.

Thanks a lot Jimmo!

Post Reply