8000 esp8266: Allow disable of REPL on UART0 by dmkent · Pull Request #3277 · micropython/micropython · GitHub
[go: up one dir, main page]

Skip to content

esp8266: Allow disable of REPL on UART0 #3277

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 18 commits into from

Conversation

dmkent
Copy link
@dmkent dmkent commented Aug 16, 2017

This PR builds on the great initial work of @mhoffma in #2891. It rebases that work then extends those changes to address comments on #2891 by @dpgeorge, provide ability to enable/disable REPL and further decouple esp_mphal.c, machine_uart.c and uart.c from one-another

It pumps all UART RX into it's own ring buffer as well as conditionally to the main REPL input_buf. TX will go out on the UART as normal but this adds a conditional TX API for esp_mphal to use that will conditionally disable REPL TX to UART.

The conditional RX/TX behaviour is currently switched using an extra parameter to UART.init(). This would need to change to align with whatever is eventually decided in #3144. This shouldn't be very onerous if the uos.dupterm(obj, index) approach is adopted.

To make use of this behaviour the process is basically:

  1. Boot ESP8266, connect via UART, use REPL on UART to setup webrepl.

  2. Power down, connect whatever other device you want to your UART.

  3. Boot and connect to webrepl.

  4. Reinitalise the UART to disable REPL (and set other params as needed):

    uart0.init(use_repl=0, baudrate=9600, rxbuflen=256)

  5. Use the webrepl and the Pythonic UART API to talk to your other device using UART without any weird REPL interaction!

mhoffma and others added 18 commits August 16, 2017 20:21
Previously was not checking rxbuf ringbuffer state correctly.
From @dpgeorge on micropython#2891:

    IMO this belongs in machine_uart.c, since it's specific to UART
    behaviour. Also, since UART1 can't receive it doesn't need to
    take an argument.

Makes more sense here as it is UART specific.
Add flag to determine if UART object's rx should be sent to
repl as well.

When sending to repl all input is sent to input_buf as well as
internal rxbuf.

Note that this logic will need to be changed when dupterm slots
stuff is implemented.
Apply the use_repl flag to TX in addition to RX.

When flag is true then we send TX chars to UART, when false they
don't go anywhere.
All logic now mediated by machine_uart which in turn
handles the raw uart interactions.
Make sure we reallocate rxbuf if we change rxbuflen
using UART.init().
This is needed to ensure rxbuf and use_repl are properly
initialised on boot. With-out this we don't get working
REPL on UART.
@elfmimi
Copy link
Contributor
elfmimi commented Aug 18, 2017

This is what I am waiting for. I will try it out.

Copy link
Contributor
@pfalcon pfalcon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed in the previous tickets, UART should be refactored in a separate class, and its usage or not usage for REPL should be achieved using machine.dupterm() (#3144).

@mhoffma
Copy link
Contributor
mhoffma commented Sep 17, 2017

Man I was just looking for this, thanks for carrying the torch!

@dpgeorge
Copy link
Member

@dmkent thanks for making further progress with this topic. Now that #3144 merged (uos.dupterm behaviour) would you like to update this PR to use that instead of the use_repl argument to the UART constructor? If not then I will take it from here.

@dmkent
Copy link
Author
dmkent commented Sep 22, 2017

Sure, happy to look into it.

Couple of things that might be simpler resolved first.

  1. Which index should each stream go on? UART=> 1, webrepl => 0 is less breaking (i.e. that would replicated current behaviour) but UART => 0, webrepl => 1 seems more logical given the UART is more or less the default REPL stream.

  2. The current UART interface is not all that far from a standard write/readinto interface so will look into making that consistent.

  3. Where is the state best maintained? I'm assuming building on the term_obj in py/mpstate.h is the line of least resistance but is there another better preference?

@dpgeorge
Copy link
Member

Which index should each stream go on? UART=> 1, webrepl => 0 is less breaking (i.e. that would replicated current behaviour) but UART => 0, webrepl => 1 seems more logical given the UART is more or less the default REPL stream.

The original discussion in #3144 was to leave index=0 free for the user to use, and then index=1 would have the UART in it by default. So that means the user can do uos.dupterm(some_serial_object) and it will "just work", and won't destroy the existing REPL source.

But, looking at it again after some time, it does seem more logical to put the default REPL source at index=0. Doing it that way is not such a breaking change for esp8266 because WebREPL is the main user of dupterm and the WebREPL setup code must anyway change no matter what approach is taken. So might be better to aim for this behaviour, of UART at index=0.

The current UART interface is not all that far from a standard write/readinto interface so will look into making that consistent.

It should already have exactly a readinto/write interface.

Where is the state best maintained?

The esp8266 is short on RAM so objects should only be created if needed. Thus the UART should be created on the heap when needed and a pointer to it stored in the root pointers upon creation.

@dmkent
Copy link
Author
dmkent commented Oct 12, 2017

@dpgeorge, while I'd love to get back to this, it's not likely to happen in the next month or so. Feel free to pick it up if you have the inclination in the mean-time.

@ulno
Copy link
ulno commented Jan 20, 2018

It would really be nice if this could somehow be made work in mainline. However doing that patch seems way out of my league as there seem so many changes regarding this from 1.9.1 (what this patch is for) to 1.9.3.. I assume nobody is interested to use the serial port on esp8266 upy for anything else than debugging as also all other related threads are dead? Is there any place where a normal human being mediumly skilled in c and c++ but not working 8 hours a day on upy development can start to revive this patch?

@roger-
Copy link
roger- commented Apr 8, 2018

Any updates on this?

@dpgeorge
Copy link
Member
dpgeorge commented May 8, 2018

Sorry, this did get quite stale. It's not forgotten!

@dpgeorge
Copy link
Member

Please see #3784 for my alternative to this PR.

@dpgeorge
Copy link
Member

Ability to disable UART(0) on the REPL was implemented in afd0701

@dpgeorge dpgeorge closed this May 21, 2018
tannewt added a commit to tannewt/circuitpython that referenced this pull request Aug 18, 2020
sharpdisplay: Prevent 'ValueError: <pin> in use' exception
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants
0