SPI flash ... TODO

Discuss development of drivers for external hardware and components, such as LCD screens, sensors, motor drivers, etc.
Target audience: Users and developers of drivers.
manitou
Posts: 73
Joined: Wed Feb 25, 2015 12:15 am

SPI flash ... TODO

Post by manitou » Sun Jun 21, 2015 2:45 pm

There are various makes and models of SPI flash. They share a "mostly" standard set of SPI commands. The ESP8266 has an onboard winbond SPI flash. I did some pyboard tests with the Adafruit 1MB 8-pin DIP chip.
http://www.adafruit.com/product/1564

pyboard SPI flash tests:
I developed/hacked a "classless" set of python functions to exercise the Adafruit SPI flash, see
https://github.com/manitou48/pyboard/bl ... piflash.py
With breadboard and jumpers, I hooked the SPI flash to SPI1 of the pyboard. The specs say the flash SPI can operate up to 104MHz. I configured SPI1 to max speed of 42MHz. read speed is limited by the SPI speed. erase and write times are limited by the SPI flash. Maximum write unit per SPI transaction is 256 bytes. Here are some performance results:

Code: Select all

Erase times (microseconds)
block   microseconds
 4K         33109
32K        100354
64K        116908
chip      1162603

Write speed (megabits/second)
256 bytes   2.176 mbs
512 bytes   2.197 mbs

Read speed (mbs)
512 bytes    19.8 mbs
 1K          26.3
 4K          36.5
 8K          39.3
16K          40.6
32K          41.3
64000        41.6
For comparison, some performance numbers for pyboard SD, flash, and SPI SD (sdcard.py) are at
http://forum.micropython.org/viewtopic. ... =469#p4176

Paul has a teensy 3 library (C++) that supports various makes and models of SPI flash and has a simple file system for the SPI flash, see
https://github.com/PaulStoffregen/SerialFlash


TODO ...
Someone could develop a set of micropython classes to support the makes and models of SPI flash. There is already a python library that could be adapted to pyboard/micropython. See
https://github.com/eblot/pyspiflash/tre ... r/spiflash
On top of that, you could add a FAT wrapper in the spirit of the pyboard's firmware sdcard.py, so you could mount the SPI flash as a file system.

oscar.lambri
Posts: 15
Joined: Mon Jun 01, 2015 4:36 pm

Re: SPI flash ... TODO

Post by oscar.lambri » Wed Jan 13, 2016 3:37 pm

Hi, I am also interested in using a spi flash (AT45DB641E) with FAT-FS, how can I do to add this option to the source files.

Best regards,

Oscar

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: SPI flash ... TODO

Post by dhylands » Wed Jan 13, 2016 9:29 pm

Support for this is already in the tree.

There is some documentation here:
http://docs.micropython.org/en/latest/l ... #pyb.mount

You basically implement a python class which implements a certain set of functions (which in your case would read/write blocks to the SPI flash).

There is an example which uses an sdcard connected over a SPI bus:
https://github.com/micropython/micropyt ... /sdcard.py

oscar.lambri
Posts: 15
Joined: Mon Jun 01, 2015 4:36 pm

Re: SPI flash ... TODO

Post by oscar.lambri » Thu Jan 14, 2016 8:29 am

Thank you!

Best regards,

Oscar.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: SPI flash ... TODO

Post by pythoncoder » Thu Jan 14, 2016 9:35 am

If you are programming flash at the chip level you need to get involved at a deeper level than the standard SD card driver to handle the gory details of sector buffering and erasing. You might like to look at flash.py here, which is a driver for the Winbond W25Q32 32Mbit chip. https://github.com/peterhinch/micropython-epaper.git.

The MicroPython block device API is excellent - I've used it several times and it works perfectly.

A thing to note: when writing a file, FAT does repeated writes to sectors near the start. To minimise wear I implemented a caching scheme supporting two sectors. There's a tradeoff here between performance and RAM usage: more sectors would be better but RAM is limited.

I have my doubts about writing a generic driver - I suspect the differences between chips may make this impractical. Lastly, with the Winbond chip and my driver, write performance is limited by the erase time which is significant. My intended application was read-mostly, with the flash chip being used to store files loaded at design time. A more generally useful driver would implement a means of performing erasure as a background task - something presumably handled by the controller chip on a uSD card.
Peter Hinch
Index to my micropython libraries.

oscar.lambri
Posts: 15
Joined: Mon Jun 01, 2015 4:36 pm

Re: SPI flash ... TODO

Post by oscar.lambri » Thu Jan 14, 2016 10:40 am

Hi, it's possible to recompile the firmware for have

+---------------------------------+
| |
| micropyton board |
| |
+---------------------------------+
|
+
|
+---------------------------------+
| spi flash (example 128MB) |
| like a disk /spi_disk |
+---------------------------------+

I wish to see the spi flash like a disk when the pyboard it's plug on the pc
I wish to save and run all the micropyton code on this new disk.

Best regards, Oscar.

oscar.lambri
Posts: 15
Joined: Mon Jun 01, 2015 4:36 pm

Re: SPI flash ... TODO

Post by oscar.lambri » Thu Jan 14, 2016 10:48 am

Thank you pythoncoder,

for the clarification.

Oscar.

oscar.lambri
Posts: 15
Joined: Mon Jun 01, 2015 4:36 pm

Re: SPI flash ... TODO

Post by oscar.lambri » Thu Jan 14, 2016 11:37 am


oscar.lambri
Posts: 15
Joined: Mon Jun 01, 2015 4:36 pm

Re: SPI flash ... TODO

Post by oscar.lambri » Thu Jan 14, 2016 1:39 pm

Hi,

for have more space for code, is possible resize the flash disk ?

Is possbile remove some librares and recompile the firmware?

Best regards,

Oscar.

oscar.lambri
Posts: 15
Joined: Mon Jun 01, 2015 4:36 pm

Re: SPI flash ... TODO

Post by oscar.lambri » Thu Jan 14, 2016 2:15 pm

... for example, can I remove the SD card library from the firmware?

Post Reply