diff options
author | Peter Hinch <peter@hinch.me.uk> | 2016-01-30 07:21:43 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2016-02-02 11:16:15 +0000 |
commit | 2bd758fe96e2913f48c1a0fdccafddc3dfb31cf9 (patch) | |
tree | d550b5a4b1a6638882353c79d89f082eb2aaa2ab /drivers/sdcard/sdtest.py | |
parent | 67e810834569ec63d85016bff8e619a933b65c3a (diff) | |
download | micropython-2bd758fe96e2913f48c1a0fdccafddc3dfb31cf9.tar.gz micropython-2bd758fe96e2913f48c1a0fdccafddc3dfb31cf9.zip |
drivers/sdcard: Add support for multi-block read/write; add SD test.
Diffstat (limited to 'drivers/sdcard/sdtest.py')
-rw-r--r-- | drivers/sdcard/sdtest.py | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/drivers/sdcard/sdtest.py b/drivers/sdcard/sdtest.py new file mode 100644 index 0000000000..438baa245d --- /dev/null +++ b/drivers/sdcard/sdtest.py @@ -0,0 +1,57 @@ +# Test for sdcard block protocol +# Peter hinch 30th Jan 2016 +import os, sdcard, pyb + +def sdtest(): + sd = sdcard.SDCard(pyb.SPI(1), pyb.Pin.board.X21) # Compatible with PCB + pyb.mount(sd, '/fc') + print('Filesystem check') + print(os.listdir('/fc')) + + line = 'abcdefghijklmnopqrstuvwxyz\n' + lines = line * 200 # 5400 chars + short = '1234567890\n' + + fn = '/fc/rats.txt' + print() + print('Multiple block read/write') + with open(fn,'w') as f: + n = f.write(lines) + print(n, 'bytes written') + n = f.write(short) + print(n, 'bytes written') + n = f.write(lines) + print(n, 'bytes written') + + with open(fn,'r') as f: + result1 = f.read() + print(len(result1), 'bytes read') + + fn = '/fc/rats1.txt' + print() + print('Single block read/write') + with open(fn,'w') as f: + n = f.write(short) # one block + print(n, 'bytes written') + + with open(fn,'r') as f: + result2 = f.read() + print(len(result2), 'bytes read') + + pyb.mount(None, '/fc') + + print() + print('Verifying data read back') + success = True + if result1 == ''.join((lines, short, lines)): + print('Large file Pass') + else: + print('Large file Fail') + success = False + if result2 == short: + print('Small file Pass') + else: + print('Small file Fail') + success = False + print() + print('Tests', 'passed' if success else 'failed') |