Add ESP8266 tests.

pull/1/head
Peter Hinch 2020-01-11 18:02:19 +00:00
rodzic bc8b29ea84
commit 9466ad2061
4 zmienionych plików z 247 dodań i 16 usunięć

Wyświetl plik

@ -26,18 +26,21 @@ the subsequent improvements to MicroPython to achieve these advantages:
Any I2C interface may be used. The table below assumes a Pyboard running I2C(2)
as per the test program. To wire up a single EEPROM chip, connect to a Pyboard
as below. Pin numbers assume a PDIP package (8 pin plastic dual-in-line).
or ESP8266 as below. Any ESP8266 pins may be used, those listed below are as
used in the test program.
| EEPROM | PB |
|:------:|:---:|
| 1 A0 | Gnd |
| 2 A1 | Gnd |
| 3 A2 | Gnd |
| 4 Vss | Gnd |
| 5 Sda | Y10 |
| 6 Scl | Y9 |
| 7 WPA1 | Gnd |
| 8 Vcc | 3V3 |
EEPROM Pin numbers assume a PDIP package (8 pin plastic dual-in-line).
| EEPROM | PB | ESP8266 |
|:------:|:---:|:-------:|
| 1 A0 | Gnd | Gnd |
| 2 A1 | Gnd | Gnd |
| 3 A2 | Gnd | Gnd |
| 4 Vss | Gnd | Gnd |
| 5 Sda | Y10 | 12 D6 |
| 6 Scl | Y9 | 13 D7 |
| 7 WPA1 | Gnd | Gnd |
| 8 Vcc | 3V3 | 3V3 |
For multiple chips the address lines A0, A1 and A2 of each chip need to be
wired to 3V3 in such a way as to give each device a unique address. These must
@ -72,9 +75,11 @@ Other platforms may vary.
1. `eeprom_i2c.py` Device driver.
2. `bdevice.py` (In root directory) Base class for the device driver.
3. `eep_i2c.py` Test programs for above.
3. `eep_i2c.py` Pyboard test programs for above.
4. `wemos_i2c_eeprom.py` Test program using a Wemos D1 mini ESP8266 board.
Installation: copy files 1 and 2 (optionally 3) to the target filesystem.
Installation: copy files 1 and 2 (optionally 3 and/or 4) to the target
filesystem.
# 4. The device driver

Wyświetl plik

@ -0,0 +1,134 @@
# wemos_fi2c_eeprom.py Test I2C EEPROM chips with ESP8266 host
# Released under the MIT License (MIT). See LICENSE.
# Copyright (c) 2020 Peter Hinch
import uos
from machine import I2C, Pin
from eeprom_i2c import EEPROM, T24C512
i2c=I2C(-1, scl=Pin(13, Pin.OPEN_DRAIN), sda=Pin(12, Pin.OPEN_DRAIN))
# Return an EEPROM array. Adapt for platforms other than Pyboard or chips
# smaller than 64KiB.
def get_eep():
eep = EEPROM(i2c, T24C512)
print('Instantiated EEPROM')
return eep
# Dumb file copy utility to help with managing EEPROM contents at the REPL.
def cp(source, dest):
if dest.endswith('/'): # minimal way to allow
dest = ''.join((dest, source.split('/')[-1])) # cp /sd/file /eeprom/
with open(source, 'rb') as infile: # Caller should handle any OSError
with open(dest,'wb') as outfile: # e.g file not found
while True:
buf = infile.read(100)
outfile.write(buf)
if len(buf) < 100:
break
# ***** TEST OF DRIVER *****
def _testblock(eep, bs):
d0 = b'this >'
d1 = b'<is the boundary'
d2 = d0 + d1
garbage = b'xxxxxxxxxxxxxxxxxxx'
start = bs - len(d0)
end = start + len(garbage)
eep[start : end] = garbage
res = eep[start : end]
if res != garbage:
return 'Block test fail 1:' + str(list(res))
end = start + len(d0)
eep[start : end] = d0
end = start + len(garbage)
res = eep[start : end]
if res != b'this >xxxxxxxxxxxxx':
return 'Block test fail 2:' + str(list(res))
start = bs
end = bs + len(d1)
eep[start : end] = d1
start = bs - len(d0)
end = start + len(d2)
res = eep[start : end]
if res != d2:
return 'Block test fail 3:' + str(list(res))
def test():
eep = get_eep()
sa = 1000
for v in range(256):
eep[sa + v] = v
for v in range(256):
if eep[sa + v] != v:
print('Fail at address {} data {} should be {}'.format(sa + v, eep[sa + v], v))
break
else:
print('Test of byte addressing passed')
data = uos.urandom(30)
sa = 2000
eep[sa:sa + 30] = data
if eep[sa:sa + 30] == data:
print('Test of slice readback passed')
block = 256
res = _testblock(eep, block)
if res is None:
print('Test block boundary {} passed'.format(block))
else:
print('Test block boundary {} fail'.format(block))
print(res)
block = eep._c_bytes
if eep._a_bytes > block:
res = _testblock(eep, block)
if res is None:
print('Test chip boundary {} passed'.format(block))
else:
print('Test chip boundary {} fail'.format(block))
print(res)
else:
print('Test chip boundary skipped: only one chip!')
# ***** TEST OF FILESYSTEM MOUNT *****
def fstest(format=False):
eep = get_eep()
# ***** CODE FOR LITTLEFS *****
if format:
uos.VfsLfs2.mkfs(eep)
try:
uos.mount(eep,'/eeprom')
except OSError: # Already mounted
pass
print('Contents of "/": {}'.format(uos.listdir('/')))
print('Contents of "/eeprom": {}'.format(uos.listdir('/eeprom')))
print(uos.statvfs('/eeprom'))
def cptest():
eep = get_eep()
if 'eeprom' in uos.listdir('/'):
print('Device already mounted.')
else:
try:
uos.mount(eep,'/eeprom')
except OSError:
print('Fail mounting device. Have you formatted it?')
return
print('Mounted device.')
cp('eep_i2c.py', '/eeprom/')
cp('eeprom_i2c.py', '/eeprom/')
print('Contents of "/eeprom": {}'.format(uos.listdir('/eeprom')))
print(uos.statvfs('/eeprom'))
# ***** TEST OF HARDWARE *****
def full_test():
eep = get_eep()
page = 0
for sa in range(0, len(eep), 128):
data = uos.urandom(128)
eep[sa:sa + 128] = data
if eep[sa:sa + 128] == data:
print('Page {} passed'.format(page))
else:
print('Page {} readback failed.'.format(page))
page += 1

