API
Winbond Flash
Implementation to interact with Winbond W25Q Flash with software reset.
Credits & kudos to crizeo Taken from https://forum.micropython.org/viewtopic.php?f=16&t=3899
- class winbond.winbond.W25QFlash(spi: <Mock name='mock.SPI' id='139858710143088'>, cs: <Mock name='mock.Pin' id='139858710143136'>, baud: int = 40000000, software_reset: bool = True)[source]
Bases:
object
W25QFlash implementation
- _read(buf: list, addr: int) None [source]
Read the length of the buffer bytes from the chip.
The buffer length has to be a multiple of self.SECTOR_SIZE (or less).
- _sector_erase(addr) None [source]
Resets all memory within the specified sector (4kB) to 0xFF
- Parameters
addr (int) – The address
- _write(buf: list, addr: int) None [source]
Write the data of the given buffer to the address location
Writes the data from <buf> to the device starting at <addr>, which has to be erased (0xFF) before. Last byte of <addr> has to be zero, which means <addr> has to be a multiple of self.PAGE_SIZE (= start of page), because wrapping to the next page (if page size exceeded) is implemented for full pages only. Length of <buf> has to be a multiple of self.PAGE_SIZE, because only full pages are supported at the moment (<addr> will be auto-incremented).
- _writeblock(blocknum: int, buf: list) None [source]
Write a data block.
To write a block, the sector (e.g. 4kB = 8 blocks) has to be erased first. Therefore, a sector will be read and saved in cache first, then the given block will be replaced and the whole sector written back when
- property capacity: int
Get the storage capacity of the flash
- Returns
Capacity of the flash in bytes
- Return type
- count() int [source]
Return the number of blocks available on the device
- Returns
Number of blocks
- Return type
- format() None [source]
Format the Winbond flash chip by resetting all memory to 0xFF.
Important: Run “os.VfsFat.mkfs(flash)” to make the flash an accessible file system. As always, you will then need to run “os.mount(flash, ‘/MyFlashDir’)” then to mount the flash
- identify() None [source]
Identify the Winbond chip.
Determine the manufacturer and device ID and raises an error if the device is not detected or not supported. The capacity variable is set to the number of blocks (calculated based on the detected chip).
- property manufacturer: int
Get the manufacturer ID of the flash
- Returns
Manufacturer ID of the flash
- Return type
- property mem_type: int
Get the memory type of the flash
- Returns
Memory type of the flash
- Return type
- readblocks(blocknum: int, buf: list) None [source]
Read a data block. The length has to be a multiple of self.BLOCK_SIZE
- reset() None [source]
Reset the Winbond flash if the device has no hardware reset pin.
See datasheet section 7.2.43 Enable Reset (66h) and Reset (99h) Because of the small package and the limitation on the number of pins, the W25Q64FV provide a software Reset instruction instead of a dedicated RESET pin. Once the Reset instruction is accepted, any on-going internal operations will be terminated and the device will return to its default power-on state and lose all the current volatile settings, such as Volatile Status Register bits, Write Enable Latch (WEL) status, Program/Erase Suspend status, Read parameter setting (P7-P0), Continuous Read Mode bit setting (M7-M0) and Wrap Bit setting (W6-W4). “Enable Reset (66h)” and “Reset (99h)” instructions can be issued in either SPI mode or QPI mode. To avoid accidental reset, both instructions must be issued in sequence. Any other commands other than “Reset (99h)” after the “Enable Reset (66h)” command will disable the “Reset Enable” state. A new sequence of “Enable Reset (66h)” and “Reset (99h)” is needed to reset the device. Once the Reset command is accepted by the device, the device will take approximately tRST=30us to reset. During this period, no command will be accepted. Data corruption may happen if there is an on-going or suspended internal Erase or Program operation when Reset command sequence is accepted by the device. It is recommended to check the BUSY bit and the SUS bit in Status Register before issuing the Reset command sequence.