UART data corrupted and events delayed while connecting to Wifi

torkleyy
Posts: 6
Joined: Tue Sep 05, 2023 5:51 pm

UART data corrupted and events delayed while connecting to Wifi

Postby torkleyy » Mon Sep 18, 2023 2:10 pm

I'm experiencing some weird issues when trying to receive data from UART while also connecting to a wifi.

Some details about my setup:

Board: Olimex ESP32-Gateway Rev. G
ESP IDF: 5.1.1
UART: UART1
Baud rate: 2400

My application is very time critical which is why I have configured all application tasks to run on core0, except for UART handling which runs on core1:

Code: Select all

CONFIG_ESP_MAIN_TASK_AFFINITY=0x0
CONFIG_PTHREAD_TASK_CORE_DEFAULT=0
CONFIG_PTHREAD_DEFAULT_CORE_0=y
For my UART handler, I set a high priority (10) and install the UART driver on Core 1 so it shouldn't interfere with any interrupts on Core 0. I also configure the interrupts so I am notified of every single byte (because I need to be able to respond quickly to one specific byte value):

Flags: RX Fifo Overflow, TX Done
Receive timeout: 8
RX Fifo full: 1
TX Fifo full: 1

To receive the bytes, I am blocking on the queue to receive the next event.

During "normal operation", everything works as expected, that is:

* I receive notification about every single byte I receive (I only ever receive one at a time)
* The delay between receiving it and being notified about it is consistent, such that the observed standard deviation is 9µs

When enabling wifi (starting the wifi driver and connecting to an AP), I observed the following problems:

* The received data would get corrupted (value measured at pin (using an oscilloscope) is correct, value received in software is not) while doing any communication at all while the device is connected via USB. Probably cause: Peaks during wifi communication cannot be reliably supplied by the USB port. An external power supply solved the problem.
* With external power supply: While connecting to a wifi, in 50% of cases (bootups), I would receive garbage data on UART and be notified of the bytes late (up 8 bytes received at time of notification).
* After the connection is established, UART works as expected again, even when performing HTTP requests in the background (granted, I have not tested what happens with extensive communication)

Interestingly, the pins used for UART also seem to make a substantial difference in the delay between receiving a byte and transmitting in response to it. I have tried:

tx=32, rx=35
tx=13, rx=12

With the latter, I have noticed an increase in the delay of around 130µs (delay, not deviation).

At this point, I have no idea what else to try or how to debug the issue... Can anybody shed light on these issues?
Thank you so much in advance!

username
Posts: 537
Joined: Thu May 03, 2018 1:18 pm

Re: UART data corrupted and events delayed while connecting to Wifi

Postby username » Thu Sep 21, 2023 1:36 am

Have you made any changes in menuconfig ?
Like changing the CPU speed from default 160mhz to 240 ?
There are allot of other options in there such as placing uart functions into IRAM.

Who is online

Users browsing this forum: Bing [Bot] and 107 guests