Giter VIP home page Giter VIP logo

spimemory's Introduction

SPIMemory Build Status DOI

GitHub release GitHub commits GitHub issues GitHub pull requests license Join the chat at https://gitter.im/SPIMemory/community

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.

spimemory's People

Contributors

boseji avatar c0zm0z avatar constiko avatar gitter-badger avatar hanyazou avatar jacky4566 avatar marzogh avatar miduchp avatar mix86 avatar per1234 avatar rambo avatar rnestler avatar stanislav-povolotsky avatar vitorboss avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

spimemory's Issues

Problem with powerDown

Systematically powerDown() is not working for me (more precisely it returns a false)
powerUp() and other functions are working properly. The chip is a Winbond W25Q32BV

Add a 'clone' function

GitHub issue state GitHub issue title GitHub issue author GitHub issue label GitHub issue comments GitHub issue age GitHub issue last update

---------------------------- DO NOT DELETE OR EDIT anything above this line ----------------------------

Add the ability for the library to clone from one chip to another - i.e. add the ability to use two chips at once.

Doesn't work with Arduino 1.0.x

Examples don't compile with IDE 1.0.5 and even using a Makefile and calling avr-g++ directly (and enabling gnu++11 and so on) it won't build.

If I add the #define ARDUINO_ARCH_AVR 1 to readWriteString.ino (should really be __AVR__ to do it automatically) I get a bit further but also need to change:

(void)xfer(PAGEPROG); at line 290 etc. to void xfer(PAGEPROG);

But then I get the error:

error: expected initializer before ‘.’ token
     #define xfer(n)   SPI.transfer(n)

Which I assume is because SPI.transfer() expects two arguments - a pointer and a value, or lack of trailing semi-colons in various places?

How to perform error checking?

I was wondering if it were possible to detect the following:

  1. If the SPI chip is wired and initialized correctly.
  2. If SPIFlash::begin() was called and completed successfully.

I'm modifying a FAT library that uses this library as a backend and it would be useful to know whether the chip and class have been initialized appropriately before calling read/write operations.

Compiling getAddressEx.ino example failes when using make

When using the Arduino-Makefile to build the example I get the following errors:

libs/SPIFlash/examples/getAddressEx/getAddressEx.ino: In function 'void setup()':
libs/SPIFlash/examples/getAddressEx/getAddressEx.ino:49:16: error: 'getAddresses' was not declared in this scope
   getAddresses();
                ^
libs/SPIFlash/examples/getAddressEx/getAddressEx.ino:50:13: error: 'writeData' was not declared in this scope
   writeData();
             ^
make: *** [build-micro/libs/SPIFlash/examples/getAddressEx/getAddressEx.ino.o] Error 1

This is due to missing function prototypes for getAddresses() and writeData()

Faster memory access

That is a idea for enhancement, eliminate all shifts from code, that will increase average speed, just use those macros:

#define Lo(param) ((char *)&param)[0] //0x000y
#define Hi(param) ((char *)&param)[1] //0x00y0
#define Higher(param) ((char *)&param)[2] //0x0y00
#define Highest(param) ((char *)&param)[3] //0xy000
#define Low(param) ((int *)&param)[0] //0x00yy
#define Top(param) ((int *)&param)[1] //0xyy00

In my tests those macros reduce memory access in a 2000 loop from 200+mS to 2mS.

SPIFlash::writeByteArray fails it's error check on SAMD

SPIFlash::writeByteArray modify data buffer (storing data from SPI MISO into the buffer) and fails it's read after write verification. Write with error check always fails because of this.

