micropython / micropython-esp32

Old port of MicroPython to the ESP32 -- new port is at https://github.com/micropython/micropython
MIT License
673 stars 216 forks source link

Change REPL uart pins #158

Closed 0xDBFB7 closed 7 years ago

0xDBFB7 commented 7 years ago

I see that the machine.uart implementation allows one to change the UART pins, and all UARTs can go through the GPIO matrix. Is there any way for one to change which pins UART0 (REPL) is connected to?

Even if this would require source editing and recompilation, if someone could point me in the right direction, that'd be great.

I realize that this is a bit niche, but I could see a few real-world uses (also I need it :wink:).

MrSurly commented 7 years ago

@BasedOnTechnology

I don't think µPy exposes the GPIO matrix in Python directly. Some things (e.g. HW SPI) utilize it. I suppose the UART class initializer could be extended to accept rx_pin and tx_pin.

0xDBFB7 commented 7 years ago

@MrSurly Mainly what I'm looking for is the ability to switch the REPL to UART1, and use UART0 with machine.uart. I tried digging through the code, but I couldn't find where the uart was defined with respect to the REPL.

nickzoic commented 7 years ago

I, uh, think it already does as the rxand tx parameters to the constructor ... ... but looking at it, it might not be doing those steps in the right order ... machine_uart_init sets usp self->tx(etc) from the args but machine_uart_make_new has already configured the UART to the default pins. In any case, I think this is the right way to do it, rather than futzing with the matrix directly. We may want to write some code which handles collisions in pin usage though (?)

MrSurly commented 7 years ago

Mainly what I'm looking for is the ability to switch the REPL to UART1

@BasedOnTechnology Looks like UART 0 is already hard-coded dedicated to the repl, as seen in esp32/uart.c.

nickzoic commented 7 years ago

Yeah, I think we could maybe fix that too ... I started off messing around with a telnet server [1] for the REPL and some kind of generic REPL multiplexor would make sense I think, so that rrepl / webrepl can hook into the REPL mulitiplexor. Then if your code seizes control of UART 0 it can be disconnected gracefully and the other connections stay alive.

[1] https://github.com/nickzoic/micropython-esp32/tree/esp32-rrepl , don't look too closely at the code, it's rather sketchy but I'm thinking of a tinyssh server instead anyway

dpgeorge commented 7 years ago

When machine.dupterm() is implemented it will allow you to turn off the REPL from UART0 (and redirect it elsewhere if needed). See https://github.com/micropython/micropython/pull/3144 for some recent discussion around the dupterm function.

0xDBFB7 commented 7 years ago

I don't actually need this anymore, (switched pins in hardware) and since UART already takes pin numbers, I think I'll close this since dupterm would supersede it.

0xDBFB7 commented 6 years ago

For citizens of the future: The relevant lines are in sdkconfig.h, modify like so:

#define CONFIG_CONSOLE_UART_BAUDRATE 115200
#define CONFIG_CONSOLE_UART_CUSTOM 1
#define CONFIG_CONSOLE_UART_CUSTOM_NUM 0
#define CONFIG_CONSOLE_UART_NUM 0
#define CONFIG_CONSOLE_UART_TX_GPIO 17
#define CONFIG_CONSOLE_UART_RX_GPIO 5