Search code examples
taskesp32

ESP32 - Task error while communicating over UART


I am currently working on a communication over UART with interrupts between 2 boards (ESP32 and NUCLEO64). I have the following code:

#define rxBufferSIZE (256)

void app_main()
{
    UART_init();    
    uart_isr_free(UART_NUM_2); 
    uart_isr_register(UART_NUM_2, uart_intr_handle, NULL, ESP_INTR_FLAG_IRAM, &handle_console);
    uart_enable_rx_intr(UART_NUM_2);

    while (1) 
    { 

    }
}

static void IRAM_ATTR uart_intr_handle(void *arg)
{
    uint16_t rx_fifo_len;
    uint16_t i=0;

    rx_fifo_len = UART2.status.rxfifo_cnt; // read number of bytes in UART buffer

    while(rx_fifo_len)
    {
        UART_SlaveRxBuffer[i] = UART2.fifo.rw_byte; // read all bytes
        i++;
        rx_fifo_len--;
    }


    /* Some additional code */


    uart_clear_intr_status(UART_NUM_2, UART_RXFIFO_FULL_INT_CLR|UART_RXFIFO_TOUT_INT_CLR);
}

static void UART_init()
{
    /* Configure parameters of an UART driver,
     * communication pins and install the driver */
    uart_config_t uart_config = {
        .baud_rate = 115200,
        .data_bits = UART_DATA_8_BITS,
        .parity    = UART_PARITY_DISABLE,
        .stop_bits = UART_STOP_BITS_1,
        .flow_ctrl = UART_HW_FLOWCTRL_DISABLE
    };
    uart_param_config(UART_NUM_2, &uart_config);
    uart_set_pin(UART_NUM_2, UART_TX, UART_RX, UART_RTS, UART_CTS);
    uart_driver_install(UART_NUM_2, rxBufferSIZE * 2, 0, 0, NULL, 0);
 }

Communication between both boards works everytime. The problem is I get the following error repeatedly after the first communication:

enter image description here

I do not know what is causing this so any help is appreciated. Thank you in advance!


Solution

  • I'd venture that your while loop is running at a higher priority than IDLE0, so IDLE0 doesn't get the chance to reset the WDT.

    You could do this instead (if only to test my idea):

    while (1)
    {
        vTaskDelay(1); // or 2 or 2; units are 10ms unless you changed it.
    }