void SPIFlash::_nextBuf(uint8_t opcode, uint8_t *data_buffer, uint32_t size) {
// snipped
#elif defined (ARDUINO_ARCH_SAMD)
#ifdef ENABLEZERODMA
spi_write(&(*data_buffer), size);
#else
_spi->transfer(&(*data_buffer), size); // this call destroy the contents of the buffer
#endif
#elif defined (ARDUINO_ARCH_AVR)
SPI.transfer(&(*data_buffer), size);

0x02 error

Hi can you confirm this is how i would set this up.

#include<SPIFlash.h>

int ss = 10;
SPIFlash flash;

void setup() {
 Serial.begin(115200);
flash.begin(MB32); // is this correct
Serial.println("erasing chip");
flash.eraseChip();
delay(0);
flash.begin();
Serial.println(flash.readChar(22,44,false));// is this correct
}

void loop() {
 
}

readByte does not work

The very first line of the readByte function should not have the braces and should return false.

The first line is the check for busy, out of range page/offset and should return false right after it.

If you compare the first two lines of the readByte and readBytes you will see the bug.

As it is today, the readByte functon only runs if the chip is busy or if you pass in an out of range page/offset.

I am using NodeMCU esp8266 module, In my case it gives 0 for all function call . Please give any solution of it. I want to read file which wash flashed is it possible.?

#include<SPIFlash.h>
#include<SPI.h>
#define arrayLen(x) sizeof(x)/sizeof(x[0])
uint32_t strAddr[3], floatAddr[2], byteAddr[4];
String testStr[] = {
  "Test String 0",
  "Test String 1",
  "Test String 2"
};
float testFloat[] = {
  3.1415, 6.283
};
byte testByte[] = {
  3, 245, 84, 100
};

SPIFlash flash;

void getAddresses();
void writeData();

void setup() {
  Serial.begin(9600);
  Serial.print(F("Initialising Flash memory"));
  for (int i = 0; i < 10; ++i)
  {
    Serial.print(F("."));
  }
  Serial.println();
  flash.begin();
  
  Serial.println();
  Serial.println();

  getAddresses();
 
  writeData();
     Serial.printf("\n getMaxPage  = %d\n", flash.getMaxPage());
     
     Serial.printf("\n getCapacity= %d\n", flash.getCapacity());
      
      Serial.printf("\n getManID = %d\n", flash.getManID());
      
 
  //flash.eraseChip();
}

void loop() {

}
// Function to get adresses for various variables
void getAddresses() {
  for (uint8_t i = 0; i < arrayLen(byteAddr); i++) {
    byteAddr[i] = flash.getAddress(sizeof(byte));
    Serial.printf("error= %d\n", flash.error());
    Serial.print("Byte Address ");
    Serial.print(i);
    Serial.print(" : ");
    Serial.println(byteAddr[i]);
  }

  for (uint8_t i = 0; i < arrayLen(floatAddr); i++) {
    floatAddr[i] = flash.getAddress(sizeof(float));
     Serial.printf("error= %d\n", flash.error());
    Serial.print("Float Address ");
    Serial.print(i);
    Serial.print(" : ");
    Serial.println(floatAddr[i]);
  }

  for (uint8_t i = 0; i < arrayLen(strAddr); i++) {
    strAddr[i] = flash.getAddress(flash.sizeofStr(testStr[i]));
  Serial.printf("error= %d\n", flash.error());
    Serial.print("String Address ");
    Serial.print(i);
    Serial.print(" : ");
    Serial.println(strAddr[i]);
  }
}

// Function to write data
void writeData() {
  for (uint8_t i = 0; i < arrayLen(byteAddr); i++) {
    if (flash.writeByte(byteAddr[i], testByte[i])) {
      Serial.printf("error= %d\n", flash.error());
      Serial.print(testByte[i]);
      Serial.print(" written to ");
      Serial.println(byteAddr[i]);
    }
  }

  for (uint8_t i = 0; i < arrayLen(floatAddr); i++) {
    if (flash.writeFloat(floatAddr[i], testFloat[i])) {
     Serial.printf("error= %d\n", flash.error());
      Serial.print(testFloat[i]);
      Serial.print(" written to ");
      Serial.println(floatAddr[i]);
    }
  }

  for (uint8_t i = 0; i < arrayLen(strAddr); i++) {
    if (flash.writeStr(strAddr[i], testStr[i])) {
     Serial.printf("error= %d\n", flash.error());
      Serial.print(testStr[i]);
      Serial.print(" written to ");
      Serial.println(strAddr[i]);
    }
  }
}

========================================
out put

�cüÿInitialising Flash memory..........
error= 5
Byte Address 0 : 0
error= 5
Byte Address 1 : 0
error= 5
Byte Address 2 : 0
error= 5
Byte Address 3 : 0
error= 5
Float Address 0 : 0
error= 5
Float Address 1 : 0
error= 5
String Address 0 : 0
error= 5
String Address 1 : 0
error= 5
String Address 2 : 0

getMaxPage = 0

getCapacity= 0

getManID = 0

error: 'flashCode' was not declared in this scope

in the file SPIFlash/examples/TestFlash/TestFlash.ino
after doing the following...
//Uncomment this code block if your code doesn't run to check for Flash error code
i get the error below

command_list.ino: In function 'void setup()':

command_list:96: error: 'flashCode' was not declared in this scope

exit status 1
'flashCode' was not declared in this scope

for both uno & esp8266

Random Error Code

Hi,

I'm using an Arduino Uno with a Winbond 32mB chip, W25Q256FV. I've been trying to get it to run with no success. I have already swapped the chip out and that changed nothing. I've been running the Flash Diagnostics page and it only works on special cases. I have to comment out the GetID and diagnose functions and upload. Then I can uncomment GetID and upload. Then finally I can uncomment diagnose and upload, but I have to have the powerFuncDiag commented out. If I don't do all those steps I get:

Error Code 0x04
Error Code 0x04
Error Code 0x04.

Which says could be a wiring problem, but I'm able to get it to work if I use all the steps above (besides PowerDown, that has never passed). When I do all of that stuff first I get the screenshot that I attached.
serial monitor output
I'm using the sparkfun logic level converter you recommended in the arduino forums and I've checked my wiring 50 times at least. Would appreciate any help/wondering if there is a bug in the library. Thank you very much!

How to handle multiple flash chips?

So the constructor is SPIFlash flash(csPin); but how to create two constructors for two flash chips with different csPins and start them with .begin() in setup?

Calculate and save a checksum for data files

GitHub issue state GitHub issue title GitHub issue author GitHub issue label GitHub issue comments GitHub issue age GitHub issue last update

---------------------------- DO NOT DELETE OR EDIT anything above this line ----------------------------

Once a file system is setup on the Flash chip, the end of every file could possibly have a 16/32bit checksum to test the integrity of the file - without having to re-read the whole thing?

Add SPI Transactions support

Add support for SPI.Transactions() so this library plays well with other libraries that use the SPI interface.

Missing CLK Pulses

Hello,

With a Salea Logic 4 analyzer I was able to determine that I was missing the clock pulses when trying to read\write to my Windbond SPI memory chip.

I have this connected to the SPI bus of my ATMEGA644A microcontroller.

Through further testing I figure out that if I swapped my crystal from 8MHz to 16MHz I can get the clock pulses to generate and I am able to work with the memory chip.

According to my chips datasheet it seems like 8MHZ would be just fine all the way up to 100MHz.

What could be reasons why an 8MHz crystal does not work with the demo program?

Thanks,

Stephen

ATMega2560 problems

Have ATmega2560 wired up to W25Q64FV winbond chip. Using Hardware SPI pins and SS pin (53) for chipselect
Running XP.

If I use the SPIflash library from RinkyDink website the above setup is reported as working fine.

If I erase the chip using RinkyDink and then switch to your library and run your testflash sketch the only menu item that works is number 1 and it reports the correct chip ID for W25Q64FV.
All other menu items fail or appear to do nothing. ie EraseSector

EraseChip returns very quickly, the RinkyDink erasechip function takes quite a while.
WriteByte reports data failed. ReadPage reports 256 X 0xFF as you would expect but none of the commands that perform writes to the flash chip are working.

This is most strange given the large amount of positive feedback you have received from users on the internet. Is it me ?? Appreciate if anything obvious springs to mind.
BTW. Have also tried 2.4.0,wip download but results are the same.
Best Regards

ATTiny85 compatibility

I'm trying to compile the library on an ATTiny85 (adafruit trinket), and I'm getting quite some errors.

for example:

SPIFlash/defines.h:81:12: error: 'SS' was not declared in this scope
#define CS SS

I can tell there are some checks for AVR_ATtiny85 in the library, but I can't make the standard examples work out of the box. Am I missing something? Or has ATTiny support not been tested in a while?

Is Cypress f.memory works?

Hi mate, I try using your library for my Cypress S25FL512S f.memory using Arduino MEGA and somehow it display error code 0x03. I edit some common instructions from defines.h code that match for my f.memory but still does not work. Can you give me some advice what to edit if wanna to use another f.memory (i.e Cypress f.memory for my case)? Really appreciate it if you can help me because I am still learning about this. Thank you.

Support for Microchip flash memories? (SST26VF064B)

Hello. I have an SST26VF064B flash chip from Microchip and am desperately trying to find a way to control it from an arduino UNO. No success so far, tried with multiple libraries including yours. Can you please add support for my chip in your library or perhaps point me to another library that supports it?

Can't write data into W25Q256FV

Hello!
I have plugged a Winbond W25Q256FV and run the diagnostic sketch (FlashDiagnostics.ino in the library example sketch folder).
The output says that reading chip is OK but all writings have failed...
The pins WP, HOLD and RESET are HIGH so the chip should be working.
I have uncommented the line 38 in SPIFlash.h :
#define RUNDIAGNOSTIC

Serial output :

Initialising Flash memory..........

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
                                                                    SPIFlash Library version: 2.7.0
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
                                                                                Get ID
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
			JEDEC ID: ef4019h
			Manufacturer ID: efh
			Memory Type: 40h
			Capacity: 33554432 bytes
			Maximum pages: 131072
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
                                                                               Data Check
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
	Data Written	||	Data Read	||	Result		||	Write Time	||	Read Time	||	Write Time	||	Fast Read Time
			||			||			||			||			||	(No Error Chk)	||
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
	35		||	4		||	Fail		||	144 us		||	96 us		||	104 us		||	104 us
	-110		||	0		||	Fail		||	112 us		||	96 us		||	112 us		||	104 us
	4520		||	3072		||	Fail		||	120 us		||	104 us		||	120 us		||	104 us
	-1250		||	0		||	Fail		||	120 us		||	104 us		||	120 us		||	112 us
	876532		||	0		||	Fail		||	128 us		||	120 us		||	128 us		||	120 us
	-10959		||	16711935		||	Fail		||	144 us		||	120 us		||	128 us		||	120 us
	3.14		||	0.00		||	Fail		||	2008.9382 s		||	120 us		||	2008.9382 s		||	128 us
	123 Test !@#	||		||	Fail		||	2890.3596 s		||	264 us		||	2890.3596 s		||	3416 us
	inputStruct	||	outputStruct	||	Fail		||	144 us		||	184 us		||	144 us		||	184 us

Not closing SPI Transactions

I'm having issues with this library while working with other SPI devices.
There are circumstances where it isn't closing the SPI transaction after completing a task, which causes havoc while talking to other devices on the SPI bus that use a different SPI_MODE.
I did some digging and notices several instances where _endSPI has been commented out within the library. Uncommenting the _endSPI() in the _readStat1() function fixed my issues, but I thought ya'll might want to check it out.
-thanks.

Error 0x04

Dear All,

I work with w25q64 module and ESP32-WROOM-32 via arduino IDE. From few days w25q64 can't start work. I deleted almost all code and I want only begin the module, but all time i recieve error code 0x04. I chech all connection and tried different combination of connection with different pins.
My connections:
CS -> IO5
CLK ->IO18
DI -> IO19
DO -> IO23

Please note that if I connect csPin to IO2 (as was said in extras in this repository) in ESP32 boatloader tell me

flash read err, 1000
Falling back to built-in command interpreter.
OK

And I should choose another pin, e.g. no 5. My code is below.

#include<SPIFlash.h>
#include<SPI.h>

#define csPin 5

SPIFlash flash(csPin); 

void setup() {
Serial.begin(115200);
while (!flash.begin()){
  if (flash.error()) {
          Serial.print(flash.error());
     }
}
}

void loop() {
}

If someone know what i do wrong please let me know.

How to get the uniqueid?

Hello, I'm looking to get the uniqueID out of the chip to use for ID purposes. The specific chip I'm using is the W25Q16JV which I can successfully read/write to.

The dataheet http://www.winbond.com/resource-files/w25q16jv%20spi%20revf%2005092017.pdf

page 46:

The Read Unique ID instruction is initiated by driving the /CS pin
low and shifting the instruction code “4Bh” followed by a four bytes of dummy clocks.

But I have no idea how to add this! Any suggestions?

thanks!

32-bit or 24-bit flash memory

Hi,
what I know from ur library support for 32-bit flash memory right?
Is there any possible u make library for 24-bit too?
Thanks mate.

getAddress() isn't considering addresses which have data already written

@Marzogh
The function getAddress() is expected to return the next available address for use.

Say I have addresses 0 to 40 written with data already. Then I expect getAddress() to return 41. But it is returning 0.

Output of getAddressEx.ino:
Please note that I have data written till address 63
Just added an else condition with a print statement if any write in writeData() doesn't return 1

The output is as follows:

Initialising Flash memory..........

Byte Address 0 : 0
Byte Address 1 : 1
Byte Address 2 : 2
Byte Address 3 : 3
Float Address 0 : 4
Float Address 1 : 8
String Address 0 : 12
String Address 1 : 30
String Address 2 : 48
Data write failed
Data write failed
Data write failed
Data write failed
Data write failed
Data write failed
Data write failed
Data write failed
Data write failed

The write wouldn't happen because the addresses returned already have data and this is expected.
I am using v2.7.0 of the library with a Winbond external flashchip.

MX25L12845E

GitHub issue state GitHub issue title GitHub issue author GitHub issue label GitHub issue comments GitHub issue age GitHub issue last update

---------------------------- DO NOT DELETE OR EDIT anything above this line ----------------------------

library works fine with 25Q64 Winbond chip but I'm unable make the necessary modification to read/write or even get chip id from MX25L12845E
Using standard SPI I'm able to read the chip id and random segment of memory address.

Name conflict with SPIFlash library

GitHub issue state GitHub issue title GitHub issue author GitHub issue label GitHub issue comments GitHub issue age GitHub issue last update

---------------------------- DO NOT DELETE OR EDIT anything above this line ----------------------------

Hi,
I have a library called SPIFlash which was created many years ago.
Since you created your own "SPIFlash" with the identical same name, Arduino is causing naming conflicts. I suspect your users have the same issue.
Could you possibly rename your library to something else?

Bug report : Struct writing not reliable

Hello!

I'm submitting a bug report, I tried to identify what's going wrong but I cannot fix it...

Bug report :

Library version : 3.0.0
Branch : master
Arduino IDE : 1.8.4
OS : Windows
Microcontroller : Arduino-nano (Atmega328P)
Flash memory module : W25Q64 freshly erased
Current behaviour :
Writing Struct type is not reliable (8% of errors) while writing ByteArray is reliable (0% of error)
Expected behaviour :
Writing Struct should be as reliable as writing ByteArray

Code snippet that reproduces the bug :
First sketch (not reliable) : part of the code that loops for writing Struct

    for (long k=1;k<10000;k++) {
      addr = flash.getAddress(sizeof(configuration));

      Serial.println();
      Serial.print ("addr = ");
      Serial.println(addr);
      
      if (flash.writeAnything(addr, configuration)){
      }
      else {
        Serial.println ("Struct write failed");
      }
    }

I observe a strange thing on the serial output : "Struct write failed" tends to occur each 12 Struct writings...

Second sketch (reliable) : part of the code that loops for writing ByteArray

for (long k=1;k<10000;k++) { 
      addr = flash.getAddress(sizeof(pageBuffer));

      Serial.println();
      Serial.print ("addr = ");
      Serial.println(addr);
      
      if (flash.writeByteArray(addr, &pageBuffer[0], SPI_PAGESIZE)) {
       }
      else {
        Serial.println("Page write failed");
      }
      
    }

Erase before write - check

Library needs ability to check that data is not being written without erasing previously written data

Ability to update data required - Due only (for now)

GitHub issue state GitHub issue title GitHub issue author GitHub issue label GitHub issue comments GitHub issue age GitHub issue last update

---------------------------- DO NOT DELETE OR EDIT anything above this line ----------------------------

Add the ability to update_dataType_(..., ..., data, ...) for the Arduino due.

Updating can be achieved by reading the sector/32kb block of data into a buffer in the Due's SRAM, modifying the required data bits in the SRAM and then writing it back to the flash chip.

This is not a true update, but a workaround the limit that the flash memory can only erase one 4k sector at the minimum.

Questions about the erasing system

Two quick questions about erasing sectors:

  1. If I call the eraseSector, pass a page to erase, and the offset different than zero, what will happen?
  • Ex: eraseSector(page 0, offset 128) will erase the page 0, starting from byte 128 (maintaining the info in the 0-127 bytes) until the page 15;offset 128, (maintaining the info in the 128-255 bytes)? - Or it will just erase all data in the pages 0 to 15??
  1. The erase sector erases all data in 16 pages, what happens if I try to erase starting on the last page? It will overflow and erase data in the 0-14 pages as well?

Thanks!

Bug Report : Arduine freezes when looping on readWriteString.ino example sketch

GitHub issue state GitHub issue title GitHub issue author GitHub issue label GitHub issue comments GitHub issue age GitHub issue last update

---------------------------- DO NOT DELETE OR EDIT anything above this line ----------------------------

Hello!

I'm submitting a bug report, I tried to identify what's going wrong but I cannot fix it...

Bug report :

Library version : 3.0.0
Branch : master
Arduino IDE : 1.8.4
OS : Windows
Microcontroller : Arduino-nano (Atmega328P)
Flash memory module : W25Q64 freshly erased
Current behaviour :
I edited the example sketch readWriteString in order to repeat the Write/Read/Erase functions of the sketch but after 3 iterations the Arduino nano freezes.
Here is the serial output :

Written string: This is a test String
To address: 7025326
Read string: This is a test String
From address: 7025326
Written string: This is a test String
To address: 4996536
Read string: This is a test Str�
To address: 4996536

Expected behaviour :
The Arduino should loop until the for condition is reached

Code snippet that reproduces the bug (edited readWriteString example sketch) :

#include<SPIFlash.h>

uint32_t strAddr;

#if defined(ARDUINO_SAMD_ZERO) && defined(SERIAL_PORT_USBVIRTUAL)
// Required for Serial on Zero based boards
#define Serial SERIAL_PORT_USBVIRTUAL
#endif

#if defined (SIMBLEE)
#define BAUD_RATE 250000
#define RANDPIN 1
#else
#define BAUD_RATE 115200
#define RANDPIN A0
#endif

//SPIFlash flash(SS1, &SPI1);       //Use this constructor if using an SPI bus other than the default SPI. Only works with chips with more than one hardware SPI bus
SPIFlash flash;

bool readSerialStr(String &inputStr);

void setup() {
  Serial.begin(BAUD_RATE);
#if defined (ARDUINO_SAMD_ZERO) || (__AVR_ATmega32U4__)
  while (!Serial) ; // Wait for Serial monitor to open
#endif

  flash.begin();
  randomSeed(analogRead(RANDPIN));

    for (int i=0;i<1000;i++) {  
    
      strAddr = random(0, flash.getCapacity());
      String inputString = "This is a test String";
      flash.writeStr(strAddr, inputString);
      Serial.print(F("Written string: "));
      Serial.println(inputString);
      Serial.print(F("To address: "));
      Serial.println(strAddr);
      String outputString = "";
      if (flash.readStr(strAddr, outputString)) {
        Serial.print(F("Read string: "));
        Serial.println(outputString);
        Serial.print(F("From address: "));
        Serial.println(strAddr);
      }
      while (!flash.eraseSector(strAddr));
    
      delay(1000);
    }  
}

void loop() {

}

//Reads a string from Serial
bool readSerialStr(String &inputStr) {
  if (!Serial)
    Serial.begin(115200);
  while (Serial.available()) {
    inputStr = Serial.readStringUntil('\n');
    Serial.println(inputStr);
    return true;
  }
  return false;
}

Other information :

  • I tried to show memory usage during loops but this doesn't help
    Here is the serial output :
freeRam()=1585
Written string: This is a test String
To address: 6773221
Read string: This is a test String
From address: 6773221
freeRam()=1557
Written string: This is a test String
To address: 4114840
Read string: This is a test Str�
From address: 4114840
freeRam()=1557

  • I moved the Write/Read/Erase functions into the main "loop" function and the problem is the same
  • I uncommented #define RUNDIAGNOSTIC in SPIFlash.h with no effect
  • I have better result by passing outputString and inputString as global variables but there is still unexpected behaviour. Here is the serial output with unprintable characters :
    serialoutput
    serialoutput_2
    The Arduino reboots at each "strange" line

I must be sure that the library is reliable before using it in projects so any help is welcome ! 😀

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.