diff options
author | Daniel Campora <daniel@wipy.io> | 2015-09-07 21:19:11 +0200 |
---|---|---|
committer | Daniel Campora <daniel@wipy.io> | 2015-09-10 08:00:12 +0200 |
commit | 4d7fa05b43cb3db88a6ecacf8406d2636f202aba (patch) | |
tree | e9333fd94b157e2274cad16c53d2900216099a43 /tests/wipy/uart.py | |
parent | 4054c4eadd13fa3aaacb96202cdfb1a666484b5c (diff) | |
download | micropython-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/wipy/uart.py')
-rw-r--r-- | tests/wipy/uart.py | 61 |
1 files changed, 47 insertions, 14 deletions
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') |