Save problematic version.

pull/13/head
Peter Hinch 2020-02-13 09:09:07 +00:00
rodzic 82104ac4cc
commit cb1c33303e
3 zmienionych plików z 23 dodań i 8 usunięć

Wyświetl plik

@ -63,7 +63,10 @@ class BlockDevice:
return return
def readblocks(self, blocknum, buf, offset=0): def readblocks(self, blocknum, buf, offset=0):
self.readwrite(offset + (blocknum << self._nbits), buf, True) if blocknum < 0 or (offset + (blocknum << self._nbits)) > self._a_bytes:
print('rb', hex(blocknum), offset, hex(offset + (blocknum << self._nbits)))
else:
self.readwrite(offset + (blocknum << self._nbits), buf, True)
def writeblocks(self, blocknum, buf, offset=0): def writeblocks(self, blocknum, buf, offset=0):
self.readwrite(offset + (blocknum << self._nbits), buf, False) self.readwrite(offset + (blocknum << self._nbits), buf, False)

Wyświetl plik

@ -133,20 +133,26 @@ each chip select line a flash array is instantiated. A `RuntimeError` will be
raised if a device is not detected on a CS line. The test has no effect on raised if a device is not detected on a CS line. The test has no effect on
the array contents. the array contents.
Arguments: Arguments. In most cases only the first two mandatory args are required:
1. `spi` Mandatory. An initialised SPI bus created by `machine`. 1. `spi` An initialised SPI bus created by `machine`.
2. `cspins` A list or tuple of `Pin` instances. Each `Pin` must be initialised 2. `cspins` A list or tuple of `Pin` instances. Each `Pin` must be initialised
as an output (`Pin.OUT`) and with `value=1` and be created by `machine`. as an output (`Pin.OUT`) and with `value=1` and be created by `machine`.
3. `size=None` Chip size in KiB. The size is read from the chip. If a value 3. `size=None` Chip size in KiB. The size is read from the chip. If a value
is passed, the actual size is compared with the passed value: a mismatch will is passed, the actual size is compared with the passed value: a mismatch will
raise a `ValueError`. Optionally set to 32768 for the S25FL256L chip or 16384 raise a `ValueError`. A `ValueError` will also occur if chips in the array
for the S25FL128L. have differing sizes. See table below for values.
4. `verbose=True` If `True`, the constructor issues information on the flash 4. `verbose=True` If `True`, the constructor issues information on the flash
devices it has detected. devices it has detected.
5. `sec_size=4096` Chip sector size. 5. `sec_size=4096` Chip sector size.
6. `block_size=9` The block size reported to the filesystem. The size in bytes 6. `block_size=9` The block size reported to the filesystem. The size in bytes
is `2**block_size` so is 512 bytes by default. is `2**block_size` so is 512 bytes by default.
Size values:
| Chip | Size |
|:---------:|:-----:|
| S25FL256L | 32768 |
| S25FL128L | 16384 |
### 4.1.2 Methods providing byte level access ### 4.1.2 Methods providing byte level access
It is possible to read and write individual bytes or arrays of arbitrary size. It is possible to read and write individual bytes or arrays of arbitrary size.

Wyświetl plik

@ -63,8 +63,8 @@ class FLASH(FlashDevice):
cs(1) cs(1)
scansize = 1 << (mvp[3] - 10) scansize = 1 << (mvp[3] - 10)
if size is None: if size is None:
size = scansize size = scansize # Save size of 1st chip
if size != scansize: if size != scansize: # Mismatch passed size or 1st chip.
raise ValueError('Flash size mismatch: expected {}KiB, found {}KiB'.format(size, scansize)) raise ValueError('Flash size mismatch: expected {}KiB, found {}KiB'.format(size, scansize))
if verbose: if verbose:
s = '{} chips detected. Total flash size {}MiB.' s = '{} chips detected. Total flash size {}MiB.'
@ -152,10 +152,16 @@ class FLASH(FlashDevice):
# Given an address, set current chip select and address buffer. # Given an address, set current chip select and address buffer.
# Return the number of bytes that can be processed in the current chip. # Return the number of bytes that can be processed in the current chip.
def _getaddr(self, addr, nbytes): def _getaddr(self, addr, nbytes):
# print(hex(addr), hex(self._a_bytes), hex(self._c_bytes), self._nbits, self._block_size, divmod(addr, self._c_bytes))
if addr >= self._a_bytes: if addr >= self._a_bytes:
# print(hex(addr), hex(self._a_bytes), hex(self._c_bytes), self._nbits, self._block_size, divmod(addr, self._c_bytes))
raise RuntimeError("Flash Address is out of range") raise RuntimeError("Flash Address is out of range")
ca, la = divmod(addr, self._c_bytes) # ca == chip no, la == offset into chip ca, la = divmod(addr, self._c_bytes) # ca == chip no, la == offset into chip
self._ccs = self._cspins[ca] # Current chip select try:
self._ccs = self._cspins[ca] # Current chip select
except:
print(ca, la)
raise
cmdlen = self._cmdlen cmdlen = self._cmdlen
mvp = self._mvp[:cmdlen] mvp = self._mvp[:cmdlen]
if cmdlen > 3: if cmdlen > 3: