micropython/micropython-esp32

Change REPL uart pins

0xDBFB7 opened this issue · 8 comments

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 😉).

@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.

@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.

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.

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

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

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.

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