Commit d3bb3e38 authored by Damien George's avatar Damien George
Browse files

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).
parent 27c149ef
......@@ -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
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
......
import pyb
if not hasattr(pyb, 'DAC'):
print('SKIP')
import sys
sys.exit()
dac = pyb.DAC(1)
print(dac)
dac.noise(100)
......
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())
......
0
line: 0
line: 0
6
line: 6
line: 6
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())
......
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
......
......@@ -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()))
......
3
3
(168000000, 168000000, 42000000, 84000000)
True
12
# 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()))
(168000000, 168000000, 42000000, 84000000)
<class 'int'>
# 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())
(96000000, 96000000, 24000000, 48000000)
......@@ -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):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment