diff --git a/cores/esp32/esp32-hal-uart.c b/cores/esp32/esp32-hal-uart.c index 706124c7451..7b2250c34fa 100644 --- a/cores/esp32/esp32-hal-uart.c +++ b/cores/esp32/esp32-hal-uart.c @@ -166,6 +166,7 @@ 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); } @@ -173,6 +174,7 @@ 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); } @@ -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); } /* diff --git a/cores/esp32/esp32-hal-uart.h b/cores/esp32/esp32-hal-uart.h index 402b5785915..389193df9da 100644 --- a/cores/esp32/esp32-hal-uart.h +++ b/cores/esp32/esp32-hal-uart.h @@ -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 diff --git a/libraries/ESP32/examples/Serial/OnReceiveError_BREAK_Demo/OnReceiveError_BREAK_Demo.ino b/libraries/ESP32/examples/Serial/OnReceiveError_BREAK_Demo/OnReceiveError_BREAK_Demo.ino index fb7af04c5f5..727dc61e47d 100644 --- a/libraries/ESP32/examples/Serial/OnReceiveError_BREAK_Demo/OnReceiveError_BREAK_Demo.ino +++ b/libraries/ESP32/examples/Serial/OnReceiveError_BREAK_Demo/OnReceiveError_BREAK_Demo.ino @@ -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++) { diff --git a/libraries/ESP32/examples/Serial/OnReceive_Demo/OnReceive_Demo.ino b/libraries/ESP32/examples/Serial/OnReceive_Demo/OnReceive_Demo.ino index cac59a50cd6..0abaa4d653e 100644 --- a/libraries/ESP32/examples/Serial/OnReceive_Demo/OnReceive_Demo.ino +++ b/libraries/ESP32/examples/Serial/OnReceive_Demo/OnReceive_Demo.ino @@ -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++) { diff --git a/libraries/ESP32/examples/Serial/RxFIFOFull_Demo/RxFIFOFull_Demo.ino b/libraries/ESP32/examples/Serial/RxFIFOFull_Demo/RxFIFOFull_Demo.ino index 7722ef6f47a..a0365163414 100644 --- a/libraries/ESP32/examples/Serial/RxFIFOFull_Demo/RxFIFOFull_Demo.ino +++ b/libraries/ESP32/examples/Serial/RxFIFOFull_Demo/RxFIFOFull_Demo.ino @@ -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++) { diff --git a/libraries/ESP32/examples/Serial/RxTimeout_Demo/RxTimeout_Demo.ino b/libraries/ESP32/examples/Serial/RxTimeout_Demo/RxTimeout_Demo.ino index 64d15d3d916..c231ed6f7b6 100644 --- a/libraries/ESP32/examples/Serial/RxTimeout_Demo/RxTimeout_Demo.ino +++ b/libraries/ESP32/examples/Serial/RxTimeout_Demo/RxTimeout_Demo.ino @@ -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++) { diff --git a/libraries/ESP32/examples/Serial/Serial_STD_Func_OnReceive/Serial_STD_Func_OnReceive.ino b/libraries/ESP32/examples/Serial/Serial_STD_Func_OnReceive/Serial_STD_Func_OnReceive.ino index 3c5ff0ba6fc..9e17ee5b9a4 100644 --- a/libraries/ESP32/examples/Serial/Serial_STD_Func_OnReceive/Serial_STD_Func_OnReceive.ino +++ b/libraries/ESP32/examples/Serial/Serial_STD_Func_OnReceive/Serial_STD_Func_OnReceive.ino @@ -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 diff --git a/tests/validation/periman/periman.ino b/tests/validation/periman/periman.ino index 8da59dd23b9..5e7fad90e61 100644 --- a/tests/validation/periman/periman.ino +++ b/tests/validation/periman/periman.ino @@ -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" @@ -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()); } @@ -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); } @@ -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"); @@ -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; @@ -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; @@ -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(); diff --git a/tests/validation/uart/uart.ino b/tests/validation/uart/uart.ino index 01c449867db..f729bf02745 100644 --- a/tests/validation/uart/uart.ino +++ b/tests/validation/uart/uart.ino @@ -1,9 +1,9 @@ /* UART test - * - * This test is using UART0 (Serial) only for reporting test status and helping with the auto - * baudrate detection test. - * UART1 (Serial1) and UART2 (Serial2), where available, are used for testing. - */ + + This test is using UART0 (Serial) only for reporting test status and helping with the auto + baudrate detection test. + UART1 (Serial1) is used for testing. +*/ #include #include "HardwareSerial.h" @@ -11,57 +11,31 @@ #include "Wire.h" // Default pins: -// | Name | ESP32 | S2 | S3 | C3 | C6 | H2 | -// UART0 RX | SOC_RX0 | 3 | 44 | 44 | 20 | 17 | 23 | -// UART0 TX | SOC_TX0 | 1 | 43 | 43 | 21 | 16 | 24 | -// UART1 RX | RX1 | 26 | 4 | 15 | 18 | 4 | 0 | -// UART1 TX | TX1 | 27 | 5 | 16 | 19 | 5 | 1 | -// UART2 RX | RX2 | 4 | -- | 19 | -- | -- | -- | -// UART2 TX | TX2 | 25 | -- | 20 | -- | -- | -- | +// | Name | ESP32 | S2 | S3 | C3 | C6 | H2 | P4 | +// UART0 RX | SOC_RX0 | 3 | 44 | 44 | 20 | 17 | 23 | 38 | +// UART0 TX | SOC_TX0 | 1 | 43 | 43 | 21 | 16 | 24 | 37 | +// UART1 RX | RX1 | 26 | 4 | 15 | 18 | 4 | 0 | 11 | +// UART1 TX | TX1 | 27 | 5 | 16 | 19 | 5 | 1 | 10 | /* - * For 2 UARTS: - * - * terminal - * | ^ - * v UART0 | - * RX ^ TX - * | - * report status - * | - * TX <---> RX - * UART1 - * - * For 3 UARTS: - * - * =====terminal====== - * ^ | ^ ^ - * | v UART0 | | - * | RX TX | - * | | - * ^ report status ^ - * | | - * | TX ---> RX | - * UART2 RX <--- TX UART1 - * - */ - -#if SOC_UART_HP_NUM == 2 -// Used for the pin swap test -#define NEW_RX1 9 -#define NEW_TX1 10 -#endif + Using 2 UARTS: + + terminal + | ^ + v UART0 | + RX ^ TX + | + report status + | + TX <---> RX + UART1 +*/ -// ESP32-P4 has no UART pin definition for RX2, TX2, RX3, TX3, RX4, TX4 -#ifndef RX2 -#define RX2 RX1 -#endif -#ifndef TX2 -#define TX2 RX1 -#endif +// Used for the pin swap test +#define NEW_RX1 10 +#define NEW_TX1 11 /* Utility global variables */ - static String recv_msg = ""; static int peeked_char = -1; @@ -71,105 +45,39 @@ extern int8_t uart_get_RxPin(uint8_t uart_num); extern int8_t uart_get_TxPin(uint8_t uart_num); // This function starts all the available test UARTs -void start_serial(unsigned long baudrate = 115200) { -#if SOC_UART_HP_NUM >= 2 +void start_serial1(unsigned long baudrate = 115200) { Serial1.begin(baudrate); while (!Serial1) { delay(10); } -#endif - -#if SOC_UART_HP_NUM >= 3 - Serial2.begin(baudrate); - while (!Serial2) { - delay(10); - } -#endif } // This function stops all the available test UARTs -void stop_serial(bool hard_stop = false) { -#if SOC_UART_HP_NUM >= 2 - Serial1.end(/*hard_stop*/); -#endif - -#if SOC_UART_HP_NUM >= 3 - Serial2.end(/*hard_stop*/); -#endif +void stop_serial() { + Serial1.end(); } // This function transmits a message and checks if it was received correctly void transmit_and_check_msg(const String msg_append, bool perform_assert = true) { delay(100); // Wait for some settings changes to take effect -#if SOC_UART_HP_NUM == 2 Serial1.print("Hello from Serial1 (UART1) >>> via loopback >>> Serial1 (UART1) " + msg_append); Serial1.flush(); delay(100); if (perform_assert) { TEST_ASSERT_EQUAL_STRING(("Hello from Serial1 (UART1) >>> via loopback >>> Serial1 (UART1) " + msg_append).c_str(), recv_msg.c_str()); } -#elif SOC_UART_HP_NUM >= 3 - Serial1.print("Hello from Serial1 (UART1) >>> to >>> Serial2 (UART2) " + msg_append); - Serial1.flush(); - delay(100); - if (perform_assert) { - TEST_ASSERT_EQUAL_STRING(("Hello from Serial1 (UART1) >>> to >>> Serial2 (UART2) " + msg_append).c_str(), recv_msg.c_str()); - } - - Serial2.print("Hello from Serial2 (UART2) >>> to >>> Serial1 (UART1) " + msg_append); - Serial2.flush(); - delay(100); - if (perform_assert) { - TEST_ASSERT_EQUAL_STRING(("Hello from Serial2 (UART2) >>> to >>> Serial1 (UART1) " + msg_append).c_str(), recv_msg.c_str()); - } -#else - log_d("No UARTs available for transmission"); - TEST_FAIL(); -#endif -} - -/* Tasks */ - -// This task is used to send a message after a delay to test the auto baudrate detection -void task_delayed_msg(void *pvParameters) { - HardwareSerial *selected_serial; - -#if SOC_UART_HP_NUM == 2 - selected_serial = &Serial; -#elif SOC_UART_HP_NUM >= 3 - selected_serial = &Serial1; -#endif - - delay(2000); - selected_serial->println("Hello from Serial1 to detect baudrate"); - selected_serial->flush(); - vTaskDelete(NULL); } /* Unity functions */ // This function is automatically called by unity before each test is run void setUp(void) { - start_serial(115200); -#if SOC_UART_HP_NUM == 2 + start_serial1(115200); log_d("Setup internal loop-back from and back to Serial1 (UART1) TX >> Serial1 (UART1) RX"); - - Serial1.onReceive([]() { - onReceive_cb(Serial1); - }); - uart_internal_loopback(1, RX1); -#elif SOC_UART_HP_NUM >= 3 - log_d("Setup internal loop-back between Serial1 (UART1) <<--->> Serial2 (UART2)"); - Serial1.onReceive([]() { - onReceive_cb(Serial1); - }); - Serial2.onReceive([]() { - onReceive_cb(Serial2); + onReceive_cb(Serial1, 1); }); - uart_internal_loopback(1, RX2); - uart_internal_loopback(2, RX1); -#endif + uart_internal_loopback(1, true); } // This function is automatically called by unity after each test is run @@ -180,52 +88,34 @@ void tearDown(void) { /* Callback functions */ // This is a callback function that will be activated on UART RX events -void onReceive_cb(HardwareSerial &selected_serial) { - int uart_num = -1; +void onReceive_cb(HardwareSerial &HWSerial, uint8_t uartNum) { char c; - (void)uart_num; // Avoid compiler warning when debug level is set to none - - if (&selected_serial == &Serial) { - uart_num = 0; -#if SOC_UART_HP_NUM >= 2 - } else if (&selected_serial == &Serial1) { - uart_num = 1; -#endif -#if SOC_UART_HP_NUM >= 3 - } else if (&selected_serial == &Serial2) { - uart_num = 2; -#endif - } - recv_msg = ""; - size_t available = selected_serial.available(); - + size_t available = HWSerial.available(); if (available != 0) { - peeked_char = selected_serial.peek(); + peeked_char = HWSerial.peek(); } while (available--) { - c = (char)selected_serial.read(); + c = (char)HWSerial.read(); recv_msg += c; } - log_d("UART %d received message: %s\n", uart_num, recv_msg.c_str()); + log_d("UART%d received message: %s\n", uartNum, recv_msg.c_str()); } /* Test functions */ // This test checks if a message can be transmitted and received correctly using the default settings -void basic_transmission_test(void) { +void basic_transmission_test() { log_d("Performing basic transmission test"); - transmit_and_check_msg(""); - Serial.println("Basic transmission test successful"); } // This test checks if the baudrate can be changed and if the message can be transmitted and received correctly after the change -void change_baudrate_test(void) { +void change_baudrate_test() { //Test first using the updateBaudRate method and then using the begin method log_d("Changing baudrate to 9600"); @@ -233,24 +123,15 @@ void change_baudrate_test(void) { Serial1.updateBaudRate(9600); TEST_ASSERT_UINT_WITHIN(192, 9600, Serial1.baudRate()); -#if SOC_UART_HP_NUM >= 3 - Serial2.updateBaudRate(9600); - TEST_ASSERT_UINT_WITHIN(192, 9600, Serial2.baudRate()); -#endif - log_d("Sending string using 9600 baudrate"); transmit_and_check_msg("using 9600 baudrate"); log_d("Changing baudrate back to 115200"); - start_serial(115200); + start_serial1(115200); //Baudrate error should be within 2% of the target baudrate TEST_ASSERT_UINT_WITHIN(2304, 115200, Serial1.baudRate()); -#if SOC_UART_HP_NUM >= 3 - TEST_ASSERT_UINT_WITHIN(2304, 115200, Serial2.baudRate()); -#endif - log_d("Sending string using 115200 baudrate"); transmit_and_check_msg("using 115200 baudrate"); @@ -258,7 +139,7 @@ void change_baudrate_test(void) { } // This test checks if the buffers can be resized properly -void resize_buffers_test(void) { +void resize_buffers_test() { size_t ret; log_d("Trying to resize RX buffer while running."); @@ -283,25 +164,39 @@ void resize_buffers_test(void) { } // This test checks if the begin function can be called when the UART is already running -void begin_when_running_test(void) { +void begin_when_running_test() { log_d("Trying to set up serial twice"); - start_serial(115200); + start_serial1(115200); + start_serial1(115200); + // starting other Serial ports as part of the test +#if SOC_UART_HP_NUM > 2 + Serial2.begin(115200, SERIAL_8N1, RX1, TX1); + Serial2.begin(115200); +#endif +#if SOC_UART_HP_NUM > 3 + Serial3.begin(115200, SERIAL_8N1, RX1, TX1); + Serial3.begin(115200); +#endif +#if SOC_UART_HP_NUM > 4 + Serial4.begin(115200, SERIAL_8N1, RX1, TX1); + Serial4.begin(115200); +#endif Serial.println("Begin when running test successful"); } // This test checks if the end function can be called when the UART is already stopped -void end_when_stopped_test(void) { +void end_when_stopped_test() { log_d("Trying to end serial twice"); // Calling end(true) twice should not crash - stop_serial(true); - stop_serial(true); + stop_serial(); + stop_serial(); Serial.println("End when stopped test successful"); } // This test checks if all the UART methods work when the UART is running -void enabled_uart_calls_test(void) { +void enabled_uart_calls_test() { bool boolean_ret; long int integer_ret; uint8_t test_buf[1]; @@ -350,7 +245,7 @@ void enabled_uart_calls_test(void) { } // This test checks if all the UART methods work when the UART is stopped -void disabled_uart_calls_test(void) { +void disabled_uart_calls_test() { bool boolean_ret; int integer_ret; uint8_t test_buf[1]; @@ -422,100 +317,37 @@ void disabled_uart_calls_test(void) { } // This test checks if the pins can be changed and if the message can be transmitted and received correctly after the change -void change_pins_test(void) { +void change_pins_test() { //stop_serial(); log_d("Disabling UART loopback"); - -#if SOC_UART_HP_NUM == 2 - esp_rom_gpio_connect_out_signal(SOC_RX0, SIG_GPIO_OUT_IDX, false, false); -#elif SOC_UART_HP_NUM >= 3 - esp_rom_gpio_connect_out_signal(RX1, SIG_GPIO_OUT_IDX, false, false); - esp_rom_gpio_connect_out_signal(RX2, SIG_GPIO_OUT_IDX, false, false); -#endif + uart_internal_loopback(0, false); log_d("Swapping UART pins"); -#if SOC_UART_HP_NUM == 2 Serial1.setPins(NEW_RX1, NEW_TX1); TEST_ASSERT_EQUAL(NEW_RX1, uart_get_RxPin(1)); TEST_ASSERT_EQUAL(NEW_TX1, uart_get_TxPin(1)); -#elif SOC_UART_HP_NUM >= 3 - Serial1.setPins(RX2, TX2); - Serial2.setPins(RX1, TX1); - TEST_ASSERT_EQUAL(RX2, uart_get_RxPin(1)); - TEST_ASSERT_EQUAL(TX2, uart_get_TxPin(1)); - TEST_ASSERT_EQUAL(RX1, uart_get_RxPin(2)); - TEST_ASSERT_EQUAL(TX1, uart_get_TxPin(2)); -#endif - start_serial(115200); + start_serial1(115200); log_d("Re-enabling UART loopback"); -#if SOC_UART_HP_NUM == 2 - uart_internal_loopback(1, NEW_RX1); -#elif SOC_UART_HP_NUM >= 3 - uart_internal_loopback(1, RX1); - uart_internal_loopback(2, RX2); -#endif + uart_internal_loopback(1, true); transmit_and_check_msg("using new pins"); Serial.println("Change pins test successful"); } -// This test checks if the auto baudrate detection works on ESP32 and ESP32-S2 -#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 -void auto_baudrate_test(void) { - log_d("Starting auto baudrate test"); - - HardwareSerial *selected_serial; - unsigned long baudrate; - - log_d("Stopping test serial. Using Serial2 for ESP32 and Serial1 for ESP32-S2."); - -#if SOC_UART_HP_NUM == 2 - selected_serial = &Serial1; - uart_internal_loopback(0, RX1); -#elif SOC_UART_HP_NUM >= 3 - selected_serial = &Serial2; -#endif - - //selected_serial->end(false); - - log_d("Starting delayed task to send message"); - - xTaskCreate(task_delayed_msg, "task_delayed_msg", 2048, NULL, 2, NULL); - - log_d("Starting serial with auto baudrate detection"); - - selected_serial->begin(0); - baudrate = selected_serial->baudRate(); - -#if SOC_UART_HP_NUM == 2 - Serial.end(); - Serial.begin(115200); -#endif - - TEST_ASSERT_UINT_WITHIN(2304, 115200, baudrate); - - Serial.println("Auto baudrate test successful"); -} -#endif - // This test checks if the peripheral manager can properly manage UART pins -void periman_test(void) { +void periman_test() { log_d("Checking if peripheral manager can properly manage UART pins"); log_d("Setting up I2C on the same pins as UART"); Wire.begin(RX1, TX1); -#if SOC_UART_HP_NUM >= 3 - Wire1.begin(RX2, TX2); -#endif - recv_msg = ""; log_d("Trying to send message using UART with I2C enabled"); @@ -525,14 +357,7 @@ void periman_test(void) { log_d("Disabling I2C and re-enabling UART"); Serial1.setPins(RX1, TX1); - -#if SOC_UART_HP_NUM >= 3 - Serial2.setPins(RX2, TX2); - uart_internal_loopback(1, RX2); - uart_internal_loopback(2, RX1); -#elif SOC_UART_HP_NUM == 2 - uart_internal_loopback(1, RX1); -#endif + uart_internal_loopback(1, true); log_d("Trying to send message using UART with I2C disabled"); transmit_and_check_msg("while I2C is disabled"); @@ -541,7 +366,7 @@ void periman_test(void) { } // This test checks if messages can be transmitted and received correctly after changing the CPU frequency -void change_cpu_frequency_test(void) { +void change_cpu_frequency_test() { uint32_t old_freq = getCpuFrequencyMhz(); uint32_t new_freq = getXtalFrequencyMhz(); @@ -549,7 +374,7 @@ void change_cpu_frequency_test(void) { Serial.flush(); setCpuFrequencyMhz(new_freq); - Serial.updateBaudRate(115200); + Serial1.updateBaudRate(115200); log_d("Trying to send message with the new CPU frequency"); transmit_and_check_msg("with new CPU frequency"); @@ -558,7 +383,7 @@ void change_cpu_frequency_test(void) { Serial.flush(); setCpuFrequencyMhz(old_freq); - Serial.updateBaudRate(115200); + Serial1.updateBaudRate(115200); log_d("Trying to send message with the original CPU frequency"); transmit_and_check_msg("with the original CPU frequency"); @@ -573,33 +398,6 @@ void setup() { while (!Serial) { delay(10); } - log_d("SOC_UART_HP_NUM = %d", SOC_UART_HP_NUM); - - // Begin needs to be called before setting up the loopback because it creates the serial object - start_serial(115200); - -#if SOC_UART_HP_NUM == 2 - log_d("Setup internal loop-back from and back to Serial1 (UART1) TX >> Serial1 (UART1) RX"); - - Serial1.onReceive([]() { - onReceive_cb(Serial1); - }); - uart_internal_loopback(1, RX1); -#elif SOC_UART_HP_NUM >= 3 - log_d("Setup internal loop-back between Serial1 (UART1) <<--->> Serial2 (UART2)"); - - Serial1.onReceive([]() { - onReceive_cb(Serial1); - }); - Serial2.onReceive([]() { - onReceive_cb(Serial2); - }); - uart_internal_loopback(1, RX2); - uart_internal_loopback(2, RX1); -#endif - - log_d("Setup done. Starting tests"); - UNITY_BEGIN(); RUN_TEST(begin_when_running_test); RUN_TEST(basic_transmission_test); @@ -608,9 +406,6 @@ void setup() { RUN_TEST(change_cpu_frequency_test); RUN_TEST(disabled_uart_calls_test); RUN_TEST(enabled_uart_calls_test); -#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 - RUN_TEST(auto_baudrate_test); -#endif RUN_TEST(periman_test); RUN_TEST(change_pins_test); RUN_TEST(end_when_stopped_test);