UART2 malfunctioning after esp_restart() after migration to 4.2 toolchain.

tschak909
Posts: 36
Joined: Mon Oct 26, 2020 8:17 pm

UART2 malfunctioning after esp_restart() after migration to 4.2 toolchain.

Postby tschak909 » Sat Feb 06, 2021 11:55 pm

After migration to the 4.2 toolchain (from 4.1), we now are experiencing the UART malfunctioning after an esp_restart();

Code: Select all

void UARTManager::end()
{
    uart_driver_delete(_uart_num);
    if(_uart_q)
        vQueueDelete(_uart_q);
    _uart_q = NULL;
}

void UARTManager::begin(int baud)
{
    if(_uart_q)
    {
        end();
    }

    uart_config_t uart_config = 
    {
        .baud_rate = baud,
        .data_bits = UART_DATA_8_BITS,
        .parity = UART_PARITY_DISABLE,
        .stop_bits = UART_STOP_BITS_1,
        .flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
        .rx_flow_ctrl_thresh = 122, // No idea what this is for, but shouldn't matter if flow ctrl is disabled?
        .use_ref_tick = false // ?
    };
    uart_param_config(_uart_num, &uart_config);

    int tx, rx;
    if(_uart_num == 0)
    {
        rx = UART0_RX;
        tx = UART0_TX;
    }
    else if(_uart_num == 1)
    {
        rx = UART1_RX;
        tx = UART1_TX;
    }
    else if (_uart_num == 2)
    {
        rx = UART2_RX;
        tx = UART2_TX;
    } else {
        return;
    }

    uart_set_pin(_uart_num, tx, rx, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);

    // Arduino default buffer size is 256
    int uart_buffer_size = 256;
    int uart_queue_size = 10;
    int intr_alloc_flags = 0;

    // Install UART driver using an event queue here
    //uart_driver_install(_uart_num, uart_buffer_size, uart_buffer_size, uart_queue_size, &_uart_q, intr_alloc_flags);
    uart_driver_install(_uart_num, uart_buffer_size, 0, uart_queue_size, NULL, intr_alloc_flags);

    // Set initialized.
    _initialized=true;
}
Has behavior changed? Do we need to do something different?

tschak909
Posts: 36
Joined: Mon Oct 26, 2020 8:17 pm

Re: UART2 malfunctioning after esp_restart() after migration to 4.2 toolchain.

Postby tschak909 » Sun Feb 07, 2021 12:36 am

For some reason, reverting THIS commit to IDF fixed it for us...
https://github.com/espressif/esp-idf/co ... 995c21dcaa

why?

What's going on?

-Thom

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: UART2 malfunctioning after esp_restart() after migration to 4.2 toolchain.

Postby WiFive » Sun Feb 07, 2021 3:03 am

Can you give more details about the malfunction?

tschak909
Posts: 36
Joined: Mon Oct 26, 2020 8:17 pm

Re: UART2 malfunctioning after esp_restart() after migration to 4.2 toolchain.

Postby tschak909 » Sun Feb 07, 2021 3:17 am

Well, it looks like the TX fifo is being reset incorrectly for UART2, causing transmits to fail _AFTER_ the esp_restart() is issued.

Our fix is here:
https://github.com/FujiNetWIFI/fujinet- ... 252b927d82

And the initial fix that led us to this conclusion is here in IDF:
https://github.com/espressif/esp-idf/co ... 995c21dcaa

While I do think IDF's fix is correct (you DO want to reset both of the FIFOs when you reset comms parameters, because your data is invalid), the fact that this somehow causes FIFO corruption may point to a hardware bug. Since the comms parameters aren't changing for UART2 when the esp_restart() is issued, our fix of simply not setting the comms parameters again seems to work.

-Thom

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: UART2 malfunctioning after esp_restart() after migration to 4.2 toolchain.

Postby WiFive » Sun Feb 07, 2021 6:13 am

https://github.com/espressif/esp-idf/co ... 5405f6a67e

Maybe the DPORT_UART_MEM_RST needs to be added?

Who is online

Users browsing this forum: ChatGPT-User, PerplexityBot and 4 guests