Skip to content

Arduino Library for SPI Flash memory chips

Compare
Choose a tag to compare
@Marzogh Marzogh released this 17 Nov 02:27
· 226 commits to master since this release
4347aee

SPIFlash Build Status DOI

GitHub release
GitHub commits
GitHub issues
GitHub pull requests
license


Please report any bugs in issues


Arduino library for Flash Memory Chips (SPI based only)

Download the latest stable release (v3.0.0) from here. Please report any bugs in issues.

This Arduino library is for use with flash memory chips that communicate using the SPI protocol. In its current form it supports identifying the flash chip and its various features; automatic address allocation and management; writing and reading a number of different types of data, ranging from 8-bit to 32-bit (signed and unsigned) values, floats, Strings, arrays of bytes/chars and structs to and from various locations; sector, block and chip erase; and powering down for low power operation.

  • For details of the Flash chips compatible with this library please refer to the list below.

Compatibility

Arduino IDEs supported (actually tested with)
  • IDE v1.5.x
  • IDE v1.6.0-v1.6.5
  • IDE v1.6.9-v1.6.12
  • IDE v1.8.1-v1.8.5
Boards
Completely supported
  • Arduino Uno
  • Arduino Leonardo
  • Arduino Due
  • Arduino Zero
  • Nucleo-F091RC
  • Adafruit Feather M0
  • Adafruit Feather M0 Express
  • ESP8266 Boards (On the Arduino IDE)
  • Simblee Boards (On the Arduino IDE)
  • Arduino Mega
  • Arduino Micro
  • Arduino Fio
In BETA
  • ESP32 Boards (Tested on the Adafruit ESP32 Feather) The library is known to work with the ESP32 core as of the current commit 8ba91b9 on 07.11.2017. ESP32 support will remain in beta till the ESP32 core can be installed via the Arduino boards manager.
    NOTE: ESP32 boards usually have an SPIFlash already attached to their SS pin, so the user has to declare the ChipSelect pin being used when the constructor is declared - for example
SPIFlash flash(33);
Flash memory compatibility
Completely supported (Actually tested with)
  • Winbond
    • W25Q16BV
    • W25Q64FV
    • W25Q80BV
    • W25Q256FV
  • Microchip
    • SST25VF064C
    • SST26VF064B
  • Cypress/Spansion
    • S25FL116K
Should work with (Similar enough to the ones actually tested with)
  • Winbond (All SPI Flash chips)
  • Microchip (SST25 & SST26 series)
  • Cypress/Spansion (S25FL series)

Installation

Option 1
  • Open the Arduino IDE.
  • Go to Sketch > Include Library > Manage libraries.
  • Search for SPIFlash.
  • Install the latest version.
Option 2
  • Click on the 'Clone or download' button above the list of files on this page .
  • Select Download ZIP. A .zip file will download to your computer.
  • Unzip the archive and rename resulting folder to 'SPIFlash'
  • Move the folder to your libraries folder (~/sketches/libraries)

Change log

v3.0.0

Bugs Squashed:
  • The writeByteArray() & writeCharArray() bug that occurred when writing arrays that spanned page boundaries (squashed in v2.5.0), stayed around to haunt the other functions. Writing any data larger than a single byte that spanned page boundaries would cause the data to wrap around to the beginning of the page. The likelihood of this occurring was slim - no one has reported it to date. However, just in case, this has now been squashed in this release.
Deprecations:
  • Going forward the ATTiny85 is no longer officially supported.
  • The library no longer supports using the page number + offset combination instead of addresses. If your code requires you to use a page number + offset combination, use the following code to help
address = (pagenumber << 8) + offset.
  • The constructor no longer takes the pageOverflow variable as an argument. Page overflow is globally enabled by default and can be disabled by including a "#define DISABLEOVERFLOW" at the beginning of SPIFlash.h.
New Boards supported
  • Nucleo-F091RC
  • Adafruit Feather M0
New Flash manufacturers supported:
  • Microchip (SST25 & SST26 series)
  • Cypress
  • Spansion
Enhancements & Optimizations:
  • Confirmed to work with SPANSION/CYPRESS & MICROCHIP (Both SST25 & SST26 series).
  • If not using an officially supported chip, use the following variation of flash.begin() (where flashChipSize is indicated in Bytes, Kilobytes or Megabytes. (Refer to the next two items in this change log):
flash.begin(flashChipSize);
  • Including 'flashChipSize' in flash.begin() compiles more efficiently than in previous versions.
  • The way memory size is indicated by the users in flash.begin(flashChipSize) has changed - please refer to defines.h or the wiki for further information. The new method enables users to define any custom size unlike the previous version where only a limited number of predetermined sizes were available to use.
  • Library faster than before:

Improvements in speed in v3.0.0 when compared to v2.7.0 (values in percentage of time v3.0.0 is faster than v2.7.0)

Function Change in speed
writeByte +3%
writeChar +6%
writeWord +3%
writeShort +5%
writeULong +7%
writeLong +7%
readLong +7%
writeFloat +7%
writeStr +57%
readStr +61%
writeAnything +25%
readAnything (struct) +20%
writeByteArray +18%
readByteArray (256 bytes) +45%
eraseSector +99%
eraseBlock32K +99.4%
eraseBlock64K +99.5%
eraseChip +12%
  • Constructor changed to enable user to choose one of multiple SPI ports - if available. Look at wiki for further info
  • When RUNDIAGNOSTIC is uncommented in SPIFlash.h, users now have access to a new function called flash.functionRunTime() which can be called after any library I/O function is run. flash.functionRunTime() returns the time taken by the previous function to run, in microseconds (as a float). An example use case can be found when the FlashDiagnostics sketch is run with RUNDIAGNOSTIC uncommented.
  • _notBusy() is faster
  • Completely re-written FlashDiagnostics - uses fewer resources, compatible with more chips and boards
  • All functions except the Byte/Char Array Read/Write functions now call an internal _write/_read function for increased ease of compilation, execution and troubleshooting
  • Restructured the internal _troubleshoot() function to be better human readable and faster to compile.
  • Added a function getUniqueID() which returns the unique ID of the flash memory chip as a 64-bit integer.
  • Added an internal _readStat3() function to enable 4-byte addressing when using flash memory larger than 128 MB
  • 4-byte addressing enabled in flash memory larger than 128 MB. This is currently only supported on the W25Q256 and W25Q512. More chips will be supported on a case-by-case basis
  • getAddress() function now works anytime it is called - even if there is preexisting data on the chip