ESP32 uart problems

I’m encountering a problem where uart receive data from UART1 is being lost.

This seems to occur when communicating via WiFi.

I have used a logic analyser to observe the serial data going in and by toggling a port pin when data is read.
I have set the uart receive buffer to 16384 bytes, but this does not make any observable difference. When there is an event that is consuming some time (say 40ms) and the uart dispatcher is not being called, incoming uart data gets lost.

My guess is the esp32 uart fifo gets filled, but the mongoose higher level code is not retrieving the data and buffering it.

Is this the expected behaviour? Any suggestions how I can mitigate this problem?

I ended up using the ESP-IDF drivers. The receive buffer on those drivers works as I expect.

Hello @Kartman, I’m having similar problem. I realize this is an old thread but if you’re still around could you please provide some more detail about how you solved this? Thanks…

Here’s some excerpts from my code. Refer to the ESP-IDF doc on the finer details.
Basically I call the ESP-IDF functions to setup the uart and maintain a buffer. The I use a mongoose timer
to regularly poll the buffer to see if there is any data

//
//   called regularly to read data from the uart
//
static void uart_handler_cb(void *arg)
{
  #define BUFFSIZE 128
  uint8_t data[BUFFSIZE];
  int length = 0;
  uint8_t *buff;

  uart_get_buffered_data_len(uart_num, (size_t *)&length);

  length = uart_read_bytes(uart_num, data, length, 10);

//...process uart data
}



    static void uart_init(void)
{

  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};
  // Configure UART parameters
  uart_param_config(uart_num, &uart_config);

  // tx is gpio 26,rx is 25
  uart_set_pin(uart_num, GPIO_NUM_26, GPIO_NUM_25, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);

  // Install UART driver using an event queue here
   uart_driver_install(uart_num, 16384, 512, 0, NULL, 0);
}

// in mgos_app_init().....
mgos_set_timer(2, true, uart_handler_cb, NULL); //uart handler
  uart_init();                                    //alternate uart handler (esp-idf)

Tanks very much! I’ll play with this.

Hi, I tried to compile your program but it didn’t work. Did you added something else to your mos.yml to compiles ESP-IDF functions?

You shouldn’t have that problem
mOS is an event-driven framework and you are expected to return as soon as possible, if you need to perform further actions fire another event (a timer callback).
At what speed are you communicating ?
How do you configure the UART ?
How do you call mOS functions ? Do you use C or mJS ?
Post a bare minimum piece of code reproducing the problem

Hi @scaprile, you can find the code in this post: Use ESP-IDF functions (UART)