tests/pyb: Adjust tests so they can run on PYB and PYBLITE.

A few tests still fail on PYBLITE, and that's due to differences in the
available peripheral block numbers on the different MCUs (eg I2C(2)
exists on one, but it's I2C(3) on the other).
This commit is contained in:
Damien George 2017-02-06 13:48:01 +11:00
parent 27c149efe0
commit d3bb3e38df
14 changed files with 57 additions and 24 deletions

View File

@ -9,9 +9,12 @@ print(adc)
val = adc.read()
assert val < 500
# timer for read_timed
tim = pyb.Timer(5, freq=500)
# read into bytearray
buf = bytearray(50)
adc.read_timed(buf, 500)
adc.read_timed(buf, tim)
print(len(buf))
for i in buf:
assert i < 500
@ -19,12 +22,12 @@ for i in buf:
# read into arrays with different element sizes
import array
ar = array.array('h', 25 * [0])
adc.read_timed(ar, 500)
adc.read_timed(ar, tim)
print(len(ar))
for i in buf:
assert i < 500
ar = array.array('i', 30 * [0])
adc.read_timed(ar, 500)
adc.read_timed(ar, tim)
print(len(ar))
for i in buf:
assert i < 500

View File

@ -1,4 +1,10 @@
from pyb import CAN
try:
from pyb import CAN
except ImportError:
print('SKIP')
import sys
sys.exit()
import pyb
# test we can correctly create by id or name

View File

@ -1,5 +1,10 @@
import pyb
if not hasattr(pyb, 'DAC'):
print('SKIP')
import sys
sys.exit()
dac = pyb.DAC(1)
print(dac)
dac.noise(100)

View File

@ -1,7 +1,7 @@
import pyb
# test basic functionality
ext = pyb.ExtInt('X1', pyb.ExtInt.IRQ_RISING, pyb.Pin.PULL_DOWN, lambda l:print('line:', l))
ext = pyb.ExtInt('Y1', pyb.ExtInt.IRQ_RISING, pyb.Pin.PULL_DOWN, lambda l:print('line:', l))
ext.disable()
ext.enable()
print(ext.line())

View File

@ -1,3 +1,3 @@
0
line: 0
line: 0
6
line: 6
line: 6

View File

@ -1,14 +1,14 @@
from pyb import Pin
p = Pin('X1', Pin.IN)
p = Pin('Y1', Pin.IN)
print(p)
print(p.name())
print(p.pin())
print(p.port())
p = Pin('X1', Pin.IN, Pin.PULL_UP)
p = Pin('X1', Pin.IN, pull=Pin.PULL_UP)
p = Pin('X1', mode=Pin.IN, pull=Pin.PULL_UP)
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)
print(p)
print(p.value())

View File

@ -1,10 +1,10 @@
Pin(Pin.cpu.A0, mode=Pin.IN)
A0
0
0
Pin(Pin.cpu.A0, mode=Pin.IN, pull=Pin.PULL_UP)
Pin(Pin.cpu.C6, mode=Pin.IN)
C6
6
2
Pin(Pin.cpu.C6, mode=Pin.IN, pull=Pin.PULL_UP)
1
Pin(Pin.cpu.A0, mode=Pin.IN, pull=Pin.PULL_DOWN)
Pin(Pin.cpu.C6, mode=Pin.IN, pull=Pin.PULL_DOWN)
0
0
1

View File

@ -27,14 +27,10 @@ print((pyb.millis() - start) // 5) # should print 3
pyb.disable_irq()
pyb.enable_irq()
print(pyb.freq())
print(pyb.have_cdc())
pyb.hid((0, 0, 0, 0)) # won't do anything
pyb.rng()
pyb.sync()
print(len(pyb.unique_id()))

View File

@ -1,5 +1,4 @@
3
3
(168000000, 168000000, 42000000, 84000000)
True
12

11
tests/pyb/pyb_f405.py Normal file
View File

@ -0,0 +1,11 @@
# test pyb module on F405 MCUs
import os, pyb
if not 'STM32F405' in os.uname().machine:
print('SKIP')
import sys
sys.exit()
print(pyb.freq())
print(type(pyb.rng()))

View File

@ -0,0 +1,2 @@
(168000000, 168000000, 42000000, 84000000)
<class 'int'>

10
tests/pyb/pyb_f411.py Normal file
View File

@ -0,0 +1,10 @@
# test pyb module on F411 MCUs
import os, pyb
if not 'STM32F411' in os.uname().machine:
print('SKIP')
import sys
sys.exit()
print(pyb.freq())

View File

@ -0,0 +1 @@
(96000000, 96000000, 24000000, 48000000)

View File

@ -7,7 +7,7 @@ print(rtc)
# make sure that 1 second passes correctly
rtc.datetime((2014, 1, 1, 1, 0, 0, 0, 0))
pyb.delay(1001)
pyb.delay(1002)
print(rtc.datetime()[:7])
def set_and_print(datetime):