kopia lustrzana https://github.com/micropython/micropython
tests/pyb: Refactor pyboard tests to work on PYBv1, PYBLITEv1 and PYBD.
rodzic
7280bf40d9
commit
4b184d1281
|
@ -1,5 +1,9 @@
|
||||||
import pyb
|
import pyb
|
||||||
|
|
||||||
|
if not hasattr(pyb, 'Accel'):
|
||||||
|
print('SKIP')
|
||||||
|
raise SystemExit
|
||||||
|
|
||||||
accel = pyb.Accel()
|
accel = pyb.Accel()
|
||||||
print(accel)
|
print(accel)
|
||||||
accel.x()
|
accel.x()
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from pyb import ADC, Timer
|
from pyb import ADC, Timer
|
||||||
|
|
||||||
adct = ADC(16) # Temperature 930 -> 20C
|
adct = ADC(16) # Temperature 930 -> 20C
|
||||||
print(adct)
|
print(str(adct)[:19])
|
||||||
adcv = ADC(17) # Voltage 1500 -> 3.3V
|
adcv = ADC(17) # Voltage 1500 -> 3.3V
|
||||||
print(adcv)
|
print(adcv)
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
<ADC on 16 channel=16>
|
<ADC on 16 channel=
|
||||||
<ADC on 17 channel=17>
|
<ADC on 17 channel=17>
|
||||||
50
|
50
|
||||||
25
|
25
|
||||||
|
|
|
@ -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)
|
|
@ -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 micropython
|
||||||
import pyb
|
import pyb
|
||||||
|
|
||||||
# test we can correctly create by id or name
|
# test we can correctly create by id (2 handled in can2.py test)
|
||||||
for bus in (-1, 0, 1, 2, 3, "YA", "YB", "YC"):
|
for bus in (-1, 0, 1, 3):
|
||||||
try:
|
try:
|
||||||
CAN(bus, CAN.LOOPBACK)
|
CAN(bus, CAN.LOOPBACK)
|
||||||
print("CAN", bus)
|
print("CAN", bus)
|
||||||
|
@ -273,18 +273,11 @@ while can.any(0):
|
||||||
|
|
||||||
# Testing rtr messages
|
# Testing rtr messages
|
||||||
bus1 = CAN(1, CAN.LOOPBACK)
|
bus1 = CAN(1, CAN.LOOPBACK)
|
||||||
bus2 = CAN(2, CAN.LOOPBACK, extframe = True)
|
|
||||||
while bus1.any(0):
|
while bus1.any(0):
|
||||||
bus1.recv(0)
|
bus1.recv(0)
|
||||||
while bus2.any(0):
|
|
||||||
bus2.recv(0)
|
|
||||||
bus1.setfilter(0, CAN.LIST16, 0, (1, 2, 3, 4))
|
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(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))
|
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)
|
bus1.send('',1,rtr=True)
|
||||||
print(bus1.any(0))
|
print(bus1.any(0))
|
||||||
|
@ -299,11 +292,9 @@ print(bus1.any(0))
|
||||||
bus1.send('',32,rtr=True)
|
bus1.send('',32,rtr=True)
|
||||||
print(bus1.recv(0))
|
print(bus1.recv(0))
|
||||||
|
|
||||||
bus2.send('',1,rtr=True)
|
# test HAL error, timeout
|
||||||
print(bus2.recv(0))
|
can = pyb.CAN(1, pyb.CAN.NORMAL)
|
||||||
bus2.send('',2,rtr=True)
|
try:
|
||||||
print(bus2.recv(0))
|
can.send('1', 1, timeout=50)
|
||||||
bus2.send('',3,rtr=True)
|
except OSError as e:
|
||||||
print(bus2.recv(0))
|
print(repr(e))
|
||||||
bus2.send('',4,rtr=True)
|
|
||||||
print(bus2.any(0))
|
|
||||||
|
|
|
@ -1,11 +1,7 @@
|
||||||
ValueError -1
|
ValueError -1
|
||||||
ValueError 0
|
ValueError 0
|
||||||
CAN 1
|
CAN 1
|
||||||
CAN 2
|
|
||||||
ValueError 3
|
ValueError 3
|
||||||
CAN YA
|
|
||||||
CAN YB
|
|
||||||
ValueError YC
|
|
||||||
CAN(1)
|
CAN(1)
|
||||||
True
|
True
|
||||||
CAN(1, CAN.LOOPBACK, extframe=False, auto_restart=False)
|
CAN(1, CAN.LOOPBACK, extframe=False, auto_restart=False)
|
||||||
|
@ -70,7 +66,4 @@ False
|
||||||
(7, True, 6, b'')
|
(7, True, 6, b'')
|
||||||
False
|
False
|
||||||
(32, True, 9, b'')
|
(32, True, 9, b'')
|
||||||
(1, True, 0, b'')
|
OSError(110,)
|
||||||
(2, True, 1, b'')
|
|
||||||
(3, True, 2, b'')
|
|
||||||
False
|
|
||||||
|
|
|
@ -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))
|
|
@ -0,0 +1,4 @@
|
||||||
|
(1, True, 0, b'')
|
||||||
|
(2, True, 1, b'')
|
||||||
|
(3, True, 2, b'')
|
||||||
|
False
|
|
@ -1,7 +1,7 @@
|
||||||
import pyb
|
import pyb
|
||||||
|
|
||||||
# test basic functionality
|
# 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.disable()
|
||||||
ext.enable()
|
ext.enable()
|
||||||
print(ext.line())
|
print(ext.line())
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
6
|
4
|
||||||
line: 6
|
line: 4
|
||||||
line: 6
|
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
|
import pyb
|
||||||
from pyb import I2C
|
from pyb import I2C
|
||||||
|
|
||||||
# test we can correctly create by id or name
|
# test we can correctly create by id
|
||||||
for bus in (-1, 0, 1, 2, 3, "X", "Y", "Z"):
|
for bus in (-1, 0, 1):
|
||||||
try:
|
try:
|
||||||
I2C(bus)
|
I2C(bus)
|
||||||
print("I2C", bus)
|
print("I2C", bus)
|
||||||
|
@ -14,19 +14,3 @@ i2c = I2C(1)
|
||||||
i2c.init(I2C.MASTER, baudrate=400000)
|
i2c.init(I2C.MASTER, baudrate=400000)
|
||||||
print(i2c.scan())
|
print(i2c.scan())
|
||||||
i2c.deinit()
|
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 -1
|
||||||
ValueError 0
|
ValueError 0
|
||||||
I2C 1
|
I2C 1
|
||||||
I2C 2
|
|
||||||
ValueError 3
|
|
||||||
I2C X
|
|
||||||
I2C Y
|
|
||||||
ValueError Z
|
|
||||||
[]
|
[]
|
||||||
[76]
|
|
||||||
True
|
|
||||||
b'\x01'
|
|
||||||
|
|
|
@ -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)
|
|
@ -0,0 +1,3 @@
|
||||||
|
[76]
|
||||||
|
True
|
||||||
|
b'\x01'
|
|
@ -3,6 +3,10 @@
|
||||||
import pyb
|
import pyb
|
||||||
from pyb import I2C
|
from pyb import I2C
|
||||||
|
|
||||||
|
if not hasattr(pyb, 'Accel'):
|
||||||
|
print('SKIP')
|
||||||
|
raise SystemExit
|
||||||
|
|
||||||
# init accelerometer
|
# init accelerometer
|
||||||
pyb.Accel()
|
pyb.Accel()
|
||||||
|
|
||||||
|
|
|
@ -1,17 +1,19 @@
|
||||||
import pyb
|
import os, pyb
|
||||||
from pyb import LED
|
|
||||||
|
|
||||||
l1 = pyb.LED(1)
|
machine = os.uname().machine
|
||||||
l2 = pyb.LED(2)
|
if 'PYBv1.' in machine or 'PYBLITEv1.' in machine:
|
||||||
l3 = pyb.LED(3)
|
leds = [pyb.LED(i) for i in range(1, 5)]
|
||||||
l4 = pyb.LED(4)
|
pwm_leds = leds[2:]
|
||||||
|
elif 'PYBD' in machine:
|
||||||
leds = [LED(i) for i in range(1, 5)]
|
leds = [pyb.LED(i) for i in range(1, 4)]
|
||||||
pwm_leds = leds[2:]
|
pwm_leds = []
|
||||||
|
else:
|
||||||
|
print('SKIP')
|
||||||
|
raise SystemExit
|
||||||
|
|
||||||
# test printing
|
# test printing
|
||||||
for l in leds:
|
for i in range(3):
|
||||||
print(l)
|
print(leds[i])
|
||||||
|
|
||||||
# test on and off
|
# test on and off
|
||||||
for l in leds:
|
for l in leds:
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
LED(1)
|
LED(1)
|
||||||
LED(2)
|
LED(2)
|
||||||
LED(3)
|
LED(3)
|
||||||
LED(4)
|
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
from pyb import Pin
|
from pyb import Pin
|
||||||
|
|
||||||
p = Pin('Y1', Pin.IN)
|
p = Pin('X8', Pin.IN)
|
||||||
print(p)
|
print(p)
|
||||||
print(p.name())
|
print(p.name())
|
||||||
print(p.pin())
|
print(p.pin())
|
||||||
print(p.port())
|
print(p.port())
|
||||||
|
|
||||||
p = Pin('Y1', Pin.IN, Pin.PULL_UP)
|
p = Pin('X8', Pin.IN, Pin.PULL_UP)
|
||||||
p = Pin('Y1', Pin.IN, pull=Pin.PULL_UP)
|
p = Pin('X8', Pin.IN, pull=Pin.PULL_UP)
|
||||||
p = Pin('Y1', mode=Pin.IN, pull=Pin.PULL_UP)
|
p = Pin('X8', mode=Pin.IN, pull=Pin.PULL_UP)
|
||||||
print(p)
|
print(p)
|
||||||
print(p.value())
|
print(p.value())
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
Pin(Pin.cpu.C6, mode=Pin.IN)
|
Pin(Pin.cpu.A7, mode=Pin.IN)
|
||||||
C6
|
A7
|
||||||
6
|
7
|
||||||
2
|
0
|
||||||
Pin(Pin.cpu.C6, mode=Pin.IN, pull=Pin.PULL_UP)
|
Pin(Pin.cpu.A7, mode=Pin.IN, pull=Pin.PULL_UP)
|
||||||
1
|
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
|
||||||
0
|
0
|
||||||
1
|
1
|
||||||
|
|
|
@ -8,3 +8,11 @@ if not 'STM32F405' in os.uname().machine:
|
||||||
|
|
||||||
print(pyb.freq())
|
print(pyb.freq())
|
||||||
print(type(pyb.rng()))
|
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)
|
(168000000, 168000000, 42000000, 84000000)
|
||||||
<class 'int'>
|
<class 'int'>
|
||||||
|
OSError(5,)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from pyb import SPI
|
from pyb import SPI
|
||||||
|
|
||||||
# test we can correctly create by id or name
|
# test we can correctly create by id
|
||||||
for bus in (-1, 0, 1, 2, 3, "X", "Y", "Z"):
|
for bus in (-1, 0, 1, 2):
|
||||||
try:
|
try:
|
||||||
SPI(bus)
|
SPI(bus)
|
||||||
print("SPI", bus)
|
print("SPI", bus)
|
||||||
|
@ -14,7 +14,7 @@ print(spi)
|
||||||
spi = SPI(1, SPI.MASTER)
|
spi = SPI(1, SPI.MASTER)
|
||||||
spi = SPI(1, SPI.MASTER, baudrate=500000)
|
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)
|
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)
|
spi.init(SPI.SLAVE, phase=1)
|
||||||
print(spi)
|
print(spi)
|
||||||
|
|
|
@ -2,12 +2,8 @@ ValueError -1
|
||||||
ValueError 0
|
ValueError 0
|
||||||
SPI 1
|
SPI 1
|
||||||
SPI 2
|
SPI 2
|
||||||
ValueError 3
|
|
||||||
SPI X
|
|
||||||
SPI Y
|
|
||||||
ValueError Z
|
|
||||||
SPI(1)
|
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)
|
SPI(1, SPI.SLAVE, polarity=1, phase=1, bits=8)
|
||||||
OSError
|
OSError
|
||||||
b'\xff'
|
b'\xff'
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from pyb import UART
|
from pyb import UART
|
||||||
|
|
||||||
# test we can correctly create by id or name
|
# test we can correctly create by id
|
||||||
for bus in (-1, 0, 1, 2, 3, 4, 5, 6, 7, "XA", "XB", "YA", "YB", "Z"):
|
for bus in (-1, 0, 1, 2, 5, 6, 7):
|
||||||
try:
|
try:
|
||||||
UART(bus, 9600)
|
UART(bus, 9600)
|
||||||
print("UART", bus)
|
print("UART", bus)
|
||||||
|
|
|
@ -2,16 +2,9 @@ ValueError -1
|
||||||
ValueError 0
|
ValueError 0
|
||||||
UART 1
|
UART 1
|
||||||
UART 2
|
UART 2
|
||||||
UART 3
|
|
||||||
UART 4
|
|
||||||
ValueError 5
|
ValueError 5
|
||||||
UART 6
|
UART 6
|
||||||
ValueError 7
|
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=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)
|
UART(1, baudrate=2400, bits=8, parity=None, stop=1, flow=0, timeout=0, timeout_char=7, rxbuf=64)
|
||||||
0
|
0
|
||||||
|
|
Ładowanie…
Reference in New Issue