ESP32-通过UART通讯时出现任务错误

时间:2019-02-11 19:14:38

标签: task esp32

我目前正在通过UART进行通信,其中2个板(ESP32和NUCLEO64)之间存在中断。我有以下代码:

#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);
 }

两个板之间的通信每次都起作用。问题是我在第一次通信后反复得到以下错误:

enter image description here

我不知道是什么原因造成的,因此不胜感激。 预先谢谢你!

1 个答案:

答案 0 :(得分:1)

我敢保证您的while循环的运行优先级高于IDLE0,因此IDLE0没有机会重置WDT。

您可以改为这样做(如果只是为了测试我的想法):

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