Skip to content

Commit 6be85a3

Browse files
authored
fix(uart_ci): fixes the UART CI sketch due to IDF 5.3 pull up change
1 parent e6a0b20 commit 6be85a3

File tree

1 file changed

+73
-80
lines changed

1 file changed

+73
-80
lines changed

tests/validation/uart/uart.ino

+73-80
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/* UART test
2-
*
3-
* This test is using UART0 (Serial) only for reporting test status and helping with the auto
4-
* baudrate detection test.
5-
* The other serials are used for testing.
6-
*/
2+
3+
This test is using UART0 (Serial) only for reporting test status and helping with the auto
4+
baudrate detection test.
5+
The other serials are used for testing.
6+
*/
77

88
// Default pins:
99
// | Name | ESP32 | S2 | S3 | C3 | C6 | H2 | P4 |
@@ -15,18 +15,18 @@
1515
// UART2 TX | TX2 | 25 | -- | 20 | -- | -- | -- | -- |
1616

1717
/*
18-
* For each UART:
19-
*
20-
* terminal
21-
* | ^
22-
* v UART0 |
23-
* RX ^ TX
24-
* |
25-
* report status
26-
* |
27-
* TX <---> RX
28-
* UARTx
29-
*/
18+
For each UART:
19+
20+
terminal
21+
| ^
22+
v UART0 |
23+
RX ^ TX
24+
|
25+
report status
26+
|
27+
TX <---> RX
28+
UARTx
29+
*/
3030

3131
#include <vector>
3232
#include <unity.h>
@@ -41,56 +41,58 @@
4141
/* Utility classes */
4242

