feat(uart): sets correct ESP32/S2 clock source for the example by SuGlider · Pull Request #11286 · espressif/arduino-esp32 (original) (raw)

Rx Timeout example was not working correctly using ESP32 and ESP32-S2 due to default selection of REF_TICK as UART Clock Source. REF_TICK limits RX Timeout to 1.

This PR adds the necessary call to HardwareSerial::setClockSource() in order to make it work properly.

Tested using the example code of this PR.
ESP32 | ESP32-S2 | ESP32-C3 | ESP32-C6 | ESP32-S3 | ESP32-H2

ets Jul 29 2019 12:21:46

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:4888
load:0x40078000,len:16516
load:0x40080400,len:4
load:0x40080404,len:3476
entry 0x400805b4
[     8][I][esp32-hal-psram.c:102] psramAddToHeap(): PSRAM added to the heap.


================================
Test Case #1
================================
Testing the time for receiving 10 bytes at 9600 baud, using RX Timeout = 50:
It has sent 10 bytes from Serial1 TX to Serial1 RX
It took 62 milliseconds to read 10 bytes
Received data: [0123456789]
========================
Finished!


================================
Test Case #2
================================
Testing the time for receiving 10 bytes at 9600 baud, using RX Timeout = 20:
It has sent 10 bytes from Serial1 TX to Serial1 RX
It took 31 milliseconds to read 10 bytes
Received data: [0123456789]
========================
Finished!


================================
Test Case #3
================================
Testing the time for receiving 10 bytes at 9600 baud, using RX Timeout = 10:
It has sent 10 bytes from Serial1 TX to Serial1 RX
It took 21 milliseconds to read 10 bytes
Received data: [0123456789]
========================
Finished!


================================
Test Case #4
================================
Testing the time for receiving 10 bytes at 9600 baud, using RX Timeout = 5:
It has sent 10 bytes from Serial1 TX to Serial1 RX
It took 16 milliseconds to read 10 bytes
Received data: [0123456789]
========================
Finished!


================================
Test Case #5
================================
Testing the time for receiving 10 bytes at 9600 baud, using RX Timeout = 1:
It has sent 10 bytes from Serial1 TX to Serial1 RX
It took 11 milliseconds to read 10 bytes
Received data: [0123456789]
========================
Finished!