Skip to content

fix(uart): uses IDF 5.x API to set loopback #10442

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
85d83f3
fix(uart): uses IDF 5.x API to set loopback
SuGlider Oct 9, 2024
412b76e
fix(uart): ESP32-P4 loopback functions
SuGlider Oct 9, 2024
d7bb46e
fix(uart): fix example
SuGlider Oct 9, 2024
55a2d1e
fix(uart): new testing loopback API
SuGlider Oct 9, 2024
4ef3148
fix(uart): new testing loopback API
SuGlider Oct 9, 2024
38b4474
fix(uart): new testing loopback API
SuGlider Oct 9, 2024
2b0672e
fix(uart): new testing loopback API
SuGlider Oct 9, 2024
7176970
fix(uart): new testing loopback API
SuGlider Oct 9, 2024
f078662
fix(uart): new testing loopback API
SuGlider Oct 9, 2024
61e2263
fix(uart): new testing loopback API
SuGlider Oct 9, 2024
5748548
fix(test): Fix UART validation test
lucasssvaz Oct 11, 2024
a0d685d
Merge branch 'release/v3.1.x' into uart_loop_back
SuGlider Oct 23, 2024
ef50176
fix(uart): fixes P4 pins for uart testing case
SuGlider Oct 24, 2024
c35b76e
fix(uart): fixes pins detaching - shall revert loopback
SuGlider Oct 24, 2024
8d73687
fix(uart): removes esp32-p4 rx2 and tx2 pin definition
SuGlider Oct 24, 2024
a97e7ab
fix(uart): no uart2,3,4 esp32-p4 pins check
SuGlider Oct 24, 2024
ec64369
fix(uart): update uart.ino commentaries
SuGlider Oct 24, 2024
3c93de7
feat(uart): allows the board pins_arduino.h to define other uart pins
SuGlider Oct 24, 2024
06dffa1
fix(uart): typo - additional } in the code
SuGlider Oct 24, 2024
f9b291f
fix(uart): wrong block coding - bad { }
SuGlider Oct 24, 2024
812e6c5
fix(uart): code blocks errors
SuGlider Oct 24, 2024
4c62634
fix(uart): CI error with uninitialized struct member
SuGlider Oct 24, 2024
df73cb4
fix(uart): fixes uart.ino CI test code
SuGlider Oct 24, 2024
d9c3987
fix(uart): keep previous pins as is in case -1 is used
SuGlider Oct 24, 2024
96d4757
Merge branch 'release/v3.1.x' into uart_loop_back
SuGlider Oct 25, 2024
b1428b3
fix(uart): making the source code the same as in the branch
SuGlider Oct 25, 2024
520ea66
feat(ci): simplification of uart testing sketch
SuGlider Oct 26, 2024
be20fcb
feat(ci): fixing and adapting perimanager teste
SuGlider Oct 26, 2024
6e5baf1
fix(ci): cleanup code
SuGlider Oct 26, 2024
cb7b967
fix(ci): minimal changes
SuGlider Oct 26, 2024
5ff67d6
fix(ci): restore log level to debug
SuGlider Oct 26, 2024
b342545
fix(ci): missing error message
SuGlider Oct 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions cores/esp32/esp32-hal-uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,15 @@ static bool _uartDetachBus_RX(void *busptr) {
// sanity check - it should never happen
assert(busptr && "_uartDetachBus_RX bus NULL pointer.");
uart_t *bus = (uart_t *)busptr;
uart_set_loop_back(bus->num, false); // disable loopback
return _uartDetachPins(bus->num, bus->_rxPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
}

static bool _uartDetachBus_TX(void *busptr) {
// sanity check - it should never happen
assert(busptr && "_uartDetachBus_TX bus NULL pointer.");
uart_t *bus = (uart_t *)busptr;
uart_set_loop_back(bus->num, false); // disable loopback
return _uartDetachPins(bus->num, UART_PIN_NO_CHANGE, bus->_txPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
}

Expand Down Expand Up @@ -1164,11 +1166,11 @@ unsigned long uartDetectBaudrate(uart_t *uart) {
This function internally binds defined UARTs TX signal with defined RX pin of any UART (same or different).
This creates a loop that lets us receive anything we send on the UART without external wires.
*/
void uart_internal_loopback(uint8_t uartNum, int8_t rxPin) {
if (uartNum > SOC_UART_HP_NUM - 1 || !GPIO_IS_VALID_GPIO(rxPin)) {
void uart_internal_loopback(uint8_t uartNum, bool loop_back_en) {
if (uartNum > SOC_UART_HP_NUM - 1) {
return;
}
esp_rom_gpio_connect_out_signal(rxPin, UART_TX_SIGNAL(uartNum), false, false);
uart_set_loop_back(uartNum, loop_back_en);
}

/*
Expand Down
2 changes: 1 addition & 1 deletion cores/esp32/esp32-hal-uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ unsigned long uartDetectBaudrate(uart_t *uart);

// Make sure UART's RX signal is connected to TX pin
// This creates a loop that lets us receive anything we send on the UART
void uart_internal_loopback(uint8_t uartNum, int8_t rxPin);
void uart_internal_loopback(uint8_t uartNum, bool loop_back_en);

// Routines that generate BREAK in the UART for testing purpose

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void setup() {
// GPIO4 <--> GPIO5 using external wire
Serial1.begin(BAUD, SERIAL_8N1, RXPIN, TXPIN); // Rx = 4, Tx = 5 will work for ESP32, S2, S3 and C3
#if USE_INTERNAL_PIN_LOOPBACK
uart_internal_loopback(TEST_UART, RXPIN);
uart_internal_loopback(TEST_UART, true);
#endif

for (uint8_t i = 0; i < sizeof(fifoFullTestCases); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void setup() {
// GPIO4 <--> GPIO5 using external wire
Serial1.begin(BAUD, SERIAL_8N1, RXPIN, TXPIN); // Rx = 4, Tx = 5 will work for ESP32, S2, S3 and C3
#if USE_INTERNAL_PIN_LOOPBACK
uart_internal_loopback(TEST_UART, RXPIN);
uart_internal_loopback(TEST_UART, true);
#endif

for (uint8_t i = 0; i < sizeof(fifoFullTestCases); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void setup() {
// GPIO4 <--> GPIO5 using external wire
Serial1.begin(BAUD, SERIAL_8N1, RXPIN, TXPIN); // Rx = 4, Tx = 5 will work for ESP32, S2, S3 and C3
#if USE_INTERNAL_PIN_LOOPBACK
uart_internal_loopback(TEST_UART, RXPIN);
uart_internal_loopback(TEST_UART, true);
#endif

for (uint8_t i = 0; i < sizeof(fifoFullTestCases); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void setup() {
// GPIO4 <--> GPIO5 using external wire
Serial1.begin(BAUD, SERIAL_8N1, RXPIN, TXPIN); // Rx = 4, Tx = 5 will work for ESP32, S2, S3 and C3
#if USE_INTERNAL_PIN_LOOPBACK
uart_internal_loopback(TEST_UART, RXPIN);
uart_internal_loopback(TEST_UART, true);
#endif

for (uint8_t i = 0; i < sizeof(rxTimeoutTestCases); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void setup() {
// creating a loopback that will allow to write to TEST_UART number
// and send it to RX with no need to physically connect both pins
#if TEST_UART > 0
uart_internal_loopback(TEST_UART, RXPIN);
uart_internal_loopback(TEST_UART, true);
#else
// when UART0 is used for testing, it is necessary to send data using the Serial Monitor/Terminal
// Data must be sent by the CP2102, manually using the Serial Monitor/Terminal
Expand Down
36 changes: 18 additions & 18 deletions tests/validation/periman/periman.ino
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/* Peripheral Manager test
*
* This test is using Serial to check if the peripheral manager is able to
* attach and detach peripherals correctly on shared pins.
* Make sure that the peripheral names contain only letters, numbers and underscores.
*
* This test skips the following peripherals:
* - USB: USB is not able to be detached
* - SDMMC: SDMMC requires a card to be mounted before the pins are attached
* - ETH: ETH requires a ethernet port to be connected before the pins are attached
*/

This test is using Serial to check if the peripheral manager is able to
attach and detach peripherals correctly on shared pins.
Make sure that the peripheral names contain only letters, numbers and underscores.

This test skips the following peripherals:
- USB: USB is not able to be detached
- SDMMC: SDMMC requires a card to be mounted before the pins are attached
- ETH: ETH requires a ethernet port to be connected before the pins are attached
*/

#if SOC_I2S_SUPPORTED
#include "ESP_I2S.h"
Expand Down Expand Up @@ -72,7 +72,7 @@ void setup_test(String test_name, int8_t rx_pin = UART1_RX_DEFAULT, int8_t tx_pi
pinMode(uart1_rx_pin, INPUT_PULLUP);
pinMode(uart1_tx_pin, OUTPUT);
Serial1.setPins(uart1_rx_pin, uart1_tx_pin);
uart_internal_loopback(1, uart1_rx_pin);
uart_internal_loopback(1, true);
delay(100);
log_v("Running %s test", test_name.c_str());
}
Expand All @@ -88,7 +88,7 @@ void teardown_test(void) {
Serial1.flush();

Serial1.setPins(uart1_rx_pin, uart1_tx_pin);
uart_internal_loopback(1, uart1_rx_pin);
uart_internal_loopback(1, true);
delay(100);
}

Expand All @@ -101,8 +101,8 @@ void teardown_test(void) {

/* Test functions */
/* These functions must call "setup_test" and "teardown_test" and set "test_executed" to true
* if the test is executed
*/
if the test is executed
*/

void gpio_test(void) {
setup_test("GPIO");
Expand Down Expand Up @@ -130,7 +130,7 @@ void sigmadelta_test(void) {

void adc_oneshot_test(void) {
#if !SOC_ADC_SUPPORTED
setup_test("ADC_Oneshot");
setup_test("ADC_Oneshot - NO ADC Support");
#else
setup_test("ADC_Oneshot", ADC1_DEFAULT, ADC2_DEFAULT);
test_executed = true;
Expand All @@ -151,8 +151,8 @@ void ARDUINO_ISR_ATTR adcComplete() {
#endif

void adc_continuous_test(void) {
#if !SOC_ADC_SUPPORTED
setup_test("ADC_Continuous");
#if !SOC_ADC_SUPPORTED || CONFIG_IDF_TARGET_ESP32P4
setup_test("ADC_Continuous - NO Support ** P4 fails");
#else
setup_test("ADC_Continuous", ADC1_DEFAULT, ADC2_DEFAULT);
test_executed = true;
Expand Down Expand Up @@ -280,7 +280,7 @@ void setup() {
delay(10);
}
Serial1.onReceive(onReceive_cb);
uart_internal_loopback(1, uart1_rx_pin);
uart_internal_loopback(1, true);

gpio_test();
sigmadelta_test();
Expand Down
Loading
Loading