Skip to content

Commit b680011

Browse files
committed
tests/ports/stm32: Tweak tests to run on a wider set of boards.
There should be no change to these tests for existing PYBV1x and PYBD_SFx boards. Signed-off-by: Damien George <damien@micropython.org>
1 parent 29b5c22 commit b680011

File tree

15 files changed

+96
-37
lines changed

15 files changed

+96
-37
lines changed

tests/ports/stm32/adc.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
import sys
12
from pyb import ADC, Timer
23

4+
if "STM32WB" in sys.implementation._machine:
5+
print("SKIP")
6+
raise SystemExit
7+
38
adct = ADC(16) # Temperature 930 -> 20C
49
print(str(adct)[:19])
510
adcv = ADC(17) # Voltage 1500 -> 3.3V

tests/ports/stm32/adcall.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1+
import sys
12
from pyb import Pin, ADCAll
23

4+
if "STM32WB" in sys.implementation._machine:
5+
pa0_adc_channel = 5
6+
skip_temp_test = True # temperature fails on WB55
7+
else:
8+
pa0_adc_channel = 0
9+
skip_temp_test = False
10+
311
pins = [Pin.cpu.A0, Pin.cpu.A1, Pin.cpu.A2, Pin.cpu.A3]
412

513
# set pins to IN mode, init ADCAll, then check pins are ANALOG
@@ -12,7 +20,7 @@
1220
# set pins to IN mode, init ADCAll with mask, then check some pins are ANALOG
1321
for p in pins:
1422
p.init(p.IN)
15-
adc = ADCAll(12, 0x70003)
23+
adc = ADCAll(12, 0x70000 | 3 << pa0_adc_channel)
1624
for p in pins:
1725
print(p)
1826

@@ -25,7 +33,11 @@
2533
print(type(adc.read_channel(c)))
2634

2735
# call special reading functions
28-
print(0 < adc.read_core_temp() < 100)
36+
print(skip_temp_test or 0 < adc.read_core_temp() < 100)
2937
print(0 < adc.read_core_vbat() < 4)
3038
print(0 < adc.read_core_vref() < 2)
3139
print(0 < adc.read_vref() < 4)
40+
41+
if sys.implementation._build == "NUCLEO_WB55":
42+
# Restore button pin settings.
43+
Pin("SW", Pin.IN, Pin.PULL_UP)

tests/ports/stm32/extint.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import pyb
22

33
# test basic functionality
4-
ext = pyb.ExtInt("X5", pyb.ExtInt.IRQ_RISING, pyb.Pin.PULL_DOWN, lambda l: print("line:", l))
4+
pin = pyb.Pin.cpu.A4
5+
ext = pyb.ExtInt(pin, pyb.ExtInt.IRQ_RISING, pyb.Pin.PULL_DOWN, lambda l: print("line:", l))
56
ext.disable()
67
ext.enable()
78
print(ext.line())

tests/ports/stm32/i2c.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
import pyb
2-
from pyb import I2C
1+
try:
2+
from pyb import I2C
3+
except ImportError:
4+
print("SKIP")
5+
raise SystemExit
36

47
# test we can correctly create by id
58
for bus in (-1, 0, 1):

tests/ports/stm32/i2c_accel.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
# use accelerometer to test i2c bus
22

3-
import pyb
4-
from pyb import I2C
5-
6-
if not hasattr(pyb, "Accel"):
3+
try:
4+
from pyb import Accel, I2C
5+
except ImportError:
76
print("SKIP")
87
raise SystemExit
98

109
accel_addr = 76
1110

12-
pyb.Accel() # this will init the MMA for us
11+
Accel() # this will init the MMA for us
1312

1413
i2c = I2C(1, I2C.CONTROLLER, baudrate=400000)
1514

tests/ports/stm32/i2c_error.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# test I2C errors, with polling (disabled irqs) and DMA
22

33
import pyb
4-
from pyb import I2C
54

65
if not hasattr(pyb, "Accel"):
76
print("SKIP")
87
raise SystemExit
98

9+
from pyb import I2C
10+
1011
# init accelerometer
1112
pyb.Accel()
1213

tests/ports/stm32/irq.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import time
12
import pyb
23

34

@@ -8,7 +9,7 @@ def test_irq():
89
pyb.enable_irq() # by default should enable IRQ
910

1011
# check that interrupts are enabled by waiting for ticks
11-
pyb.delay(10)
12+
time.sleep_ms(10)
1213

1314
# check nested disable/enable
1415
i1 = pyb.disable_irq()
@@ -18,7 +19,7 @@ def test_irq():
1819
pyb.enable_irq(i1)
1920

2021
# check that interrupts are enabled by waiting for ticks
21-
pyb.delay(10)
22+
time.sleep_ms(10)
2223

2324

2425
test_irq()

tests/ports/stm32/modstm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# test stm module
22

33
import stm
4-
import pyb
4+
import time
55

66
# test storing a full 32-bit number
77
# turn on then off the A15(=yellow) LED
88
BSRR = 0x18
99
stm.mem32[stm.GPIOA + BSRR] = 0x00008000
10-
pyb.delay(100)
10+
time.sleep_ms(100)
1111
print(hex(stm.mem32[stm.GPIOA + stm.GPIO_ODR] & 0x00008000))
1212
stm.mem32[stm.GPIOA + BSRR] = 0x80000000
1313
print(hex(stm.mem32[stm.GPIOA + stm.GPIO_ODR] & 0x00008000))

tests/ports/stm32/pin.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1+
import sys
12
from pyb import Pin
23

3-
p = Pin("X8", Pin.IN)
4+
if "PYB" in sys.implementation._machine:
5+
test_pin = "X8"
6+
else:
7+
test_pin = Pin.cpu.A7
8+
9+
p = Pin(test_pin, Pin.IN)
410
print(p)
511
print(p.name())
612
print(p.pin())
713
print(p.port())
814

9-
p = Pin("X8", Pin.IN, Pin.PULL_UP)
10-
p = Pin("X8", Pin.IN, pull=Pin.PULL_UP)
11-
p = Pin("X8", mode=Pin.IN, pull=Pin.PULL_UP)
15+
p = Pin(test_pin, Pin.IN, Pin.PULL_UP)
16+
p = Pin(test_pin, Pin.IN, pull=Pin.PULL_UP)
17+
p = Pin(test_pin, mode=Pin.IN, pull=Pin.PULL_UP)
1218
print(p)
1319
print(p.value())
1420

tests/ports/stm32/pyb1.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
import pyb
44

5+
if not hasattr(pyb, "delay"):
6+
print("SKIP")
7+
raise SystemExit
8+
59
# test delay
610

711
pyb.delay(-1)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy