Skip to content

Commit ef870bf

Browse files
authored
Merge branch 'micropython:master' into esp32_bitstream
2 parents 4a81817 + c7c0ad2 commit ef870bf

File tree

20 files changed

+177
-170
lines changed

20 files changed

+177
-170
lines changed

ports/alif/tinyusb_port/tusb_alif_dcd.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,11 @@ void dcd_set_address(uint8_t rhport, uint8_t dev_addr)
249249
{
250250
LOG("%010u >%s", DWT->CYCCNT, __func__);
251251

252-
udev->dcfg_b.devaddr = dev_addr;
252+
// Device address is set from the ISR when SETUP packet is received
253+
// By point TinyUSB calls this function, the address has already been
254+
// set and STATUS sent back to the host. Xfer call below is purely for
255+
// internal TinyUSB state to conclude transaction and issue next SETUP req.
256+
253257
dcd_edpt_xfer(rhport, tu_edpt_addr(0, TUSB_DIR_IN), NULL, 0);
254258
}
255259

@@ -571,6 +575,9 @@ static void _dcd_handle_depevt(uint8_t ep, uint8_t evt, uint8_t sts, uint16_t pa
571575

572576
// XferNotReady NotActive for status stage
573577
if ((1 == ep) && (0b0010 == (sts & 0b1011))) {
578+
if (0x00 == _ctrl_buf[0] && TUSB_REQ_SET_ADDRESS == _ctrl_buf[1]) {
579+
udev->dcfg_b.devaddr = _ctrl_buf[2];
580+
}
574581
_dcd_start_xfer(1, NULL, 0, TRBCTL_CTL_STAT2);
575582
break;
576583
}

ports/zephyr/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ project(micropython)
3030
set(MICROPY_PORT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
3131
set(MICROPY_DIR ${MICROPY_PORT_DIR}/../..)
3232
set(MICROPY_TARGET micropython)
33+
string(TOUPPER ZEPHYR_${BOARD} MICROPY_BOARD)
3334

3435
include(${MICROPY_DIR}/py/py.cmake)
3536
include(${MICROPY_DIR}/extmod/extmod.cmake)

tests/extmod/machine_uart_irq_txidle.py

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,7 @@
1010
raise SystemExit
1111

1212
import time, sys
13-
14-
# Configure pins based on the target.
15-
if "alif" in sys.platform:
16-
uart_id = 1
17-
tx_pin = None
18-
elif "rp2" in sys.platform:
19-
uart_id = 0
20-
tx_pin = "GPIO0"
21-
rx_pin = "GPIO1"
22-
elif "samd" in sys.platform and "ItsyBitsy M0" in sys.implementation._machine:
23-
uart_id = 0
24-
tx_pin = "D1"
25-
rx_pin = "D0"
26-
elif "samd" in sys.platform and "ItsyBitsy M4" in sys.implementation._machine:
27-
uart_id = 3
28-
tx_pin = "D1"
29-
rx_pin = "D0"
30-
elif "mimxrt" in sys.platform:
31-
uart_id = 1
32-
tx_pin = None
33-
elif "nrf" in sys.platform:
34-
uart_id = 0
35-
tx_pin = None
36-
else:
37-
print("Please add support for this test on this platform.")
38-
raise SystemExit
13+
from target_wiring import uart_loopback_args, uart_loopback_kwargs
3914

4015

4116
def irq(u):
@@ -46,11 +21,7 @@ def irq(u):
4621

4722
# Test that the IRQ is called after the write has completed.
4823
for bits_per_s in (2400, 9600, 115200):
49-
if tx_pin is None:
50-
uart = UART(uart_id, bits_per_s)
51-
else:
52-
uart = UART(uart_id, bits_per_s, tx=tx_pin, rx=rx_pin)
53-
24+
uart = UART(*uart_loopback_args, baudrate=bits_per_s, **uart_loopback_kwargs)
5425
uart.irq(irq, uart.IRQ_TXIDLE)
5526

5627
# The IRQ_TXIDLE shall trigger after the message has been sent. Thus

tests/extmod/machine_uart_tx.py

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,50 +8,35 @@
88
raise SystemExit
99

1010
import time, sys
11+
from target_wiring import uart_loopback_args, uart_loopback_kwargs
1112

1213
initial_delay_ms = 0
1314
bit_margin = 0
1415
timing_margin_us = 100
1516

16-
# Configure pins based on the target.
17+
# Tune test parameters based on the target.
1718
if "alif" in sys.platform:
18-
uart_id = 1
19-
pins = {}
2019
bit_margin = 1
2120
elif "esp32" in sys.platform:
22-
uart_id = 1
23-
pins = {}
2421
timing_margin_us = 400
2522
elif "mimxrt" in sys.platform:
26-
uart_id = 1
27-
pins = {}
2823
initial_delay_ms = 20 # UART sends idle frame after init, so wait for that
2924
bit_margin = 1
25+
elif "nrf" in sys.platform:
26+
timing_margin_us = 130
3027
elif "pyboard" in sys.platform:
31-
if "STM32WB" in sys.implementation._machine:
32-
uart_id = "LP1"
33-
else:
34-
uart_id = 4
35-
pins = {}
3628
initial_delay_ms = 50 # UART sends idle frame after init, so wait for that
3729
bit_margin = 1 # first start-bit must wait to sync with the UART clock
3830
elif "rp2" in sys.platform:
39-
uart_id = 0
40-
pins = {"tx": "GPIO0", "rx": "GPIO1"}
4131
timing_margin_us = 180
4232
elif "samd" in sys.platform:
43-
uart_id = 2
44-
pins = {"tx": "D1", "rx": "D0"}
4533
timing_margin_us = 300
4634
bit_margin = 1
47-
else:
48-
print("SKIP")
49-
raise SystemExit
5035

5136
# Test that write+flush takes the expected amount of time to execute.
5237
for bits_per_s in (2400, 9600, 115200):
5338
text = "Hello World"
54-
uart = UART(uart_id, bits_per_s, bits=8, parity=None, stop=1, **pins)
39+
uart = UART(*uart_loopback_args, baudrate=bits_per_s, **uart_loopback_kwargs)
5540
time.sleep_ms(initial_delay_ms)
5641

5742
start_us = time.ticks_us()

tests/extmod_hardware/machine_uart_irq_break.py

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,7 @@
1212
raise SystemExit
1313

1414
import time, sys
15-
16-
# Configure pins based on the target.
17-
if "esp32" in sys.platform:
18-
_machine = sys.implementation._machine
19-
if "ESP32S2" in _machine or "ESP32C3" in _machine or "ESP32C6" in _machine:
20-
print("SKIP")
21-
raise SystemExit
22-
uart_id = 1
23-
tx_pin = 4
24-
rx_pin = 5
25-
elif "rp2" in sys.platform:
26-
uart_id = 0
27-
tx_pin = "GPIO0"
28-
rx_pin = "GPIO1"
29-
else:
30-
print("Please add support for this test on this platform.")
31-
raise SystemExit
15+
from target_wiring import uart_loopback_args, uart_loopback_kwargs
3216

3317

3418
def irq(u):
@@ -37,7 +21,7 @@ def irq(u):
3721

3822
# Test that the IRQ is called for each break received.
3923
for bits_per_s in (2400, 9600, 57600):
40-
uart = UART(uart_id, bits_per_s, tx=tx_pin, rx=rx_pin)
24+
uart = UART(*uart_loopback_args, baudrate=bits_per_s, **uart_loopback_kwargs)
4125
uart.irq(irq, uart.IRQ_BREAK)
4226

4327
print("write", bits_per_s)

tests/extmod_hardware/machine_uart_irq_rx.py

Lines changed: 6 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -13,49 +13,14 @@
1313

1414
import time, sys
1515

16-
byte_by_byte = False
17-
# Configure pins based on the target.
18-
if "alif" in sys.platform:
19-
uart_id = 1
20-
tx_pin = None
21-
rx_pin = None
22-
elif "esp32" in sys.platform:
23-
uart_id = 1
24-
tx_pin = 4
25-
rx_pin = 5
26-
elif "pyboard" in sys.platform:
27-
if "STM32WB" in sys.implementation._machine:
28-
# LPUART(1) is on PA2/PA3
29-
uart_id = "LP1"
30-
else:
31-
# UART(4) is on PA0/PA1
32-
uart_id = 4
33-
tx_pin = None
34-
rx_pin = None
35-
elif "samd" in sys.platform and "ItsyBitsy M0" in sys.implementation._machine:
36-
uart_id = 0
37-
tx_pin = "D1"
38-
rx_pin = "D0"
39-
byte_by_byte = True
40-
elif "samd" in sys.platform and "ItsyBitsy M4" in sys.implementation._machine:
41-
uart_id = 3
42-
tx_pin = "D1"
43-
rx_pin = "D0"
44-
elif "nrf" in sys.platform:
45-
uart_id = 0
46-
tx_pin = None
47-
rx_pin = None
48-
elif "renesas-ra" in sys.platform:
49-
uart_id = 9
50-
tx_pin = None # P602 @ RA6M2
51-
rx_pin = None # P601 @ RA6M2
52-
elif "CC3200" in sys.implementation._machine:
16+
if "CC3200" in sys.implementation._machine:
5317
# CC3200 doesn't work because it's too slow and has an allocation error in the handler.
5418
print("SKIP")
5519
raise SystemExit
56-
else:
57-
print("Please add support for this test on this platform.")
58-
raise SystemExit
20+
21+
from target_wiring import uart_loopback_args, uart_loopback_kwargs
22+
23+
byte_by_byte = "ItsyBitsy M0" in sys.implementation._machine
5924

6025

6126
def irq(u):
@@ -67,11 +32,7 @@ def irq(u):
6732
# Test that the IRQ is called for each byte received.
6833
# Use slow baudrates so that the IRQ has time to run.
6934
for bits_per_s in (2400, 9600):
70-
if tx_pin is None:
71-
uart = UART(uart_id, bits_per_s)
72-
else:
73-
uart = UART(uart_id, bits_per_s, tx=tx_pin, rx=rx_pin)
74-
35+
uart = UART(*uart_loopback_args, baudrate=bits_per_s, **uart_loopback_kwargs)
7536
uart.irq(irq, uart.IRQ_RX)
7637

7738
print("write", bits_per_s)

tests/extmod_hardware/machine_uart_irq_rxidle.py

Lines changed: 3 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -12,52 +12,10 @@
1212
raise SystemExit
1313

1414
import time, sys
15+
from target_wiring import uart_loopback_args, uart_loopback_kwargs
1516

1617
# Target tuning options.
17-
tune_wait_initial_rxidle = False
18-
19-
# Configure pins based on the target.
20-
if "alif" in sys.platform:
21-
uart_id = 1
22-
tx_pin = None
23-
rx_pin = None
24-
elif "esp32" in sys.platform:
25-
uart_id = 1
26-
tx_pin = 4
27-
rx_pin = 5
28-
elif "mimxrt" in sys.platform:
29-
uart_id = 1
30-
tx_pin = None
31-
elif "pyboard" in sys.platform:
32-
tune_wait_initial_rxidle = True
33-
if "STM32WB" in sys.implementation._machine:
34-
# LPUART(1) is on PA2/PA3
35-
uart_id = "LP1"
36-
else:
37-
# UART(4) is on PA0/PA1
38-
uart_id = 4
39-
tx_pin = None
40-
rx_pin = None
41-
elif "renesas-ra" in sys.platform:
42-
uart_id = 9
43-
tx_pin = None # P602 @ RA6M2
44-
rx_pin = None # P601 @ RA6M2
45-
elif "rp2" in sys.platform:
46-
uart_id = 0
47-
tx_pin = "GPIO0"
48-
rx_pin = "GPIO1"
49-
elif "samd" in sys.platform and "ItsyBitsy M0" in sys.implementation._machine:
50-
uart_id = 0
51-
tx_pin = "D1"
52-
rx_pin = "D0"
53-
byte_by_byte = True
54-
elif "samd" in sys.platform and "ItsyBitsy M4" in sys.implementation._machine:
55-
uart_id = 3
56-
tx_pin = "D1"
57-
rx_pin = "D0"
58-
else:
59-
print("Please add support for this test on this platform.")
60-
raise SystemExit
18+
tune_wait_initial_rxidle = sys.platform == "pyboard"
6119

6220

6321
def irq(u):
@@ -71,10 +29,7 @@ def irq(u):
7129
print("========")
7230
print("bits_per_s:", bits_per_s)
7331

74-
if tx_pin is None:
75-
uart = UART(uart_id, bits_per_s)
76-
else:
77-
uart = UART(uart_id, bits_per_s, tx=tx_pin, rx=rx_pin)
32+
uart = UART(*uart_loopback_args, baudrate=bits_per_s, **uart_loopback_kwargs)
7833

7934
# Ignore a possible initial RXIDLE condition after creating UART.
8035
if tune_wait_initial_rxidle:

tests/feature_check/target_info.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"xtensawin",
2121
"rv32imc",
2222
][sys_mpy >> 10]
23+
build = getattr(sys.implementation, "_build", "unknown")
2324
thread = getattr(sys.implementation, "_thread", None)
2425

2526
# Detect how many bits of precision the floating point implementation has.
@@ -33,4 +34,4 @@
3334
except NameError:
3435
float_prec = 0
3536

36-
print(platform, arch, thread, float_prec, len("α") == 1)
37+
print(platform, arch, build, thread, float_prec, len("α") == 1)

tests/ports/rp2/rp2_lightsleep_thread.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
SLEEP_MS = 250
1010

1111
IDEAL_RUNTIME = N_SLEEPS * SLEEP_MS
12+
MIN_RUNTIME = 2 * SLEEP_MS
1213
MAX_RUNTIME = (N_SLEEPS + 1) * SLEEP_MS
1314
MAX_DELTA = 20
1415

@@ -52,14 +53,17 @@ def test_cpu0_also_lightsleep(self):
5253
# is unspecified.
5354
#
5455
# Currently, the other thread will return immediately if one is already
55-
# in lightsleep. Therefore, runtime can be between IDEAL_RUNTIME and
56-
# IDEAL_RUNTIME * 2 depending on how many times the calls to lightsleep() race
57-
# each other.
56+
# in lightsleep doing set up, or waking up. When a thread is actually in the
57+
# sleep section of lightsleep, the CPU clock is stopped and that also stops
58+
# the other thread. It's possible for the total sleep time of this test to
59+
# be less than IDEAL_RUNTIME due to the order in which each thread gets to go
60+
# to sleep first and whether the other thread is paused before or after it
61+
# tries to enter lightsleep itself.
5862
#
5963
# Note this test case is really only here to ensure that the rp2 hasn't
6064
# hung or failed to sleep at all - not to verify any correct behaviour
6165
# when there's a race to call lightsleep().
62-
self.assertGreaterEqual(self.elapsed_ms(), IDEAL_RUNTIME - MAX_DELTA)
66+
self.assertGreaterEqual(self.elapsed_ms(), MIN_RUNTIME - MAX_DELTA)
6367
self.assertLessEqual(self.elapsed_ms(), IDEAL_RUNTIME * 2 + MAX_DELTA)
6468

6569

0 commit comments

Comments
 (0)