Disabling REPL over USB only

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
doublevee
Posts: 38
Joined: Mon Jul 02, 2018 11:09 pm

Disabling REPL over USB only

Post by doublevee » Wed Feb 26, 2020 1:13 pm

I am using my Pyboard Lite in USB VCP mode so that it can talk to a controller I am building using a RPi.

As I have serial data/commands/ACKs etc running over the USB serial link, I would like to disable the REPL as it can interfere during development. I have set up UART 6 and have the REPL duplicated onto this, but I am struggling to understand how the os.dupterm() function works.

I have issued os.dupterm(None,1) and it would appear to stop the REPL on VCP but I think it also disabled the REPL on UART 6.

Is it possible to have the REPL on just a UART connection and not the USB?

This would leave the VCP for just serial comms and all REPL and debug/print statements etc would be directed to the configured UART to assist with debugging and development.

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

Re: Disabling REPL over USB only

Post by jimmo » Wed Feb 26, 2020 2:05 pm

doublevee wrote:
Wed Feb 26, 2020 1:13 pm
I have set up UART 6 and have the REPL duplicated onto this,
Can you post the code that you used to do this?

You can either do this in Python via dupterm etc, or possibly simpler, in mpconfigboard.h:

Code: Select all

#define MICROPY_HW_UART_REPL        PYB_UART_6
#define MICROPY_HW_UART_REPL_BAUD   115200
The pyboard doesn't do this by default, but look at any of the boards that don't support USB for examples.
doublevee wrote:
Wed Feb 26, 2020 1:13 pm
understand how the os.dupterm() function works.
The idea is that there are three dupterm "slots", and the terminal (i.e. the repl, but also stdio) is duplicated to all these slots.

At startup, if USB CDC is enabled, the VCP uses slot 1. Which is why os.dupterm(None, 1) disables the VCP.

Which slot were you using for the UART? (Note that the mpconfigboard.h approach described above doesn't use dupterm, it's kind of an extra "always connected" slot).

doublevee
Posts: 38
Joined: Mon Jul 02, 2018 11:09 pm

Re: Disabling REPL over USB only

Post by doublevee » Thu Feb 27, 2020 6:52 am

Hi Jimmo - thanks for your reply.

I am using very simple code to setup the REPL in my boot.py :

Code: Select all

import pyb
import os

pyb.country('US') # ISO 3166-1 Alpha-2 code, eg US, GB, DE, AU
pyb.usb_mode('VCP') # act as a serial com port
os.dupterm(pyb.UART(6,9600))
I have then used the following to disable REPL on USB:

Code: Select all

os.dupterm(None,1)
When you say that that this commands disables the VCP, do you mean REPL on VCP or it disables the whole VCP function?

I would like REPL only on UART 6 but able to use VCP via USB.

I'm afraid I do not know where mpconfigboard.h is or how it's used? Do you have a link to any documentation I can read please?

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

Re: Disabling REPL over USB only

Post by jimmo » Thu Feb 27, 2020 1:00 pm

doublevee wrote:
Thu Feb 27, 2020 6:52 am
When you say that that this commands disables the VCP, do you mean REPL on VCP or it disables the whole VCP function?
The former. You can still use the VCP via the pyb.USB_VCP class.
doublevee wrote:
Thu Feb 27, 2020 6:52 am
I would like REPL only on UART 6 but able to use VCP via USB.
I just tested this setup -- I have a PYBV11 (should be the same as your PYBLITE) with an FTDI connected to UART 6.

I connected to ttyACM0 (i.e. the VCP UART) from my PC and did this at the REPL:

Code: Select all

os.dupterm(pyb.UART(6,9600), 0)
which immediately made the REPL appear on ttyUSB0 (i.e. the FTDI UART). (Note: 0 is the default for the second arg, so same as what you did).

Then from the UART 6 REPL, I did:

Code: Select all

os.dupterm(None, 1)
which detached the VCP.

But was then still able to do

Code: Select all

vcp = pyb.USB_VCP()
vcp.read(10)
and see input from ttyACM0 (the VCP).

So that sounds like exactly what you want?

Note there's a shortcut which is that you can write:

Code: Select all

os.dupterm(pyb.UART(6,9600), 1)
which will put UART6 straight into the slot previously used by the VCP, meaning you don't need the second call to dupterm to remove the VCP.
doublevee wrote:
Thu Feb 27, 2020 6:52 am
I'm afraid I do not know where mpconfigboard.h is or how it's used? Do you have a link to any documentation I can read please?
This is if you're building the firmware from source. Each board has a config file defining how it's configured. In this case I'm talking about https://github.com/micropython/micropyt ... figboard.h

But this is do-able with Python, so no need to worry about that.

doublevee
Posts: 38
Joined: Mon Jul 02, 2018 11:09 pm

Re: Disabling REPL over USB only

Post by doublevee » Thu Feb 27, 2020 1:35 pm

That’s great! Thank you.

In the final product I will have REPL disabled completely but this will be so useful for testing.

I will read up on the board config file stuff - I have so much to learn on how to build an image from scratch!

Post Reply