ESP32S3 IDF4.4.1 使用串口出现串口溢出的问题 求教。
Posted: Thu Jul 13, 2023 1:28 am
外部硬件: 使用两个串口不停接收数据,偶尔(也不是经常出现这样的问题)出现上电后,cpu串口buff溢出的情况,导致系统不停重启。
请教这样问题的原因是什么?如何解决?谢谢。
调试信息如下:
串口接收程序如下:
请教这样问题的原因是什么?如何解决?谢谢。
调试信息如下:
Code: Select all
I (36020) rr: Check sampling line
I (36020) rr: No adapter,connect adapter
I (36170) bsp_uart: UART buff full.uart2
RR rec toggl1
I (37160) bsp_uart: UART buff full.uart2
I (37770) bsp_uart: UART buff full.uart1
RR rec toggl1
I (38480) bsp_uart: UART fifo OV.uart2
ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x8 (TG1WDT_SYS_RST),boot:0x2f (SPI_FAST_FLASH_BOOT)
Saved PC:0x42002f85
0x42002f85: panic_handler at D:/Espressif/frameworks/esp-idf-v4.4.2/components/esp_system/port/panic_handler.c:148 (discriminator 3)
Code: Select all
//-----------------------------------------------------------------------------------------
void uart_event_handle(uart_port_t uart_num, QueueHandle_t queue, uart_event_t *event)
{
// int length = 0;
uint8_t *dtmp = malloc(BUF_SIZE);
//char *dest = malloc(BUF_SIZE);
bzero(dtmp, BUF_SIZE);
//bzero(dest, BUF_SIZE);
switch (event->type)
{
//Event of UART receving data
/*We'd better handler data event fast, there would be much more data events than
other types of events. If we take too much time on data event, the queue might
be full.*/
case UART_DATA:
//ESP_ERROR_CHECK(uart_get_buffered_data_len(uart_num, (size_t*)&length));
uart_read_bytes(uart_num, dtmp,event->size, portMAX_DELAY); //
//uart_write_bytes(uart_num, (const char *) dtmp, event->size);
//HexToAscii(dtmp, dest, event->size);
//ESP_LOGI(TAGu, "UART[%d] HEXdata:%s lenth=%d",uart_num,dest,event->size);
if(uart_num == UART1_PORT_NUM)
anlyze_SPO2(dtmp);
else if(uart_num == UART2_PORT_NUM)
{
//analzye_co2(dtmp);
data_analysis(dtmp[0]);
exchange_value(&etco2_sensor);
//HexToAscii(dtmp, dest, event->size);
//ESP_LOGI(TAGu, "UART[%d] HEXdata:%s lenth=%d",uart_num,dest,event->size);
}
break;
//Event of HW FIFO overflow detected
case UART_FIFO_OVF:
// If fifo overflow happened, you should consider adding flow control for your application.
// The ISR has already reset the rx FIFO,
// As an example, we directly flush the rx buffer here in order to read more data.
// uart_flush_input(uart_num);
uart_read_bytes(uart_num, dtmp,event->size, portMAX_DELAY);
bzero(dtmp, BUF_SIZE);
uart_flush(uart_num);
xQueueReset(queue);
ESP_LOGI(TAGu, "UART fifo OV.uart%d",uart_num);
break;
//Event of UART ring buffer full
case UART_BUFFER_FULL:
// If buffer full happened, you should consider encreasing your buffer size
// As an example, we directly flush the rx buffer here in order to read more data.
// uart_flush_input(uart_num);
uart_read_bytes(uart_num, dtmp,event->size, portMAX_DELAY);
bzero(dtmp, BUF_SIZE);
uart_flush(uart_num);
xQueueReset(queue);
ESP_LOGI(TAGu, "UART buff full.uart%d",uart_num);
break;
//Event of UART RX break detected
case UART_BREAK:
break;
//Event of UART parity check error
case UART_PARITY_ERR:
break;
//Event of UART frame error
case UART_FRAME_ERR:
break;
//UART_PATTERN_DET
case UART_PATTERN_DET:
break;
//Others
default:
break;
}
free(dtmp);
//free(dest);
dtmp = NULL;
}