summaryrefslogtreecommitdiffstatshomepage
path: root/tests
diff options
context:
space:
mode:
authorDaniel Campora <daniel@wipy.io>2015-09-07 21:19:11 +0200
committerDaniel Campora <daniel@wipy.io>2015-09-10 08:00:12 +0200
commit4d7fa05b43cb3db88a6ecacf8406d2636f202aba (patch)
treee9333fd94b157e2274cad16c53d2900216099a43 /tests
parent4054c4eadd13fa3aaacb96202cdfb1a666484b5c (diff)
downloadmicropython-4d7fa05b43cb3db88a6ecacf8406d2636f202aba.tar.gz
micropython-4d7fa05b43cb3db88a6ecacf8406d2636f202aba.zip
cc3200: Improve Pin and UART implementation.
Deassign pins af before assigning. Make uart.any() return the correct value everytime, this requires interrupts to be always enabled.
Diffstat (limited to 'tests')
-rw-r--r--tests/wipy/pin.py15
-rw-r--r--tests/wipy/pin.py.exp2
-rw-r--r--tests/wipy/uart.py61
-rw-r--r--tests/wipy/uart.py.exp8
4 files changed, 61 insertions, 25 deletions
diff --git a/tests/wipy/pin.py b/tests/wipy/pin.py
index 20bea3e5a7..ae0fa82b19 100644
--- a/tests/wipy/pin.py
+++ b/tests/wipy/pin.py
@@ -7,10 +7,10 @@ import os
machine = os.uname().machine
if 'LaunchPad' in machine:
pin_map = ['GP24', 'GP12', 'GP14', 'GP15', 'GP16', 'GP17', 'GP28', 'GP8', 'GP6', 'GP30', 'GP31', 'GP3', 'GP0', 'GP4', 'GP5']
- af_range = range(1, 16)
+ max_af_idx = 15
elif 'WiPy' in machine:
pin_map = ['GP23', 'GP24', 'GP12', 'GP13', 'GP14', 'GP9', 'GP17', 'GP28', 'GP22', 'GP8', 'GP30', 'GP31', 'GP0', 'GP4', 'GP5']
- af_range = range(1, 16)
+ max_af_idx = 15
else:
raise Exception('Board not supported!')
@@ -28,9 +28,10 @@ def test_pin_read(pull):
def test_pin_af():
for p in pin_map:
- for n in af_range:
- Pin(p, mode=Pin.ALT, alt=n)
- Pin(p, mode=Pin.ALT_OPEN_DRAIN, alt=n)
+ for af in Pin(p).alt_list():
+ if af[1] <= max_af_idx:
+ Pin(p, mode=Pin.ALT, alt=af[1])
+ Pin(p, mode=Pin.ALT_OPEN_DRAIN, alt=af[1])
# test un-initialized pins
test_noinit()
@@ -67,10 +68,6 @@ pin.init(mode=Pin.OUT, pull=Pin.PULL_UP, drive=pin.LOW_POWER)
print(pin)
pin.init(mode=Pin.OUT, pull=Pin.PULL_UP, drive=pin.HIGH_POWER)
print(pin)
-pin = Pin(pin_map[0], Pin.ALT, Pin.PULL_NONE, alt=1)
-print(pin)
-pin = Pin(pin_map[0], Pin.ALT_OPEN_DRAIN, Pin.PULL_NONE, alt=15)
-print(pin)
# test value in OUT mode
pin = Pin(pin_map[0], mode=Pin.OUT)
diff --git a/tests/wipy/pin.py.exp b/tests/wipy/pin.py.exp
index 87b4d3ef85..4fc60b5d79 100644
--- a/tests/wipy/pin.py.exp
+++ b/tests/wipy/pin.py.exp
@@ -32,8 +32,6 @@ Pin('GP23', mode=Pin.IN, pull=Pin.PULL_NONE, drive=Pin.MED_POWER, alt=-1)
Pin('GP23', mode=Pin.IN, pull=Pin.PULL_DOWN, drive=Pin.MED_POWER, alt=-1)
Pin('GP23', mode=Pin.OUT, pull=Pin.PULL_UP, drive=Pin.LOW_POWER, alt=-1)
Pin('GP23', mode=Pin.OUT, pull=Pin.PULL_UP, drive=Pin.HIGH_POWER, alt=-1)
-Pin('GP23', mode=Pin.ALT, pull=Pin.PULL_NONE, drive=Pin.MED_POWER, alt=1)
-Pin('GP23', mode=Pin.ALT_OPEN_DRAIN, pull=Pin.PULL_NONE, drive=Pin.MED_POWER, alt=15)
1
0
1
diff --git a/tests/wipy/uart.py b/tests/wipy/uart.py
index a483891ad8..31a2c3a0ab 100644
--- a/tests/wipy/uart.py
+++ b/tests/wipy/uart.py
@@ -6,6 +6,7 @@ UART0 and UART1 must be connected together for this test to pass.
from pyb import UART
from pyb import Pin
import os
+import pyb
machine = os.uname().machine
if 'LaunchPad' in machine:
@@ -25,12 +26,6 @@ for uart_id in uart_id_range:
uart.init(baudrate=115200, parity=1, pins=uart_pins[uart_id][0])
uart.sendbreak()
-# assign GP1, GP2, GP3 and GP4 back to GPIO mode
-Pin('GP1', mode=Pin.IN)
-Pin('GP2', mode=Pin.IN)
-Pin('GP3', mode=Pin.IN)
-Pin('GP4', mode=Pin.IN)
-
# now it's time for some loopback tests between the uarts
uart0 = UART(0, 1000000, pins=uart_pins[0][0])
print(uart0)
@@ -52,16 +47,16 @@ print(buf)
print(uart1.readinto(buf) == 2)
print(buf)
-uart0.write(b'123')
-print(uart1.any() > 0)
-print(uart1.readline() == b'123')
+uart0.write(b'1234567890')
+pyb.delay(2) # because of the fifo interrupt levels
+print(uart1.any() == 10)
+print(uart1.readline() == b'1234567890')
print(uart1.any() == 0)
uart0.write(b'1234567890')
print(uart1.readall() == b'1234567890')
# tx only mode
-Pin('GP13', mode=Pin.IN)
uart0 = UART(0, 1000000, pins=('GP12', None))
print(uart0.write(b'123456') == 6)
print(uart1.read() == b'123456')
@@ -69,17 +64,21 @@ print(uart1.write(b'123') == 3)
print(uart0.read() == b'')
# rx only mode
-Pin('GP12', mode=Pin.IN)
uart0 = UART(0, 1000000, pins=(None, 'GP13'))
print(uart0.write(b'123456') == 6)
print(uart1.read() == b'')
print(uart1.write(b'123') == 3)
print(uart0.read() == b'123')
-Pin('GP13', mode=Pin.IN)
-Pin('GP12', mode=Pin.IN)
-# no pin assignemnt
+# leave pins as they were (rx only mode)
uart0 = UART(0, 1000000, pins=None)
+print(uart0.write(b'123456') == 6)
+print(uart1.read() == b'')
+print(uart1.write(b'123') == 3)
+print(uart0.read() == b'123')
+
+# no pin assignemnt
+uart0 = UART(0, 1000000, pins=(None, None))
print(uart0.write(b'123456789') == 9)
print(uart1.read() == b'')
print(uart1.write(b'123456789') == 9)
@@ -87,12 +86,46 @@ print(uart0.read() == b'')
print(Pin.board.GP12)
print(Pin.board.GP13)
+# check for memory leaks...
+for i in range (0, 1000):
+ uart0 = UART(0, 1000000)
+ uart1 = UART(1, 1000000)
+
# next ones must raise
try:
UART(0, 9600, parity=2, pins=('GP12', 'GP13', 'GP7'))
except Exception:
print('Exception')
+
try:
UART(0, 9600, parity=2, pins=('GP12', 'GP7'))
except Exception:
print('Exception')
+
+uart0 = UART(0, 1000000)
+uart0.deinit()
+try:
+ uart0.any()
+except Exception:
+ print('Exception')
+
+uart0 = UART(0, 1000000)
+uart0.deinit()
+try:
+ uart0.read()
+except Exception:
+ print('Exception')
+
+uart0 = UART(0, 1000000)
+uart0.deinit()
+try:
+ uart0.write('abc')
+except Exception:
+ print('Exception')
+
+uart0 = UART(0, 1000000)
+uart0.deinit()
+try:
+ uart0.sendbreak('abc')
+except Exception:
+ print('Exception')
diff --git a/tests/wipy/uart.py.exp b/tests/wipy/uart.py.exp
index a5c6da1e8f..7234b35190 100644
--- a/tests/wipy/uart.py.exp
+++ b/tests/wipy/uart.py.exp
@@ -28,7 +28,15 @@ True
True
True
True
+True
+True
+True
+True
Pin('GP12', mode=Pin.IN, pull=Pin.PULL_NONE, drive=Pin.MED_POWER, alt=-1)
Pin('GP13', mode=Pin.IN, pull=Pin.PULL_NONE, drive=Pin.MED_POWER, alt=-1)
Exception
Exception
+Exception
+Exception
+Exception
+Exception