Using UART0 on ESP32-S2

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
p_j
Posts: 102
Joined: Mon Aug 23, 2021 1:08 pm
Location: Sydney

Using UART0 on ESP32-S2

Post by p_j » Sun Jun 26, 2022 5:46 am

Hi have a device that has 4 UART peripherals, sometimes I need to use 2 peripherals at the same time. At the moment I can only use UART1 and keep switching it between the devices. It does work but it's hard to debug and prone to errors.

I'm not that strong on C but it seems like the code below prevents changing the pins for UART0.

Does anyone know the background to this, is there an underlying reason why UART0 can't be used on the esp32 family?

Thanks

machine_uart.c

Code: Select all


STATIC mp_obj_t machine_uart_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
    mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true);


    switch (uart_num) {
        case UART_NUM_0:
            self->rx = UART_PIN_NO_CHANGE; // GPIO 3
            self->tx = UART_PIN_NO_CHANGE; // GPIO 1
            break;
        case UART_NUM_1:
            self->rx = 9;
            self->tx = 10;
            break;
        #if SOC_UART_NUM > 2
        case UART_NUM_2:
            self->rx = 16;
            self->tx = 17;
            break;
        #endif
    }

    // Only reset the driver if it's not the REPL UART.
    if (uart_num != MICROPY_HW_UART_REPL) {
        // Remove any existing configuration
        uart_driver_delete(self->uart_num);

        // init the peripheral
        // Setup
        uart_param_config(self->uart_num, &uartcfg);

        uart_driver_install(uart_num, self->rxbuf, self->txbuf, 0, NULL, 0);
    }

Christian Walther
Posts: 169
Joined: Fri Aug 19, 2016 11:55 am

Re: Using UART0 on ESP32-S2

Post by Christian Walther » Sun Jun 26, 2022 8:41 am

I don’t know any details, I don’t know if this is still relevant, and I also don’t know if it extends from the ESP32 to the ESP32-S2, but it may have something to do with the comment linked here (coming from this commit and removed in this commit):
Christian Walther wrote:
Sun Jul 11, 2021 2:07 pm
Correction: I just learned that detaching the UART using dupterm() does not work on the ESP32 because it’s not attached that way (“UART(0) is disabled (dedicated to REPL)”, esp32/machine_uart.c).

However you can run UART 1 on the same pins: machine.UART(1, tx=1, rx=3)
Are you using version 1.19, which includes the mentioned commit?

p_j
Posts: 102
Joined: Mon Aug 23, 2021 1:08 pm
Location: Sydney

Re: Using UART0 on ESP32-S2

Post by p_j » Sun Jun 26, 2022 10:22 am

Christian Walther wrote:
Sun Jun 26, 2022 8:41 am
I don’t know any details, I don’t know if this is still relevant, and I also don’t know if it extends from the ESP32 to the ESP32-S2, but it may have something to do with the comment linked here (coming from this commit and removed in this commit):
Christian Walther wrote:
Sun Jul 11, 2021 2:07 pm
Correction: I just learned that detaching the UART using dupterm() does not work on the ESP32 because it’s not attached that way (“UART(0) is disabled (dedicated to REPL)”, esp32/machine_uart.c).

However you can run UART 1 on the same pins: machine.UART(1, tx=1, rx=3)
Are you using version 1.19, which includes the mentioned commit?
Thanks for the links, interesting.

Yes I'm using 1.19 so I should have that commit. Do you know how to stop the REPL outputting to UART0?

Post Reply