Skip to content

Commit 3f54e5d

Browse files
committed
tests/extmod: Support esp32,mimxrt,stm32,samd ports in UART TX test.
Getting this test running on stm32- and mimxrt-based boards requires adding a small delay after constructing the UART so that the initial idle frame has time to be transmitted before the test starts. Also, the timing margin needs to account for an additional 1-bit worth of time on some MCUs. Thanks to @robert-hh for the esp32, mimxrt and samd settings. Signed-off-by: Damien George <[email protected]>
1 parent 6328958 commit 3f54e5d

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

tests/extmod/machine_uart_tx.py

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,43 @@
99

1010
import time, sys
1111

12+
initial_delay_ms = 0
13+
bit_margin = 0
14+
timing_margin_us = 100
15+
1216
# Configure pins based on the target.
13-
if "rp2" in sys.platform:
17+
if "esp32" in sys.platform:
18+
uart_id = 1
19+
pins = {}
20+
timing_margin_us = 400
21+
elif "mimxrt" in sys.platform:
22+
uart_id = 1
23+
pins = {}
24+
initial_delay_ms = 20 # UART sends idle frame after init, so wait for that
25+
bit_margin = 1
26+
elif "pyboard" in sys.platform:
27+
uart_id = 4
28+
pins = {}
29+
initial_delay_ms = 50 # UART sends idle frame after init, so wait for that
30+
bit_margin = 1 # first start-bit must wait to sync with the UART clock
31+
elif "rp2" in sys.platform:
1432
uart_id = 0
15-
tx_pin = "GPIO0"
16-
rx_pin = "GPIO1"
33+
pins = {"tx": "GPIO0", "rx": "GPIO1"}
1734
timing_margin_us = 180
35+
elif "samd" in sys.platform:
36+
uart_id = 2
37+
pins = {"tx": "D1", "rx": "D0"}
38+
timing_margin_us = 300
39+
bit_margin = 1
1840
else:
1941
print("SKIP")
2042
raise SystemExit
2143

2244
# Test that write+flush takes the expected amount of time to execute.
2345
for bits_per_s in (2400, 9600, 115200):
2446
text = "Hello World"
25-
uart = UART(uart_id, bits_per_s, bits=8, parity=None, stop=1, tx=tx_pin, rx=rx_pin)
47+
uart = UART(uart_id, bits_per_s, bits=8, parity=None, stop=1, **pins)
48+
time.sleep_ms(initial_delay_ms)
2649

2750
start_us = time.ticks_us()
2851
uart.write(text)
@@ -33,4 +56,5 @@
3356
bits_per_char = 10
3457
expect_us = (len(text)) * bits_per_char * 1_000_000 // bits_per_s
3558
delta_us = abs(duration_us - expect_us)
36-
print(bits_per_s, delta_us <= timing_margin_us or delta_us)
59+
margin_us = timing_margin_us + bit_margin * 1_000_000 // bits_per_s
60+
print(bits_per_s, delta_us <= margin_us or delta_us)

0 commit comments

Comments
 (0)