tests/pyb: Refactor pyboard tests to work on PYBv1, PYBLITEv1 and PYBD.
This commit is contained in:
parent
7280bf40d9
commit
4b184d1281
@ -1,5 +1,9 @@
|
||||
import pyb
|
||||
|
||||
if not hasattr(pyb, 'Accel'):
|
||||
print('SKIP')
|
||||
raise SystemExit
|
||||
|
||||
accel = pyb.Accel()
|
||||
print(accel)
|
||||
accel.x()
|
||||
|
@ -1,7 +1,7 @@
|
||||
from pyb import ADC, Timer
|
||||
|
||||
adct = ADC(16) # Temperature 930 -> 20C
|
||||
print(adct)
|
||||
print(str(adct)[:19])
|
||||
adcv = ADC(17) # Voltage 1500 -> 3.3V
|
||||
print(adcv)
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
<ADC on 16 channel=16>
|
||||
<ADC on 16 channel=
|
||||
<ADC on 17 channel=17>
|
||||
50
|
||||
25
|
||||
|
39
tests/pyb/board_pybv1x.py
Normal file
39
tests/pyb/board_pybv1x.py
Normal file
@ -0,0 +1,39 @@
|
||||
# Test board-specific items on PYBv1.x
|
||||
|
||||
import os, pyb
|
||||
|
||||
if not 'PYBv1.' in os.uname().machine:
|
||||
print('SKIP')
|
||||
raise SystemExit
|
||||
|
||||
# test creating UART by id/name
|
||||
for bus in (1, 2, 3, 4, 5, 6, 7, "XA", "XB", "YA", "YB", "Z"):
|
||||
try:
|
||||
pyb.UART(bus, 9600)
|
||||
print("UART", bus)
|
||||
except ValueError:
|
||||
print("ValueError", bus)
|
||||
|
||||
# test creating SPI by id/name
|
||||
for bus in (1, 2, 3, "X", "Y", "Z"):
|
||||
try:
|
||||
pyb.SPI(bus)
|
||||
print("SPI", bus)
|
||||
except ValueError:
|
||||
print("ValueError", bus)
|
||||
|
||||
# test creating I2C by id/name
|
||||
for bus in (2, 3, "X", "Y", "Z"):
|
||||
try:
|
||||
pyb.I2C(bus)
|
||||
print("I2C", bus)
|
||||
except ValueError:
|
||||
print("ValueError", bus)
|
||||
|
||||
# test creating CAN by id/name
|
||||
for bus in (1, 2, 3, "YA", "YB", "YC"):
|
||||
try:
|
||||
pyb.CAN(bus, pyb.CAN.LOOPBACK)
|
||||
print("CAN", bus)
|
||||
except ValueError:
|
||||
print("ValueError", bus)
|
29
tests/pyb/board_pybv1x.py.exp
Normal file
29
tests/pyb/board_pybv1x.py.exp
Normal file
@ -0,0 +1,29 @@
|
||||
UART 1
|
||||
UART 2
|
||||
UART 3
|
||||
UART 4
|
||||
ValueError 5
|
||||
UART 6
|
||||
ValueError 7
|
||||
UART XA
|
||||
UART XB
|
||||
UART YA
|
||||
UART YB
|
||||
ValueError Z
|
||||
SPI 1
|
||||
SPI 2
|
||||
ValueError 3
|
||||
SPI X
|
||||
SPI Y
|
||||
ValueError Z
|
||||
I2C 2
|
||||
ValueError 3
|
||||
I2C X
|
||||
I2C Y
|
||||
ValueError Z
|
||||
CAN 1
|
||||
CAN 2
|
||||
ValueError 3
|
||||
CAN YA
|
||||
CAN YB
|
||||
ValueError YC
|
@ -8,8 +8,8 @@ from array import array
|
||||
import micropython
|
||||
import pyb
|
||||
|
||||
# test we can correctly create by id or name
|
||||
for bus in (-1, 0, 1, 2, 3, "YA", "YB", "YC"):
|
||||
# test we can correctly create by id (2 handled in can2.py test)
|
||||
for bus in (-1, 0, 1, 3):
|
||||
try:
|
||||
CAN(bus, CAN.LOOPBACK)
|
||||
print("CAN", bus)
|
||||
@ -273,18 +273,11 @@ while can.any(0):
|
||||
|
||||
# Testing rtr messages
|
||||
bus1 = CAN(1, CAN.LOOPBACK)
|
||||
bus2 = CAN(2, CAN.LOOPBACK, extframe = True)
|
||||
while bus1.any(0):
|
||||
bus1.recv(0)
|
||||
while bus2.any(0):
|
||||
bus2.recv(0)
|
||||
bus1.setfilter(0, CAN.LIST16, 0, (1, 2, 3, 4))
|
||||
bus1.setfilter(1, CAN.LIST16, 0, (5, 6, 7, 8), rtr=(True, True, True, True))
|
||||
bus1.setfilter(2, CAN.MASK16, 0, (64, 64, 32, 32), rtr=(False, True))
|
||||
bus2.setfilter(0, CAN.LIST32, 0, (1, 2), rtr=(True, True))
|
||||
bus2.setfilter(1, CAN.LIST32, 0, (3, 4), rtr=(True, False))
|
||||
bus2.setfilter(2, CAN.MASK32, 0, (16, 16), rtr=(False,))
|
||||
bus2.setfilter(2, CAN.MASK32, 0, (32, 32), rtr=(True,))
|
||||
|
||||
bus1.send('',1,rtr=True)
|
||||
print(bus1.any(0))
|
||||
@ -299,11 +292,9 @@ print(bus1.any(0))
|
||||
bus1.send('',32,rtr=True)
|
||||
print(bus1.recv(0))
|
||||
|
||||
bus2.send('',1,rtr=True)
|
||||
print(bus2.recv(0))
|
||||
bus2.send('',2,rtr=True)
|
||||
print(bus2.recv(0))
|
||||
bus2.send('',3,rtr=True)
|
||||
print(bus2.recv(0))
|
||||
bus2.send('',4,rtr=True)
|
||||
print(bus2.any(0))
|
||||
# test HAL error, timeout
|
||||
can = pyb.CAN(1, pyb.CAN.NORMAL)
|
||||
try:
|
||||
can.send('1', 1, timeout=50)
|
||||
except OSError as e:
|
||||
print(repr(e))
|
||||
|
@ -1,11 +1,7 @@
|
||||
ValueError -1
|
||||
ValueError 0
|
||||
CAN 1
|
||||
CAN 2
|
||||
ValueError 3
|
||||
CAN YA
|
||||
CAN YB
|
||||
ValueError YC
|
||||
CAN(1)
|
||||
True
|
||||
CAN(1, CAN.LOOPBACK, extframe=False, auto_restart=False)
|
||||
@ -70,7 +66,4 @@ False
|
||||
(7, True, 6, b'')
|
||||
False
|
||||
(32, True, 9, b'')
|
||||
(1, True, 0, b'')
|
||||
(2, True, 1, b'')
|
||||
(3, True, 2, b'')
|
||||
False
|
||||
OSError(110,)
|
||||
|
24
tests/pyb/can2.py
Normal file
24
tests/pyb/can2.py
Normal file
@ -0,0 +1,24 @@
|
||||
try:
|
||||
from pyb import CAN
|
||||
CAN(2)
|
||||
except (ImportError, ValueError):
|
||||
print('SKIP')
|
||||
raise SystemExit
|
||||
|
||||
# Testing rtr messages
|
||||
bus2 = CAN(2, CAN.LOOPBACK, extframe=True)
|
||||
while bus2.any(0):
|
||||
bus2.recv(0)
|
||||
bus2.setfilter(0, CAN.LIST32, 0, (1, 2), rtr=(True, True))
|
||||
bus2.setfilter(1, CAN.LIST32, 0, (3, 4), rtr=(True, False))
|
||||
bus2.setfilter(2, CAN.MASK32, 0, (16, 16), rtr=(False,))
|
||||
bus2.setfilter(2, CAN.MASK32, 0, (32, 32), rtr=(True,))
|
||||
|
||||
bus2.send('',1,rtr=True)
|
||||
print(bus2.recv(0))
|
||||
bus2.send('',2,rtr=True)
|
||||
print(bus2.recv(0))
|
||||
bus2.send('',3,rtr=True)
|
||||
print(bus2.recv(0))
|
||||
bus2.send('',4,rtr=True)
|
||||
print(bus2.any(0))
|
4
tests/pyb/can2.py.exp
Normal file
4
tests/pyb/can2.py.exp
Normal file
@ -0,0 +1,4 @@
|
||||
(1, True, 0, b'')
|
||||
(2, True, 1, b'')
|
||||
(3, True, 2, b'')
|
||||
False
|
@ -1,7 +1,7 @@
|
||||
import pyb
|
||||
|
||||
# test basic functionality
|
||||
ext = pyb.ExtInt('Y1', pyb.ExtInt.IRQ_RISING, pyb.Pin.PULL_DOWN, lambda l:print('line:', l))
|
||||
ext = pyb.ExtInt('X5', pyb.ExtInt.IRQ_RISING, pyb.Pin.PULL_DOWN, lambda l:print('line:', l))
|
||||
ext.disable()
|
||||
ext.enable()
|
||||
print(ext.line())
|
||||
|
@ -1,3 +1,3 @@
|
||||
6
|
||||
line: 6
|
||||
line: 6
|
||||
4
|
||||
line: 4
|
||||
line: 4
|
||||
|
@ -1,15 +0,0 @@
|
||||
# test hal errors
|
||||
|
||||
import pyb
|
||||
|
||||
i2c = pyb.I2C(2, pyb.I2C.MASTER)
|
||||
try:
|
||||
i2c.recv(1, 1)
|
||||
except OSError as e:
|
||||
print(repr(e))
|
||||
|
||||
can = pyb.CAN(1, pyb.CAN.NORMAL)
|
||||
try:
|
||||
can.send('1', 1, timeout=50)
|
||||
except OSError as e:
|
||||
print(repr(e))
|
@ -1,2 +0,0 @@
|
||||
OSError(5,)
|
||||
OSError(110,)
|
@ -1,8 +1,8 @@
|
||||
import pyb
|
||||
from pyb import I2C
|
||||
|
||||
# test we can correctly create by id or name
|
||||
for bus in (-1, 0, 1, 2, 3, "X", "Y", "Z"):
|
||||
# test we can correctly create by id
|
||||
for bus in (-1, 0, 1):
|
||||
try:
|
||||
I2C(bus)
|
||||
print("I2C", bus)
|
||||
@ -14,19 +14,3 @@ i2c = I2C(1)
|
||||
i2c.init(I2C.MASTER, baudrate=400000)
|
||||
print(i2c.scan())
|
||||
i2c.deinit()
|
||||
|
||||
# use accelerometer to test i2c bus
|
||||
|
||||
accel_addr = 76
|
||||
|
||||
pyb.Accel() # this will init the MMA for us
|
||||
i2c.init(I2C.MASTER, baudrate=400000)
|
||||
|
||||
print(i2c.scan())
|
||||
print(i2c.is_ready(accel_addr))
|
||||
|
||||
print(i2c.mem_read(1, accel_addr, 7, timeout=500))
|
||||
i2c.mem_write(0, accel_addr, 0, timeout=500)
|
||||
|
||||
i2c.send(7, addr=accel_addr)
|
||||
i2c.recv(1, addr=accel_addr)
|
||||
|
@ -1,12 +1,4 @@
|
||||
ValueError -1
|
||||
ValueError 0
|
||||
I2C 1
|
||||
I2C 2
|
||||
ValueError 3
|
||||
I2C X
|
||||
I2C Y
|
||||
ValueError Z
|
||||
[]
|
||||
[76]
|
||||
True
|
||||
b'\x01'
|
||||
|
23
tests/pyb/i2c_accel.py
Normal file
23
tests/pyb/i2c_accel.py
Normal file
@ -0,0 +1,23 @@
|
||||
# use accelerometer to test i2c bus
|
||||
|
||||
import pyb
|
||||
from pyb import I2C
|
||||
|
||||
if not hasattr(pyb, 'Accel'):
|
||||
print('SKIP')
|
||||
raise SystemExit
|
||||
|
||||
accel_addr = 76
|
||||
|
||||
pyb.Accel() # this will init the MMA for us
|
||||
|
||||
i2c = I2C(1, I2C.MASTER, baudrate=400000)
|
||||
|
||||
print(i2c.scan())
|
||||
print(i2c.is_ready(accel_addr))
|
||||
|
||||
print(i2c.mem_read(1, accel_addr, 7, timeout=500))
|
||||
i2c.mem_write(0, accel_addr, 0, timeout=500)
|
||||
|
||||
i2c.send(7, addr=accel_addr)
|
||||
i2c.recv(1, addr=accel_addr)
|
3
tests/pyb/i2c_accel.py.exp
Normal file
3
tests/pyb/i2c_accel.py.exp
Normal file
@ -0,0 +1,3 @@
|
||||
[76]
|
||||
True
|
||||
b'\x01'
|
@ -3,6 +3,10 @@
|
||||
import pyb
|
||||
from pyb import I2C
|
||||
|
||||
if not hasattr(pyb, 'Accel'):
|
||||
print('SKIP')
|
||||
raise SystemExit
|
||||
|
||||
# init accelerometer
|
||||
pyb.Accel()
|
||||
|
||||
|
@ -1,17 +1,19 @@
|
||||
import pyb
|
||||
from pyb import LED
|
||||
import os, pyb
|
||||
|
||||
l1 = pyb.LED(1)
|
||||
l2 = pyb.LED(2)
|
||||
l3 = pyb.LED(3)
|
||||
l4 = pyb.LED(4)
|
||||
|
||||
leds = [LED(i) for i in range(1, 5)]
|
||||
pwm_leds = leds[2:]
|
||||
machine = os.uname().machine
|
||||
if 'PYBv1.' in machine or 'PYBLITEv1.' in machine:
|
||||
leds = [pyb.LED(i) for i in range(1, 5)]
|
||||
pwm_leds = leds[2:]
|
||||
elif 'PYBD' in machine:
|
||||
leds = [pyb.LED(i) for i in range(1, 4)]
|
||||
pwm_leds = []
|
||||
else:
|
||||
print('SKIP')
|
||||
raise SystemExit
|
||||
|
||||
# test printing
|
||||
for l in leds:
|
||||
print(l)
|
||||
for i in range(3):
|
||||
print(leds[i])
|
||||
|
||||
# test on and off
|
||||
for l in leds:
|
||||
|
@ -1,4 +1,3 @@
|
||||
LED(1)
|
||||
LED(2)
|
||||
LED(3)
|
||||
LED(4)
|
||||
|
@ -1,14 +1,14 @@
|
||||
from pyb import Pin
|
||||
|
||||
p = Pin('Y1', Pin.IN)
|
||||
p = Pin('X8', Pin.IN)
|
||||
print(p)
|
||||
print(p.name())
|
||||
print(p.pin())
|
||||
print(p.port())
|
||||
|
||||
p = Pin('Y1', Pin.IN, Pin.PULL_UP)
|
||||
p = Pin('Y1', Pin.IN, pull=Pin.PULL_UP)
|
||||
p = Pin('Y1', mode=Pin.IN, pull=Pin.PULL_UP)
|
||||
p = Pin('X8', Pin.IN, Pin.PULL_UP)
|
||||
p = Pin('X8', Pin.IN, pull=Pin.PULL_UP)
|
||||
p = Pin('X8', mode=Pin.IN, pull=Pin.PULL_UP)
|
||||
print(p)
|
||||
print(p.value())
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
Pin(Pin.cpu.C6, mode=Pin.IN)
|
||||
C6
|
||||
6
|
||||
2
|
||||
Pin(Pin.cpu.C6, mode=Pin.IN, pull=Pin.PULL_UP)
|
||||
Pin(Pin.cpu.A7, mode=Pin.IN)
|
||||
A7
|
||||
7
|
||||
0
|
||||
Pin(Pin.cpu.A7, mode=Pin.IN, pull=Pin.PULL_UP)
|
||||
1
|
||||
Pin(Pin.cpu.C6, mode=Pin.IN, pull=Pin.PULL_DOWN)
|
||||
Pin(Pin.cpu.A7, mode=Pin.IN, pull=Pin.PULL_DOWN)
|
||||
0
|
||||
0
|
||||
1
|
||||
|
@ -8,3 +8,11 @@ if not 'STM32F405' in os.uname().machine:
|
||||
|
||||
print(pyb.freq())
|
||||
print(type(pyb.rng()))
|
||||
|
||||
# test HAL error specific to F405
|
||||
i2c = pyb.I2C(2, pyb.I2C.MASTER)
|
||||
try:
|
||||
i2c.recv(1, 1)
|
||||
except OSError as e:
|
||||
print(repr(e))
|
||||
|
||||
|
@ -1,2 +1,3 @@
|
||||
(168000000, 168000000, 42000000, 84000000)
|
||||
<class 'int'>
|
||||
OSError(5,)
|
||||
|
@ -1,7 +1,7 @@
|
||||
from pyb import SPI
|
||||
|
||||
# test we can correctly create by id or name
|
||||
for bus in (-1, 0, 1, 2, 3, "X", "Y", "Z"):
|
||||
# test we can correctly create by id
|
||||
for bus in (-1, 0, 1, 2):
|
||||
try:
|
||||
SPI(bus)
|
||||
print("SPI", bus)
|
||||
@ -14,7 +14,7 @@ print(spi)
|
||||
spi = SPI(1, SPI.MASTER)
|
||||
spi = SPI(1, SPI.MASTER, baudrate=500000)
|
||||
spi = SPI(1, SPI.MASTER, 500000, polarity=1, phase=0, bits=8, firstbit=SPI.MSB, ti=False, crc=None)
|
||||
print(spi)
|
||||
print(str(spi)[:28], str(spi)[49:]) # don't print baudrate/prescaler
|
||||
|
||||
spi.init(SPI.SLAVE, phase=1)
|
||||
print(spi)
|
||||
|
@ -2,12 +2,8 @@ ValueError -1
|
||||
ValueError 0
|
||||
SPI 1
|
||||
SPI 2
|
||||
ValueError 3
|
||||
SPI X
|
||||
SPI Y
|
||||
ValueError Z
|
||||
SPI(1)
|
||||
SPI(1, SPI.MASTER, baudrate=328125, prescaler=256, polarity=1, phase=0, bits=8)
|
||||
SPI(1, SPI.MASTER, baudrate= , polarity=1, phase=0, bits=8)
|
||||
SPI(1, SPI.SLAVE, polarity=1, phase=1, bits=8)
|
||||
OSError
|
||||
b'\xff'
|
||||
|
@ -1,7 +1,7 @@
|
||||
from pyb import UART
|
||||
|
||||
# test we can correctly create by id or name
|
||||
for bus in (-1, 0, 1, 2, 3, 4, 5, 6, 7, "XA", "XB", "YA", "YB", "Z"):
|
||||
# test we can correctly create by id
|
||||
for bus in (-1, 0, 1, 2, 5, 6, 7):
|
||||
try:
|
||||
UART(bus, 9600)
|
||||
print("UART", bus)
|
||||
|
@ -2,16 +2,9 @@ ValueError -1
|
||||
ValueError 0
|
||||
UART 1
|
||||
UART 2
|
||||
UART 3
|
||||
UART 4
|
||||
ValueError 5
|
||||
UART 6
|
||||
ValueError 7
|
||||
UART XA
|
||||
UART XB
|
||||
UART YA
|
||||
UART YB
|
||||
ValueError Z
|
||||
UART(1, baudrate=9600, bits=8, parity=None, stop=1, flow=0, timeout=0, timeout_char=3, rxbuf=64)
|
||||
UART(1, baudrate=2400, bits=8, parity=None, stop=1, flow=0, timeout=0, timeout_char=7, rxbuf=64)
|
||||
0
|
||||
|
Loading…
Reference in New Issue
Block a user