Arduino library for Flash Memory Chips (SPI based only). Formerly SPIFlash
Formerly known as SPIFlash.
Please report any bugs in issues
Download the latest stable release from here. Please report any bugs in issues.
This Arduino library is for use with flash and FRAM memory chips that communicate using the SPI protocol. In its current form it supports identifying the flash/FRAM 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.
Micro controllers | Dev boards tested with | Notes |
---|---|---|
ATmega328P | Arduino Uno, Arduino Micro, Arduino Fio, Arduino Nano |
- |
ATmega32u4 | Arduino Leonardo, Arduino Fio v3 | - |
ATmega2560 | Arduino Mega | - |
ATSAMD21G18 (ARM Cortex M0+) | Adafruit Feather M0, Adafruit Feather M0 Express, Adafruit ItsyBitsy M0 Express |
- |
AT91SAM3X8E (ARM Cortex M3) | Arduino Due | - |
nRF52832 (ARM Cortex M4F) | Adafruit nRF52 Feather | - |
ATSAMD51J19 (ARM Cortex M4) | Adafruit Metro M4 | - |
STM32F091RCT6 | Nucleo-F091RC | |
STM32L0 | Nucleo-L031K6 | |
ESP8266 | Adafruit ESP8266 Feather, Sparkfun ESP8266 Thing |
- |
ESP32 | Adafruit ESP32 Feather, Sparkfun ESP32 Thing |
Onboard flash memory. Refer to footnote£ below. |
Simblee | Sparkfun Simblee | - |
£ ESP32 boards usually have an SPI Flash already attached to their default SS pin, so the user has to explicitly declare the ChipSelect
pin being used with the constructor
Manufacturer | Flash IC | Notes |
---|---|---|
Winbond | W25Q16BV W25Q64FV W25Q64JV W25Q80BV W25Q256FV |
Should work with the W25QXXXBV, W25QXXXFV & W25QXXXJV families |
Microchip | SST25VF064C SST26VF016B SST26VF032B SST26VF064B |
Should work with the SST25 & SST26 families |
Cypress/Spansion | S25FL032P S25FL116K S25FL127S |
Should work with the S25FL family |
ON Semiconductor | LE25U40CMC | |
AMIC | A25L512A0 | |
Micron | M25P40 | |
Adesto | AT25SF041 | |
Macronix | MX25L4005 MX25L4005 |
|
Giga devices | GD25Q16C | (Used on the Adafruit ItsyBitsy M0 Express) |
Manufacturer | Flash IC | Notes |
---|---|---|
Cypress/Spansion | FM25W256 | Should work with the FM25W family |
SPIFlash flash(int8_t *SPIPinsArray);
can be used (only with ESP32 boards as of now) to enable the use of custom SPI pins. SPIPinsArray
has to be a 4 element array containing the custom SPI pin numbers (as signed integers - int8_t) in the following order - sck, miso, mosi, ss. Refer to the wiki for more information. Resolves #113
NOCHIPSELECTDECLARED
for errors with declaring custom SPI pins.setClock()
works and allows for the definition of clock speed before the SPI Bus is instantiated. Refer to wiki for further details. Thanks @rambo.Formerly known as SPIFlash.
Please report any bugs in issues
Download the latest stable release from here. Please report any bugs in issues.
This Arduino library is for use with flash and FRAM memory chips that communicate using the SPI protocol. In its current form it supports identifying the flash/FRAM 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.
Micro controllers | Dev boards tested with | Notes |
---|---|---|
ATmega328P | Arduino Uno, Arduino Micro, Arduino Fio, Arduino Nano |
- |
ATmega32u4 | Arduino Leonardo, Arduino Fio v3 | - |
ATmega2560 | Arduino Mega | - |
ATSAMD21G18 (ARM Cortex M0+) | Adafruit Feather M0, Adafruit Feather M0 Express, Adafruit ItsyBitsy M0 Express |
- |
AT91SAM3X8E (ARM Cortex M3) | Arduino Due | - |
ATSAMD51J19 (ARM Cortex M4) | Adafruit Metro M4 | - |
STM32F091RCT6 | Nucleo-F091RC | |
ESP8266 | Adafruit ESP8266 Feather, Sparkfun ESP8266 Thing |
- |
ESP32 | Adafruit ESP32 Feather, Sparkfun ESP32 Thing |
Onboard flash memory. Refer to footnote£ below. |
Simblee | Sparkfun Simblee | - |
£ ESP32 boards usually have an SPI Flash already attached to their default SS pin, so the user has to explicitly declare the ChipSelect
pin being used with the constructor
Manufacturer | Flash IC | Notes |
---|---|---|
Winbond | W25Q16BV W25Q64FV W25Q64JV W25Q80BV W25Q256FV |
Should work with the W25QXXXBV, W25QXXXFV & W25QXXXJV families |
Microchip | SST25VF064C SST26VF016B SST26VF032B SST26VF064B |
Should work with the SST25 & SST26 families |
Cypress/Spansion | S25FL032P S25FL116K S25FL127S |
Should work with the S25FL family |
ON Semiconductor | LE25U40CMC | |
AMIC | A25L512A0 | |
Micron | M25P40 | |
Adesto | AT25SF041 | |
Giga devices | GD25Q16C | (Used on the Adafruit ItsyBitsy M0 Express) |
Manufacturer | Flash IC | Notes |
---|---|---|
Cypress/Spansion | FM25W256 | Should work with the FM25W family |
SPIFram
constructor--> GD25Q16C from Giga devices (Used on the Adafruit ItsyBitsy M0 Express)
Formerly known as SPIFlash.
Please report any bugs in issues
Download the latest stable release (v3.2.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.
ESP32 support will remain in beta till the ESP32 core can be installed via the Arduino boards manager.
NOTE: ESP32 boards usually have an SPI Flash already attached to their SS pin, so the user has to declare the ChipSelect pin being used when the constructor is declared - for exampleSPIFlash flash(33);
Test sketch - FlashDiagnostics.ino from v3.2.0 with #RUNDIAGNOSTIC commented out
Test platform - Arduino Pro Mini 8MHz 3.3V
Library version | SFDP discovery | Compiled code size | % Difference from v3.1.0 |
---|---|---|---|
v3.1.0 | Not supported | 17652 bytes | 0% |
v3.2.0 | Supported & enabled by default | 20104 bytes | +13.9% |
v3.2.1 | Supported & enabled | 17854 bytes | +1.1% |
v3.2.1 | Supported & disabled | 15316 bytes | -13.75% |
Fixes issue #135 : The addition of the SFDP checking to _chipID resulted in a sudden (very large) increase in compiled code size. As of the current version (v3.2.1), SFDP checking is an user controlled option. To get the library to work with SFDP compatible flash memory that is not officially supported, the user must uncomment '//#define USES_SFDP' in 'SPIMemory.h'.
Moved bool _loopedOver
from being a local variable in getAddress()
to a global one. Now it actually does what it was meant to do - i.e. prevent looping over data a second time.
Formerly known as SPIFlash.
Please report any bugs in issues
Download the latest stable release (v3.2.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.
ESP32 support will remain in beta till the ESP32 core can be installed via the Arduino boards manager.
NOTE: ESP32 boards usually have an SPI Flash already attached to their SS pin, so the user has to declare the ChipSelect pin being used when the constructor is declared - for exampleSPIFlash flash(33);
Library name changed to SPIMemory
The library now gathers sfdp information through _chipID(). SFDP information is collected when available, otherwise the library defaults to using code from v3.1.0 to ID the chip.
All flash memories compatible with the SFDP standard (as at JESD216B) should be compatible with the library
LE25U40CMC from ON Semiconductor
A25L512A0 from AMIC
M25P40 from Micron
AT25SF041 from Adesto
S25FL032P from Cypress/Spansion
Please report any bugs in issues
Important note from developer
The term 'SPI Flash' is a fairly common way to refer to Flash memory chips that communicate over the SPI protocol and there are a number of libraries that are named SPIFlash. When I first started work on this library in 2014, it was mostly as an exercise to improve my embedded systems programming skills. When I asked for it to be included in the list of Arduino libraries, I did not really expect it to go very far or get very popular. But, before I knew it, I was releasing new versions every other month and I found the number of users got way bigger than I imagined it would. The amount of traffic the GitHub repository gets still surprises me.
A few months ago, @LowPowerLab raised an issue (#83) about the problems the name of this library was causing the users of his library - also called SPIFlash. The fact that this library is in the Arduino Library manager meant that his users were being asked to upgrade their version of SPIFlash when the libraries were actually different. I can understand how much of an annoyance this can be for a user.
@LowPowerLab's version of SPIFlash has been around for longer than this one and his library is a major part of his commercial line of development boards. Since I am a hobbyist developer (I'm a full-time geneticist & a part-time dabbler in ecology - if you're curious) and this library is not a commercial product with branding and trademarks to worry about, the least I can do is change the name of this library so it stops being an annoyance to @LowPowerLab's customers.
On a side note, if you did not know already, @LowPowerLab makes and sells a fantastic line of Arduino compatible boards - the Moteino series - and has developed a fantastic IoT protocol to use with them to add smarts to your home. In January this year, I finally got around to getting my hands on some of his boards and have been playing around with them. They are fantastic! I'd strongly recommend you check them out - if you haven't already done so.
I asked the Arduino developers if there was a way to migrate this library to a new name without breaking the upgrade path (Issue #6904) and was told that it was not possible. The only way is to pull my version of SPIFlash from the library manager and ask for a renamed version to be included in the library manager after.
So, this is what I have decided to do.:
- This version - v3.1.0 - will be the last version to be released under the SPIFlash name.
- Anyone downloading this version of the library will be able to read this notice in the ReadMe file.
- Anyone using this version of the library will see a notice in their Serial output directing them to this notice in the ReadMe file. (this can be removed by commenting out the
#define PRINTNAMECHANGEALERT
inSPIFlash.h
)- Version 3.2.0 will be released in a couple of months (in May most likely) under a new name - SPIMemory.
- This version of SPIFlash will be removed from the library manager then and replaced with the new one.
The only change will have to be made in end-user code will be to change the
#include SPIFlash.h
to#include SPIMemory.h
. After the name change, rest assured that older versions will remain accessible and the development history of the library will be preserved.I apologise for any trouble this might cause you as the end user, but, given the facts, it is the only thing I can do to be fair to @LowPowerLab
Thanks again for using
SPIFlash
and I hope you will continue to find it useful in whatever new name it will take on.
Download the latest stable release (v3.1.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.
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 exampleSPIFlash flash(33);
#define PRINTNAMECHANGEALERT
in SPIFlash.h. Please refer to the Readme file for further details.An error with how _addressCheck() works with data that spans the memory boundary - when rolling over from address '_chip.capacity' to address '0x00' - has been fixed. In previous versions this caused issues with writing complex data structures across the memory boundary and led to many _writeErrorCheck() failures. Fixes issue #112
An error with how _writeErrorCheck() worked has been resolved. Writing structs is now as stable as other functions are. Fixes #106
A new function - 'flash.eraseSection(address, size)' - has been introduced in this version. When a user requires a large and variable (between writes) amount of data to be written to the flash memory on the fly and to have the correct amount of space erased to fit the data, this function will automatically calculate and erase the right amount of space to fit the data. Please note that if the the amount of data being written is consistently the same size, the pre-existing 'flash.eraseSector()', 'flash.eraseBlock32K()' and 'flash.eraseBlock64K()' functions will operate a lot faster.
Updated Diagnostics.ino to include eraseSection().
All I/O functions now check to see if the flash chip is powered down. If it is, they prevent the function from running and returns an error. A new error code 'CHIPISPOWEREDDOWN' will be returned upon calling flash.error().
Please report any bugs in issues
Download the latest stable release (v3.0.1) 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.
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 exampleSPIFlash flash(33);
Thanks for catching and fixing the following @hanyazou (PR #101)
--> S25FL127S
Please report any bugs in issues
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.
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 exampleSPIFlash flash(33);
address = (pagenumber << 8) + offset.
flash.begin(flashChipSize);
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% |
getUniqueID()
which returns the unique ID of the flash memory chip as a 64-bit integer.Please report any bugs in issues.
This Arduino library is for use with Winbond serial flash memory chips. In its current form it supports identifying the flash chip and its various features; automatic address allocation and management; reading and writing bytes/chars/ints/longs/floats/Strings from and to various locations; reading and writing pages of bytes; continous reading/writing of data from/to arrays of bytes/chars; sector, block and chip erase; and powering down for low power operation.
SPIFlash flash(33);
ESP32 support will remain in beta till the ESP32 core can be installed via the Arduino boards manager.
SPIFlash flash(33);
Please report any bugs in issues.
This Arduino library is for use with Winbond serial flash memory chips. In its current form it supports identifying the flash chip and its various features; automatic address allocation and management; reading and writing bytes/chars/ints/longs/floats/Strings from and to various locations; reading and writing pages of bytes; continous reading/writing of data from/to arrays of bytes/chars; sector, block and chip erase; and powering down for low power operation.
ESP32 support will remain in beta till the ESP32 core can be installed via the Arduino boards manager.
randomSeed(AnalogRead(A0));
cannot be used. Also, for some unknown reason, SPI clock speeds higher than board speed/4 are not stable and so, the clock speed for ESP32 dev boards has currently been throttled to 20MHz.flash.error()
now takes an optional argument VERBOSE
. By default the verbosity argument is set to false
and calling flash.error()
still returns the latest error code as an unsigned byte. However, running flash.error(VERBOSE)
will not only return the latest error code, but will also print it to serial. This - especially in boards with resources to spare - will result in a detailed error report printed to serial.flash.begin()
now returns a boolean value to indicate establishment of successful comms with the flash chip. Usercode can be made more efficient now by callingif (!flash.begin()) {
Serial.println(flash.error(VERBOSE));
}
to identify a problem as soon as the library code is run.
_addressCheck()
function now locks up usercode with appropriate error codes if
flash.begin()
has not been called (or)flash.begin()
.powerDown()
to be more efficient. The chip now powers down much faster than before.#define RUNDIAGNOSTIC
& #define HIGHSPEED
to SPIFlash.h from SPIFlash.cpp.flash.begin(_chipSize);
_troubleshoot()
function to use fewer resources.Please report any bugs in issues.
This Arduino library is for use with Winbond serial flash memory chips. In its current form it supports identifying the flash chip and its various features; automatic address allocation and management; reading and writing bytes/chars/ints/longs/floats/Strings from and to various locations; reading and writing pages of bytes; continous reading/writing of data from/to arrays of bytes/chars; sector, block and chip erase; and powering down for low power operation.
flash.setClock(uint32_t clockSpeed);
straight after begin();
.#include <SPI.h>
in user code anymore. Just #include<SPIFlash.h>
will do. Examples are now updated.