Wyświetl plik

@ -47,8 +47,9 @@ connected to 3V3 or left unconnected.
| 8 | Vcc | 3V3 | 3V3 |
For multiple chips a separate CS pin must be assigned to each chip: each one
being wired to a single chip's CS line. Multiple chips should have 3V3, Gnd,
SCL, MOSI and MISO lines wired in parallel.
being wired to a single chip's CS line. The test program assumes a second chip
with CS connected to Y4. Multiple chips should have 3V3, Gnd, SCL, MOSI and
MISO lines wired in parallel.
If you use a Pyboard D and power the chips from the 3V3 output you will need
to enable the voltage rail by issuing:
@ -72,8 +73,9 @@ Bus lines should be short and direct.
3. `flash_test.py` Test programs for above.
4. `littlefs_test.py` Torture test for the littlefs filesystem on the flash
array. Requires `flash_test.py` which it uses for hardware configuration.
5. `wemos_flash.py` Test program running on a Wemos D1 Mini ESP8266 board.
Installation: copy files 1 and 2 (3 & 4 are optional) to the target filesystem.
Installation: copy files 1 and 2 (3 - 5 are optional) to the target filesystem.
The `flash_test` script assumes two S25FL256L chips connected to SPI(2) with
CS/ pins wired to Pyboard pins Y4 and Y5. The `get_device` function may be
adapted for other setups and is shared with `littlefs_test`.

Wyświetl plik

@ -0,0 +1,90 @@
# wemos_flash.py Test flash chips with ESP8266 host
# Released under the MIT License (MIT). See LICENSE.
# Copyright (c) 2020 Peter Hinch
import uos
from machine import SPI, Pin
from flash_spi import FLASH
cspins = (Pin(5, Pin.OUT, value=1), Pin(14, Pin.OUT, value=1))
spi=SPI(-1, baudrate=20_000_000, sck=Pin(4), miso=Pin(0), mosi=Pin(2))
def get_flash():
flash = FLASH(spi, cspins)
print('Instantiated Flash')
return flash
directory = '/fl_ext'
a = bytearray(range(256)) # Data to write
b = bytearray(256) # Data to read back
files = {} # n:length
errors = 0
def fname(n):
return '{}/{:05d}'.format(directory, n + 1) # Names start 00001
def fcreate(n): # Create a binary file of random length
length = int.from_bytes(uos.urandom(2), 'little') + 1 # 1-65536 bytes
linit = length
with open(fname(n), 'wb') as f:
while(length):
nw = min(length, 256)
f.write(a[:nw])
length -= nw
files[n] = length
return linit
def fcheck(n):
length = files[n]
with open(fname(n), 'rb') as f:
while(length):
nr = f.readinto(b)
if not nr:
return False
if a[:nr] != b[:nr]:
return False
length -= nr
return True
def check_all():
global errors
for n in files:
if fcheck(n):
print('File {:d} OK'.format(n))
else:
print('Error in file', n)
errors += 1
print('Total errors:', errors)
def remove_all():
for n in files:
uos.remove(fname(n))
def flash_test(format=False):
eep = get_flash()
if format:
uos.VfsLfs2.mkfs(eep)
try:
uos.mount(eep,'/fl_ext')
except OSError: # Already mounted
pass
for n in range(128):
length = fcreate(n)
print('Created', n, length)
print('Created files', files)
check_all()
for _ in range(100):
for x in range(5): # Rewrite 5 files with new lengths
n = int.from_bytes(uos.urandom(1), 'little') & 0x7f
length = fcreate(n)
print('Rewrote', n, length)
check_all()
remove_all()
msg='''Run wemos_flash.flash_test(True) to format new array, otherwise
wemos_flash.flash_test()
Runs prolonged test of filesystem.'''
print(msg)