tests: For pyboard, add test for I2C error handling and recovery.
This commit is contained in:
parent
db573082b5
commit
ef5f2669dc
50
tests/pyb/i2c_error.py
Normal file
50
tests/pyb/i2c_error.py
Normal file
@ -0,0 +1,50 @@
|
||||
# test I2C errors, with polling (disabled irqs) and DMA
|
||||
|
||||
import pyb
|
||||
from pyb import I2C
|
||||
|
||||
# init accelerometer
|
||||
pyb.Accel()
|
||||
|
||||
# get I2C bus
|
||||
i2c = I2C(1, I2C.MASTER)
|
||||
|
||||
# test polling mem_read
|
||||
pyb.disable_irq()
|
||||
i2c.mem_read(1, 76, 0x0a) # should succeed
|
||||
pyb.enable_irq()
|
||||
try:
|
||||
pyb.disable_irq()
|
||||
i2c.mem_read(1, 77, 0x0a) # should fail
|
||||
except OSError as e:
|
||||
pyb.enable_irq()
|
||||
print(repr(e))
|
||||
i2c.mem_read(1, 76, 0x0a) # should succeed
|
||||
|
||||
# test polling mem_write
|
||||
pyb.disable_irq()
|
||||
i2c.mem_write(1, 76, 0x0a) # should succeed
|
||||
pyb.enable_irq()
|
||||
try:
|
||||
pyb.disable_irq()
|
||||
i2c.mem_write(1, 77, 0x0a) # should fail
|
||||
except OSError as e:
|
||||
pyb.enable_irq()
|
||||
print(repr(e))
|
||||
i2c.mem_write(1, 76, 0x0a) # should succeed
|
||||
|
||||
# test DMA mem_read
|
||||
i2c.mem_read(1, 76, 0x0a) # should succeed
|
||||
try:
|
||||
i2c.mem_read(1, 77, 0x0a) # should fail
|
||||
except OSError as e:
|
||||
print(repr(e))
|
||||
i2c.mem_read(1, 76, 0x0a) # should succeed
|
||||
|
||||
# test DMA mem_write
|
||||
i2c.mem_write(1, 76, 0x0a) # should succeed
|
||||
try:
|
||||
i2c.mem_write(1, 77, 0x0a) # should fail
|
||||
except OSError as e:
|
||||
print(repr(e))
|
||||
i2c.mem_write(1, 76, 0x0a) # should succeed
|
4
tests/pyb/i2c_error.py.exp
Normal file
4
tests/pyb/i2c_error.py.exp
Normal file
@ -0,0 +1,4 @@
|
||||
OSError(5,)
|
||||
OSError(5,)
|
||||
OSError(5,)
|
||||
OSError(5,)
|
Loading…
x
Reference in New Issue
Block a user