SPIMemory

2025-12-11 0 732

SPIMemory

Arduino library for Flash & FRAM Memory Chips (SPI based only)

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.


IDE Compatibility (actually tested with)

  • Arduino IDE v1.5.x
  • Arduino IDE v1.6.x
  • Arduino IDE v1.8.x

Platform compatibility

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


Flash memory compatibility – Actually tested with

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)
Should work with any flash memory that is compatible with the SFDP standard as defined in JESD216B

FRAM memory compatibility – Actually tested with

Manufacturer Flash IC Notes
Cypress/Spansion FM25W256 Should work with the FM25W family

Installation

Option 1

  • Open the Arduino IDE.
  • Go to Sketch > Include Library > Manage libraries.
  • Search for SPIMemory.
  • 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 \’SPIMemory\’
  • Move the folder to your libraries folder (~/sketches/libraries)

Usage

SPIFlash

  • The library is called by declaring theSPIFlash flash(csPin*) constructor where \’flash\’ can be replaced by a user constructor of choice and \’csPin\’ is the Chip Select pin for the flash module.

    * Optional. Do not include csPin if using the default slave select pin for your board.

  • Every version of the library >= v3.0.0 supports the ability to use any of multiple SPI interfaces (if your micro-controller supports them). Switching to use another SPI interface is done by calling SPIFlash flash(csPin, &SPI1); (or &SPI2 and so on), instead of SPIFlash flash(csPin).

    * NOTE: This is currently only supported on the SAMD and STM32 architectures.

  • An alternate version SPIFlash flash (SPIPinsArray) of the constructor can be used (only with ESP32 board 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.

  • Also make sure to include flash.begin(CHIPSIZE*) in void setup(). This enables the library to detect the type of flash chip installed and load the right parameters.

    * Optional

Note on SFDP discovery

As of v3.2.1, SFDP parameter discovery is an user controlled option. To get the library to work with SFDP compatible flash memory chips that are not officially supported by the library, the user must uncomment \’//#define USES_SFDP\’ in \’SPIMemory.h\’.

Notes on Address overflow and Error checking
  • The library has Address overflow enabled by default – i.e. if the last address read/written from/to, in any function, is 0xFFFFF then, the next address read/written from/to is 0x00000. This can be disabled by uncommenting #define DISABLEOVERFLOW in SPIMemory.h. (Address overflow only works for Read / Write functions. Erase functions erase only a set number of blocks/sectors irrespective of overflow.)

  • All write functions have Error checking turned on by default – i.e. every byte written to the flash memory will be checked against the data stored on the Arduino. Users who require greater write speeds can disable this function by setting an optional last \’errorCheck\’ argument in any write function to NOERRCHK – For eg. call the function writeByte(address, *data_buffer, NOERRCHK) instead of writeByte(address, *data_buffer).

SPIFram ^

  • The library is called by declaring theSPIFram fram(csPin*) constructor where \’fram\’ can be replaced by a user constructor of choice and \’csPin\’ is the Chip Select pin for the fram module.

    * Optional. Do not include csPin if using the default slave select pin for your board.

  • Every version of the library >= v3.0.0 supports the ability to use any of multiple SPI interfaces (if your micro-controller supports them). Switching to use another SPI interface is done by calling SPIFram fram(csPin, &SPI1); (or &SPI2 and so on), instead of SPIFram fram(csPin).

    * NOTE: This is currently only officially supported on the SAMD and STM32 architectures.

  • Also make sure to include fram.begin(CHIPSIZE*) in void setup(). This enables the library to detect the type of fram chip installed and load the right parameters.

^ Currently in BETA. The methods in SPIFram are not final and subject to change over the next few revisions.

The library enables the following functions:


Non-Read/Write functions


begin(_chipsize)
setClock(clockSpeed)
error(_verbosity)
getManID()
getJEDECID()
getUniqueID()
getAddress(sizeOfData)
sizeofStr()
getCapacity()
getMaxPage()
functionRunTime()

Read commands


All read commands take a last boolean argument \’fastRead\’. This argument defaults to FALSE, but when set to TRUE carries out the Fast Read instruction so data can be read at up to the memory\’s maximum frequency.


All read commands only take a 32-bit address variable instead of the optional 16-bit page number & 8-bit offset variables in previous versions of the library (< v3.0.0)

readAnything(address, value)
readByte(address)
readChar(address)
readWord(address)
readShort(address)
readULong(address)
readLong(address)
readFloat(address)
readStr(address, outputStr)
readAnything(address, value)

Write commands


All write commands take a boolean last argument \’errorCheck\’. This argument defaults to TRUE, but when set to FALSE will more than double the writing speed. This however comes at the cost of checking for writing errors. Use with care.

All write commands only take a 32-bit address variable instead of the optional 16-bit page number & 8-bit offset variables in previous versions of the library (< v3.0.0)

writeByte(address, data)
writeChar(address, data)
writeWord(address, data)
writeShort(address, data)
writeULong(address, data)
writeLong(address, data)
writeFloat(address, data)
writeStr(address, data)
writeAnything(address, value)

Continuous read/write commands


All write commands take a boolean last argument \’errorCheck\’. This argument defaults to TRUE, but when set to FALSE will more than double the writing speed. This however comes at the cost of checking for writing errors. Use with care.


readByteArray(address, *data_buffer, bufferSize)
writeByteArray(address, *data_buffer, bufferSize)
readCharArray(address, *data_buffer, bufferSize)
writeCharArray(address, *data_buffer, bufferSize)

Erase commands


All erase commands only take a 32-bit address variable instead of the optional 16-bit page number & 8-bit offset variables in previous versions of the library (< v3.0.0)


eraseSector(address)
eraseBlock32K(address)
eraseBlock64K(address)
eraseChip()
eraseSection(address, sizeOfData)

Suspend/Resume commands

suspendProg()
resumeProg()

Power operation commands

powerDown()
powerUp()

Error codes explained

Note: If you are unable to fix the error/s, please raise an issue here with the details of your flash chip and what you were doing when this error occurred. Please follow the issue template that show up at the link

Error code Explanation
0x00 Function executed successfully
0x01 *constructor_of_choice*.begin() was not called in void setup()
0x02 Unable to identify chip.
Is this chip officially supported?
0x03 Unable to identify capacity.
Is this chip officially supported?
If not, please define a CAPACITY constant and include it in flash.begin(CAPACITY).
0x04 Chip is busy. Make sure all pins have been connected properly.
0x05 Page overflow has been disabled and the address called exceeds the memory
0x06 Unable to Enable Writing to chip.
Please make sure the HOLD & WRITEPROTECT pins are pulled up to VCC.
0x07 This sector already contains data.
Please make sure the sectors being written to are erased.
0x08 You are running low on RAM.
Please optimise your code for better RAM usage
0x09 Unable to suspend/resume operation.
Please raise an issue.
0x0A Write Function has failed errorcheck.
Please raise an issue.
0x0B Check your wiring. Flash chip is non-responsive.
0x0C This function is not supported by the memory hardware.
0x0D Unable to enable 4-byte addressing.
Please raise an issue.
0x0E Unable to disable 4-byte addressing.
Please raise an issue.
0x0F The chip is currently powered down.
0x10 The Flash chip does not support SFDP.
0x11 Unable to read Erase Parameters from chip.
Reverting to library defaults.
0x12 Unable to read erase times from flash memory.
Reverting to library defaults.
0x13 Unable to read program times from flash memory.
Reverting to library defaults.
0x14 No Chip Select pin defined in the custom SPI Array.
Refer to section about Constructor for information on how to use custom SPI pins.
0xFE Unknown error.
Please raise an issue.

下载源码

通过命令行克隆项目:

git clone https://github.com/Marzogh/SPIMemory.git

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

申明:本文由第三方发布,内容仅代表作者观点,与本网站无关。对本文以及其中全部或者部分内容的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。本网发布或转载文章出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,也不代表本网对其真实性负责。

左子网 建站资源 SPIMemory https://www.zuozi.net/34855.html

icons
上一篇: icons
freshplayerplugin
下一篇: freshplayerplugin
常见问题
  • 1、自动:拍下后,点击(下载)链接即可下载;2、手动:拍下后,联系卖家发放即可或者联系官方找开发者发货。
查看详情
  • 1、源码默认交易周期:手动发货商品为1-3天,并且用户付款金额将会进入平台担保直到交易完成或者3-7天即可发放,如遇纠纷无限期延长收款金额直至纠纷解决或者退款!;
查看详情
  • 1、描述:源码描述(含标题)与实际源码不一致的(例:货不对板); 2、演示:有演示站时,与实际源码小于95%一致的(但描述中有”不保证完全一样、有变化的可能性”类似显著声明的除外); 3、发货:不发货可无理由退款; 4、安装:免费提供安装服务的源码但卖家不履行的; 5、收费:价格虚标,额外收取其他费用的(但描述中有显著声明或双方交易前有商定的除外); 6、其他:如质量方面的硬性常规问题BUG等。 注:经核实符合上述任一,均支持退款,但卖家予以积极解决问题则除外。
查看详情
  • 1、左子会对双方交易的过程及交易商品的快照进行永久存档,以确保交易的真实、有效、安全! 2、左子无法对如“永久包更新”、“永久技术支持”等类似交易之后的商家承诺做担保,请买家自行鉴别; 3、在源码同时有网站演示与图片演示,且站演与图演不一致时,默认按图演作为纠纷评判依据(特别声明或有商定除外); 4、在没有”无任何正当退款依据”的前提下,商品写有”一旦售出,概不支持退款”等类似的声明,视为无效声明; 5、在未拍下前,双方在QQ上所商定的交易内容,亦可成为纠纷评判依据(商定与描述冲突时,商定为准); 6、因聊天记录可作为纠纷评判依据,故双方联系时,只与对方在左子上所留的QQ、手机号沟通,以防对方不承认自我承诺。 7、虽然交易产生纠纷的几率很小,但一定要保留如聊天记录、手机短信等这样的重要信息,以防产生纠纷时便于左子介入快速处理。
查看详情

相关文章

猜你喜欢
发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务