4343
class UARTTestConfig {
44-
public:
45-
int uart_num;
46-
HardwareSerial &serial;
47-
int peeked_char;
48-
int8_t default_rx_pin;
49-
int8_t default_tx_pin;
50-
String recv_msg;
51-
52-
UARTTestConfig(int num, HardwareSerial &serial_ref, int8_t rx_pin, int8_t tx_pin)
53-
: uart_num(num), serial(serial_ref), peeked_char(-1), default_rx_pin(rx_pin), default_tx_pin(tx_pin), recv_msg("") {}
54-
55-
void begin(unsigned long baudrate) {
56-
serial.begin(baudrate, SERIAL_8N1, default_rx_pin, default_tx_pin);
57-
while (!serial) {
58-
delay(10);
44+
public:
45+
int uart_num;
46+
HardwareSerial &serial;
47+
int peeked_char;
48+
int8_t default_rx_pin;
49+
int8_t default_tx_pin;
50+
String recv_msg;
51+
52+
UARTTestConfig(int num, HardwareSerial &serial_ref, int8_t rx_pin, int8_t tx_pin)
53+
: uart_num(num), serial(serial_ref), peeked_char(-1), default_rx_pin(rx_pin), default_tx_pin(tx_pin), recv_msg("") {}
54+
55+
void begin(unsigned long baudrate) {
56+
// pinMode will force enabing the internal pullup resistor (IDF 5.3.2 Change)
57+
pinMode(default_rx_pin, INPUT_PULLUP);
58+
serial.begin(baudrate, SERIAL_8N1, default_rx_pin, default_tx_pin);
59+
while (!serial) {
60+
delay(10);
61+
}
5962
}
60-
}
6163

62-
void end() {
63-
serial.end();
64-
}
65-
66-
void reset_buffers() {
67-
recv_msg = "";
68-
peeked_char = -1;
69-
}
64+
void end() {
65+
serial.end();
66+
}
7067

71-
void transmit_and_check_msg(const String &msg_append, bool perform_assert = true) {
72-
reset_buffers();
73-
delay(100);
74-
serial.print("Hello from Serial" + String(uart_num) + " " + msg_append);
75-
serial.flush();
76-
delay(100);
77-
if (perform_assert) {
78-
TEST_ASSERT_EQUAL_STRING(("Hello from Serial" + String(uart_num) + " " + msg_append).c_str(), recv_msg.c_str());
79-
log_d("UART%d received message: %s\n", uart_num, recv_msg.c_str());
68+
void reset_buffers() {
69+
recv_msg = "";
70+
peeked_char = -1;
8071
}
81-
}
8272

83-
void onReceive() {
84-
char c;
85-
size_t available = serial.available();
86-
if (peeked_char == -1) {
87-
peeked_char = serial.peek();
73+
void transmit_and_check_msg(const String &msg_append, bool perform_assert = true) {
74+
reset_buffers();
75+
delay(100);
76+
serial.print("Hello from Serial" + String(uart_num) + " " + msg_append);
77+
serial.flush();
78+
delay(100);
79+
if (perform_assert) {
80+
TEST_ASSERT_EQUAL_STRING(("Hello from Serial" + String(uart_num) + " " + msg_append).c_str(), recv_msg.c_str());
81+
log_d("UART%d received message: %s\n", uart_num, recv_msg.c_str());
82+
}
8883
}
89-
while (available--) {
90-
c = (char)serial.read();
91-
recv_msg += c;
84+
85+
void onReceive() {
86+
char c;
87+
size_t available = serial.available();
88+
if (peeked_char == -1) {
89+
peeked_char = serial.peek();
90+
}
91+
while (available--) {
92+
c = (char)serial.read();
93+
recv_msg += c;
94+
}
9295
}
93-
}
9496
};
9597

9698
/* Utility global variables */
@@ -365,30 +367,27 @@ void change_pins_test(void) {
365367

366368
if (TEST_UART_NUM == 1) {
367369
UARTTestConfig &config = *uart_test_configs[0];
368-
// internal loopback creates a BREAK on ESP32 and ESP32-S2
369-
// setting it before changing the pins solves it
370-
uart_internal_loopback(config.uart_num, NEW_RX1);
371-
delay(5); // wait for internal circuit to settle
370+
// pinMode will force enabing the internal pullup resistor (IDF 5.3.2 Change)
371+
pinMode(NEW_RX1, INPUT_PULLUP);
372372
config.serial.setPins(NEW_RX1, NEW_TX1);
373373
TEST_ASSERT_EQUAL(NEW_RX1, uart_get_RxPin(config.uart_num));
374374
TEST_ASSERT_EQUAL(NEW_TX1, uart_get_TxPin(config.uart_num));
375-
config.transmit_and_check_msg("using new UART#1 pins");
375+
376+
uart_internal_loopback(config.uart_num, NEW_RX1);
377+
config.transmit_and_check_msg("using new pins");
376378
} else {
377379
for (int i = 0; i < TEST_UART_NUM; i++) {
378380
UARTTestConfig &config = *uart_test_configs[i];
379381
UARTTestConfig &next_uart = *uart_test_configs[(i + 1) % TEST_UART_NUM];
380-
// internal loopback creates a BREAK on ESP32 and ESP32-S2
381-
// setting it before changing the pins solves it
382-
uart_internal_loopback(config.uart_num, next_uart.default_rx_pin);
383-
delay(5); // wait for internal circuit to settle
384382
config.serial.setPins(next_uart.default_rx_pin, next_uart.default_tx_pin);
385383
TEST_ASSERT_EQUAL(uart_get_RxPin(config.uart_num), next_uart.default_rx_pin);
386384
TEST_ASSERT_EQUAL(uart_get_TxPin(config.uart_num), next_uart.default_tx_pin);
387-
String msg = String("using UART#") + config.uart_num + " pins";
388-
config.transmit_and_check_msg(msg.c_str());
385+
386+
uart_internal_loopback(config.uart_num, next_uart.default_rx_pin);
387+
config.transmit_and_check_msg("using new pins");
389388
}
390389
}
391-
390+
392391
Serial.println("Change pins test successful");
393392
}
394393

@@ -443,23 +442,17 @@ void periman_test(void) {
443442

444443
for (auto *ref : uart_test_configs) {
445444
UARTTestConfig &config = *ref;
446-
//Wire.begin(config.default_rx_pin, config.default_tx_pin);
447-
pinMode(config.default_rx_pin, INPUT);
448-
pinMode(config.default_tx_pin, OUTPUT);
449-
445+
Wire.begin(config.default_rx_pin, config.default_tx_pin);
450446
config.recv_msg = "";
451447

452448
log_d("Trying to send message using UART%d with I2C enabled", config.uart_num);
453449
config.transmit_and_check_msg("while used by I2C", false);
454450
TEST_ASSERT_EQUAL_STRING("", config.recv_msg.c_str());
455451

456452
log_d("Disabling I2C and re-enabling UART%d", config.uart_num);
453+
config.serial.setPins(config.default_rx_pin, config.default_tx_pin);
457454

458-
// internal loopback creates a BREAK on ESP32 and ESP32-S2
459-
// setting it before changing the pins solves it
460455
uart_internal_loopback(config.uart_num, config.default_rx_pin);
461-
delay(5); // wait for internal circuit to settle
462-
config.serial.setPins(config.default_rx_pin, config.default_tx_pin);
463456

464457
log_d("Trying to send message using UART%d with I2C disabled", config.uart_num);
465458
config.transmit_and_check_msg("while I2C is disabled");

0 commit comments

Comments
 (0)