diff --git a/tests/pyb/accel.py b/tests/pyb/accel.py index e5a1a2ed7..9aa60c185 100644 --- a/tests/pyb/accel.py +++ b/tests/pyb/accel.py @@ -1,5 +1,9 @@ import pyb +if not hasattr(pyb, 'Accel'): + print('SKIP') + raise SystemExit + accel = pyb.Accel() print(accel) accel.x() diff --git a/tests/pyb/adc.py b/tests/pyb/adc.py index 0bd9b9d53..ef4206538 100644 --- a/tests/pyb/adc.py +++ b/tests/pyb/adc.py @@ -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) diff --git a/tests/pyb/adc.py.exp b/tests/pyb/adc.py.exp index 1aae16fb0..381329cdd 100644 --- a/tests/pyb/adc.py.exp +++ b/tests/pyb/adc.py.exp @@ -1,4 +1,4 @@ - + 50 25 diff --git a/tests/pyb/board_pybv1x.py b/tests/pyb/board_pybv1x.py new file mode 100644 index 000000000..f4aeeb99e --- /dev/null +++ b/tests/pyb/board_pybv1x.py @@ -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) diff --git a/tests/pyb/board_pybv1x.py.exp b/tests/pyb/board_pybv1x.py.exp new file mode 100644 index 000000000..6d4a6f63c --- /dev/null +++ b/tests/pyb/board_pybv1x.py.exp @@ -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 diff --git a/tests/pyb/can.py b/tests/pyb/can.py index 8a08ea9a6..71de724c7 100644 --- a/tests/pyb/can.py +++ b/tests/pyb/can.py @@ -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)) diff --git a/tests/pyb/can.py.exp b/tests/pyb/can.py.exp index 687935e7f..a27907cc5 100644 --- a/tests/pyb/can.py.exp +++ b/tests/pyb/can.py.exp @@ -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,) diff --git a/tests/pyb/can2.py b/tests/pyb/can2.py new file mode 100644 index 000000000..440ae4925 --- /dev/null +++ b/tests/pyb/can2.py @@ -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)) diff --git a/tests/pyb/can2.py.exp b/tests/pyb/can2.py.exp new file mode 100644 index 000000000..371ad2bdc --- /dev/null +++ b/tests/pyb/can2.py.exp @@ -0,0 +1,4 @@ +(1, True, 0, b'') +(2, True, 1, b'') +(3, True, 2, b'') +False diff --git a/tests/pyb/extint.py b/tests/pyb/extint.py index ae98ccd5a..8b6bc5651 100644 --- a/tests/pyb/extint.py +++ b/tests/pyb/extint.py @@ -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()) diff --git a/tests/pyb/extint.py.exp b/tests/pyb/extint.py.exp index 1f9da9844..fbd820ed4 100644 --- a/tests/pyb/extint.py.exp +++ b/tests/pyb/extint.py.exp @@ -1,3 +1,3 @@ -6 -line: 6 -line: 6 +4 +line: 4 +line: 4 diff --git a/tests/pyb/halerror.py b/tests/pyb/halerror.py deleted file mode 100644 index 1a6bce1a7..000000000 --- a/tests/pyb/halerror.py +++ /dev/null @@ -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)) diff --git a/tests/pyb/halerror.py.exp b/tests/pyb/halerror.py.exp deleted file mode 100644 index 0f3f26253..000000000 --- a/tests/pyb/halerror.py.exp +++ /dev/null @@ -1,2 +0,0 @@ -OSError(5,) -OSError(110,) diff --git a/tests/pyb/i2c.py b/tests/pyb/i2c.py index 6875e5a5a..bc9dba878 100644 --- a/tests/pyb/i2c.py +++ b/tests/pyb/i2c.py @@ -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) diff --git a/tests/pyb/i2c.py.exp b/tests/pyb/i2c.py.exp index 709fb412d..bd896ea74 100644 --- a/tests/pyb/i2c.py.exp +++ b/tests/pyb/i2c.py.exp @@ -1,12 +1,4 @@ ValueError -1 ValueError 0 I2C 1 -I2C 2 -ValueError 3 -I2C X -I2C Y -ValueError Z [] -[76] -True -b'\x01' diff --git a/tests/pyb/i2c_accel.py b/tests/pyb/i2c_accel.py new file mode 100644 index 000000000..e42cba178 --- /dev/null +++ b/tests/pyb/i2c_accel.py @@ -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) diff --git a/tests/pyb/i2c_accel.py.exp b/tests/pyb/i2c_accel.py.exp new file mode 100644 index 000000000..206a2eb4c --- /dev/null +++ b/tests/pyb/i2c_accel.py.exp @@ -0,0 +1,3 @@ +[76] +True +b'\x01' diff --git a/tests/pyb/i2c_error.py b/tests/pyb/i2c_error.py index 3201d6367..e0f721179 100644 --- a/tests/pyb/i2c_error.py +++ b/tests/pyb/i2c_error.py @@ -3,6 +3,10 @@ import pyb from pyb import I2C +if not hasattr(pyb, 'Accel'): + print('SKIP') + raise SystemExit + # init accelerometer pyb.Accel() diff --git a/tests/pyb/led.py b/tests/pyb/led.py index d2a17ebc9..38e9993cb 100644 --- a/tests/pyb/led.py +++ b/tests/pyb/led.py @@ -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: diff --git a/tests/pyb/led.py.exp b/tests/pyb/led.py.exp index 4e8d856cd..b4170c41e 100644 --- a/tests/pyb/led.py.exp +++ b/tests/pyb/led.py.exp @@ -1,4 +1,3 @@ LED(1) LED(2) LED(3) -LED(4) diff --git a/tests/pyb/pin.py b/tests/pyb/pin.py index 9b3788343..ea42cc206 100644 --- a/tests/pyb/pin.py +++ b/tests/pyb/pin.py @@ -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()) diff --git a/tests/pyb/pin.py.exp b/tests/pyb/pin.py.exp index f2f7038fd..a2a7e42d9 100644 --- a/tests/pyb/pin.py.exp +++ b/tests/pyb/pin.py.exp @@ -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 diff --git a/tests/pyb/pyb_f405.py b/tests/pyb/pyb_f405.py index 2f161ae09..f49dd1bc7 100644 --- a/tests/pyb/pyb_f405.py +++ b/tests/pyb/pyb_f405.py @@ -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)) + diff --git a/tests/pyb/pyb_f405.py.exp b/tests/pyb/pyb_f405.py.exp index a90aa0268..a52f40920 100644 --- a/tests/pyb/pyb_f405.py.exp +++ b/tests/pyb/pyb_f405.py.exp @@ -1,2 +1,3 @@ (168000000, 168000000, 42000000, 84000000) +OSError(5,) diff --git a/tests/pyb/spi.py b/tests/pyb/spi.py index 88cc975bb..577737420 100644 --- a/tests/pyb/spi.py +++ b/tests/pyb/spi.py @@ -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) diff --git a/tests/pyb/spi.py.exp b/tests/pyb/spi.py.exp index a0d835700..473c173a5 100644 --- a/tests/pyb/spi.py.exp +++ b/tests/pyb/spi.py.exp @@ -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' diff --git a/tests/pyb/uart.py b/tests/pyb/uart.py index 836b073a6..82a66dd2e 100644 --- a/tests/pyb/uart.py +++ b/tests/pyb/uart.py @@ -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) diff --git a/tests/pyb/uart.py.exp b/tests/pyb/uart.py.exp index d302468ed..1a4cbd938 100644 --- a/tests/pyb/uart.py.exp +++ b/tests/pyb/uart.py.exp @@ -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