Arduino Forum

Using Arduino => Storage => Topic started by: Marzogh on May 19, 2015, 04:42 pm

Title: SPIMemory library - Formerly SPIFlash - now supports SPI FRAM as well! :)
Post by: Marzogh on May 19, 2015, 04:42 pm
Hi all, I've just written up a library with a bunch of basic and advanced functions for the SPI Flash modules.

I'm looking at adding more functionality to the library in time. Any suggestions/improvements are welcome.

Update 03.06.2019:

Library is now called SPIMemory not SPIFlash. (http://forum.arduino.cc/index.php?topic=324009.msg3639804#msg3639804)

      - Just updated to v 3.4.0 with a number of bug fixes and enhancements. Refer to change log  (https://github.com/Marzogh/SPIMemory/blob/master/Change%20log.md)for further details. .

As always, You can find the latest version on Github here --> SPIMemory Library for Arduino (https://github.com/Marzogh/SPIMemory/releases/latest). v3.4.0 is also attached to this post as a ZIP file. :)  (All the old versions are still attached)
Title: Re: Winbond SPI Flash library (W25Q80BV)
Post by: Marzogh on May 22, 2015, 03:48 am
Just updated to v 1.0.1 and added the ability to output data to Serial as CSV decimal values.

As always, You can find the latest version on Github here --> SPI Flash library for Arduino (https://github.com/Marzogh/SPIFlash). V1.0.1 is attached to this post. :)
Title: Re: Winbond SPI Flash library (W25Q80BV)
Post by: ghlawrence2000 on Jun 04, 2015, 07:34 pm
Nice work, but it is not specific to the W25Q08! not 80...  they all share the same command structure, as such will also work for 2M, 4M, 8M & 16M :-

Code: [Select]
#define CHIP_SIZE128     16L * 1024L * 1024L  //W25Q128
#define CHIP_SIZE64       8L * 1024L * 1024L  //W25Q64
#define CHIP_SIZE32       4L * 1024L * 1024L  //W25Q32
#define CHIP_SIZE16       2L * 1024L * 1024L  //W25Q16
#define CHIP_SIZE8        1L * 1024L * 1024L  //W25Q08


Regards,

Graham
Title: Re: Winbond SPI Flash library (W25Q80BV)
Post by: chucktodd on Jun 05, 2015, 09:09 am
How does your Library handle the 4k Erase sector size?  do you use a triangle buffer? The Uno only has 2k of ram.  If you need to change a value in the flash you have to erase an entire 4KB sector.

I wrote a similar Library, but I added a 64KB SPI Ram chip to use as a temporary buffer to copy the sector data into.  My library first verifies that the write is possible (memory bits can be programed to '0' only), if a bit is already '0' and needs to be a '1', it copies the corresponding sector to the SPI RAM, initiates a Sector Erase, merges the new data into the SPI RAM image, then after the Sector Erase Completes writes all non '0xff' bytes back into the FLASH by 256byte pages.

Chuck.
-----------------
check out my Kickstarter Memory Panes (https://www.kickstarter.com/projects/1052400055/mega2560-expansion-ram-arduino-compatible-xmem) a 1MB RAM expansion Shield for MEGA2560 projects.
Title: Re: Winbond SPI Flash library (W25Q80BV)
Post by: ghlawrence2000 on Jun 05, 2015, 09:41 am
Regarding your kickstarter project, NICE!! But why is it specific to the MEGA? Same form factor as the DUE, SPI pinout virtually the same, consider making the necessary modifications to work with MEGA AND DUE and I can see your project will do well or at least increase the potential number of devices pledged.

Regards,

Graham
Title: Re: Winbond SPI Flash library (W25Q80BV)
Post by: chucktodd on Jun 05, 2015, 10:20 pm
The DUE doesn't express all of the necessary pins from the Atmel processor.  The SAM3x does not multiplex A0-A7 and D0-D7.  The Processor has D0-D15 (PC2-PC17) A0-A22 (PC21-PC30,PD0-PD9)

But the DUE only expresses 

PC 2-9,12-17,21-26,28,30  Missing Data D8,9 Address A6,A8
PD 0-3,6-9 Missing Address A14,15

So, it is not possible unless a NEW Mega DUE is created and all of the necessary pins are expressed.

Chuck.
Title: Re: Winbond SPI Flash library (W25Q80BV)
Post by: robtillaart on Jun 06, 2015, 08:41 am
Had a very quick look, and I noticed writepage does check the pagenumber but readpage doesn't.
shouldn't that be checked too?

Code: [Select]

boolean  SPIFlash::_readPage(uint16_t page_number, uint8_t *page_buffer) {
if(!_notBusy())
return false;
...

boolean SPIFlash::_writePage(uint16_t page_number, uint8_t *page_buffer) {
if(!_notBusy() || page_number >= 4096 || !_writeEnable())
return false;



page_number >= 4096  part
Title: Re: Winbond SPI Flash library (W25Q80BV)
Post by: robtillaart on Jun 06, 2015, 08:54 am
debugging refactored
Code: (not tested) [Select]

//Prints hex/dec formatted data from page reads - for debugging
void SPIFlash::_printPageBytes(uint8_t *page_buffer, uint8_t outputType)
{
  char buffer[10];
  if (outPutType == 1)
  {
    for (int idx = 0; idx < 256; ++idx)
    {
      sprintf(buffer, "%02x,", page_buffer[idx]);
      Serial.print(buffer);
    }
  }
  else   // if (outPutType == 2)
  {
    for (int idx = 0; idx < 256; ++idx)
    {
      int x = page_buffer[idx];
      if (x < 10) Serial.print("0");
      if (x < 100) Serial.print("0");
      Serial.print(x);
      Serial.print(',');
    }
  }
}


Title: Re: Winbond SPI Flash library (W25Q80BV)
Post by: robtillaart on Jun 06, 2015, 09:18 am
using the return values of the private function result in faster failing.

Code: [Select]

boolean SPIFlash::writePage(uint16_t page_number, uint8_t *page_buffer)
{
  uint8_t temp_buffer[256];
  char buffer[28];  // <<<<<<< 80 is overkill, wastes heap space (more places)

  if (false == _writePage(page_number, page_buffer)) return false;
  if (false == _readPage(page_number, temp_buffer)) return false;

  for (int a=0; a<256; ++a)
  {
    if (!temp_buffer[a] == page_buffer[a]) return false;
  }
  sprintf(buffer, "Writing page (%04x) done", page_number);
  Serial.println(buffer);

  return true;
}


my 2 cents
Title: Re: Winbond SPI Flash library (W25Q80BV)
Post by: Marzogh on Jun 20, 2015, 07:00 pm
Just updated to v 1.2.1 with a bunch of optimizations and improvements .

As always, You can find the latest version on Github here -->SPIFlash Library for Arduino v1.2.1 (https://github.com/Marzogh/SPIFlash/releases/tag/v1.2.1) A ZIP file is also attached to this post. :)

My apologies for not getting on here in a while. It was a very busy month at Uni with the semester coming to an end and field trip season starting up. I've only just managed to get back on now.

@Graham I haven't played around with the other chips or looked at their datasheets yet, so thank you for pointing it out. It'll be the next thing I get on to. :)

@Chuck Unfortunately all the erase functions just erase, thanks to the Uno's 2K RAM. I can't think of any way to get around it without resorting to what you've done with external SPI RAM. The onboard RAM also limits the use of the readBytes() and writeBytes() functions in the latest version of the library. :(

I've been considering tossing in some FRAM. I just got some samples from Fujitsu and I'm waiting for a few components to arrive from Element14 before I cook up some breakout boards in the toaster. I'll test them out and post the results ASAP. :)

Good luck with the Kickstarter! :)

@Rob Thanks for the feedback. :) The latest version of the library does not have _readPage() and _writePage() anymore. It also has page_number and offset checking built in where ever they are used. Also, Address rollover is the default action for when the end of the memory bank is reached during any operation - rollover can be disabled globally with an optional argument in the constructor. (Now that I think of it, perhaps I should make it a local argument in any function that requires it - it might give a user more flexibility?).

Thank you for your suggestion on the debug code. My version is a bit clumsy I admit, but it outputs the code in a neat 16/16 grid which makes it easy to read. I'm still trying to see if there's a cleaner way of formatting the output, but I'm pretty much a self-taught programmer (I'm a geneticist by trade) and I'd love to learn a new way of doing things if you have any suggestions. :)

I've used some of the code from your suggestion (below) in the latest version of the library. Thank you for that!
Code: [Select]
uint8_t x = data_buffer[a * 16 + b];
if (x < 10) Serial.print("0");
if (x < 100) Serial.print("0");
Serial.print(x);
Serial.print(',');


I've actually re-written writePage() completely so it no longer uses _writePage(). My current version checks the written data byte by byte without actually having to read it all into a buffer first. Saves a ton of time in the process and catches errors exactly where they happen. I'm toying with the idea of including a subroutine in my error checking protocol to return the exact location of the error so a user can ID any faulty registers.
Title: Re: Winbond SPI Flash library (W25Q80BV)
Post by: chucktodd on Jun 21, 2015, 02:12 am
Just updated to v 1.2.1 with a bunch of optimizations and improvements .


@Chuck Unfortunately all the erase functions just erase, thanks to the Uno's 2K RAM. I can't think of any way to get around it without resorting to what you've done with external SPI RAM. The onboard RAM also limits the use of the readBytes() and writeBytes() functions in the latest version of the library. :(

I've been considering tossing in some FRAM. I just got some samples from Fujitsu and I'm waiting for a few components to arrive from Element14 before I cook up some breakout boards in the toaster. I'll test them out and post the results ASAP. :)

Good luck with the Kickstarter! :)
I was hoping you had came up with some magical way, that did not encounter this issue.  But I guess magic is rare :smiley-money: .

When you say you work with 'software' your really mean 'Wetware?' :)

Well, I'm up to 14 backers, only Need 55 :(

Chuck.


Check out my Kickstarter Project Memory Panes (https://www.kickstarter.com/projects/1052400055/mega2560-expansion-ram-arduino-compatible-xmem) an expansion RAM Shield for Mega2560's.  It adds 1MB of RAM for those projects where 8KB is not enough.

 
Title: Re: Winbond SPI Flash library
Post by: Marzogh on Aug 31, 2015, 01:49 am
Just updated to v1.3.0 with a serious set of improvements including writeAnything() & readAnything(), support for writing & reading most supported variable types (String support to come in future updates) and built in error checking. :)

As always, You can find the latest version on Github here -->SPIFlash Library for Arduino v1.3.0 (https://github.com/Marzogh/SPIFlash/releases/tag/v1.3.0) A ZIP file is also attached to the first post on this thread. :)

@Chuck: Too bad the Kickstarter didn't go through. :( I was a backer. Are you going to open source your design?
Title: Re: Winbond SPI Flash library
Post by: jtewell on Sep 14, 2015, 08:09 pm
Hi Marzogh

Brilliant library, got a W25Q128FV working with my Mega board. Tried to wire it up to my Due board but encountered some problems. Commenting out the #include <util/delay.h> in the SPIFlash.cpp file gets it to compile, but my Due board becomes unresponsive after calling the constructor. It seems to occur after the SPI.begin() call. Any ideas for a quick fix?
Title: Re: Winbond SPI Flash library
Post by: Marzogh on Sep 16, 2015, 01:53 pm
Hi Jtewell,

Thanks for that. I'm glad it works well with the Mega. :) It has been throwing errors with the Leonardo and I haven't had time to fix that yet. :( Unfortunately I have close to zero experience working with ARM processors and can't help with the issue you are facing. I'm still working on learning more about the Due and plan on including support once I figure out where I stand.

If you do find a way to add Due support, feel free to fork the github repo and submit any changes - I'm always open to learning something new. :)
Title: Re: Winbond SPI Flash library
Post by: Marzogh on Oct 09, 2015, 08:39 am
Just updated to v1.3.2 which supports storage and retrieval of Strings, along with a raft of other features. :)

As always the latest version can be found at here (https://github.com/Marzogh/SPIFlash/releases/latest).
Title: Re: Winbond SPI Flash library
Post by: Marzogh on Oct 14, 2015, 12:36 am
Just pushed through a big update to v2.0.0.

- BIG update in terms of speed. Sped up all functions atleast 25x
- Compatible with ATTiny85
- All Read/Write/Erase functions can now take either (page number & offset) or (address) as arguments (Except readPage())
- getAddress() can now return either a 32-bit address or a page number & offset.

As always, you can find this version on Github here -->SPIFlash Library for Arduino v2.0.0 (https://github.com/Marzogh/SPIFlash/releases/tag/v2.0.0) A ZIP file is also attached to the first post on this thread. :)
Title: Re: Winbond SPI Flash library
Post by: Marzogh on Oct 18, 2015, 07:16 am
Just pushed through an update to v2.1.0

- The library now supports the Arduino Due!
- Lots more optimizations + even better ATTiny85 support

As always, you can find this version on Github here -->SPIFlash Library for Arduino v2.1.0 (https://github.com/Marzogh/SPIFlash/releases/tag/v2.1.0) A ZIP file is also attached to the first post on this thread. :)

P.S. jtewell : This might be the version you are looking for!
Title: Re: Winbond SPI Flash library
Post by: Stephan_uino on Oct 24, 2015, 05:19 pm
Help please! I am trying to get the W25Q80BV Winbond 1Mbyte Spi Flash DIP chip to work with the Arduino Due, but it gets stuck in function flash.begin.
I am using example programms fron Marzogh/SPIFlash V2.1.1 with Arduino V1.6.5 with an Arduino due.
The examples compile fine and upload to the Due board fine but all I see is
"Initialising Flash memory………."
Nothing else is written to the screen. Further investigation shows it get stuck in flash.begin();
I have wired the chip to the Due as follows:
Chip pin 1 -> Due pin 10 (Chip Select)
Chip pin 2 -> Due pin MISO (108) (SPI Pins)
Chip pin 3 -> Vcc 3.3V
Chip pin 4 -> GND (Common GND for chip and Due)
Chip pin 5 -> Due pin MOSI (109) (SPI Pins)
Chip pin 6 -> Due pin SCK (110) (SPI Pins)
Chip pin 7 -> Vcc 3.3V
Chip pin 8 -> Vcc 3.3V
Any help will be much appreciated.
Title: Re: Winbond SPI Flash library
Post by: Marzogh on Oct 28, 2015, 01:42 am
That is unexpected. v2.1.1 was a bug fix release for the powerUp & powerDown functions so I didn't realise I'd broken Due support. Thanks for the heads up - I'll test and get back to you with a fix shortly, however, for the time being, using v2.1.0 should solve the problem.

Update:

I've just tested my Due with v2.1.1 and the only issue I have with it is that powerDown() returns a false negative (This is being fixed in the upcoming v2.2.0). Everything else is functioning properly and returns the following:

Code: [Select]
Initialising Flash memory..........


----------------------------------------------------------------------------------------------------------------------------------
                                                           Get ID                                                                 
----------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------
Manufacturer ID: efh
Memory Type: 13h
Capacity: 4014h
JEDEC ID: ef4014h
----------------------------------------------------------------------------------------------------------------------------------
                                                          Write Data                                                             
----------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------
Data Written || Data Read || Result
----------------------------------------------------------------------------------------------------------------------------------
35 || 35 || Pass
-110 || -110 || Pass
4520 || 4520 || Pass
-1250 || -1250 || Pass
876532 || 876532 || Pass
-10959 || -10959 || Pass
3.1415 || 3.1415 || Pass
123 Test !@# || 123 Test !@# || Pass

Struct data written successfully
31325, 4.84, 880932, 1, 5
Saved!
Local values set to 0
After reading
31325, 4.84, 880932, 1, 5

Values from 0 to 255 have been written to the page 484
These values have been read back from page 484
Reading page (01e4)
000,001,002,003,004,005,006,007,008,009,010,011,012,013,014,015,
016,017,018,019,020,021,022,023,024,025,026,027,028,029,030,031,
032,033,034,035,036,037,038,039,040,041,042,043,044,045,046,047,
048,049,050,051,052,053,054,055,056,057,058,059,060,061,062,063,
064,065,066,067,068,069,070,071,072,073,074,075,076,077,078,079,
080,081,082,083,084,085,086,087,088,089,090,091,092,093,094,095,
096,097,098,099,100,101,102,103,104,105,106,107,108,109,110,111,
112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,
128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,
192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,
224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,
240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,


Have you tried running Diagnostic.ino - included in the examples after uncommenting #define RUNDIAGNOSTIC from the top of SPIFlash.cpp? (Make sure you save SPIFlash.cpp before you recompile and upload Diagnostics.ino) If you have, what errors did it print to your serial?

Can you post a photo of your wiring?

Also, if all fails have you tried using a different chip? I have previously found the chip returns 'busy' if the breadboard connections are not properly made or if the chip is faulty and not responding.
Title: Re: Winbond SPI Flash library
Post by: Stephan_uino on Oct 29, 2015, 11:54 am
Thankyou for this reply. I am working on this today. I will use another chip just in case and will send you a photo and let you know how I get on.
I have noticed some people use lots of resistors and a 0.1uf capcitor between VCC and GND but I simply connect direct and use the Due's 3.3V for VCC. (Trust my connections above are OK for the Due) Excelent Library you have. I am sure I had something simple wrong the first time I tried it.
Title: Re: Winbond SPI Flash library
Post by: Stephan_uino on Oct 29, 2015, 12:22 pm
It works :) Many thanks for your help. Much appreciated. Excellent library, especially as you support the Arduino Due which needs the SPI memory more than most.

I have attached a photo of my setup but it is hard to see. The wiring is as stated above and now the examples are working. Perhaps I had a duff chip as I have not knowingly made any changes other than swap the chip out.

Thanks again Stephan
Title: Re: Winbond SPI Flash library
Post by: Marzogh on Oct 29, 2015, 04:01 pm
Hi Stephan,

I'm glad it works and that you find the library useful. Connecting a 0.1uF cap across VCC and GND is totally up to whether you think you need to minimize any noise on your power bus. I haven't had the need for one yet. :)

Also, if you choose to use the powerDown() mode for low power while using v2.1.1, I'd recommend that you  refer to Issue 15 (on Github) (https://github.com/Marzogh/SPIFlash/issues/15#).

Good luck with whatever you project is and thanks for the photo. The connections look ok and as you said, it might have just been a bad chip.

Cheers!
Title: Re: Winbond SPI Flash library
Post by: Hoek on Oct 31, 2015, 12:01 pm
Been writing a similar driver for the spansion S25FL132K and similar chips which will have Due and Teensy support as I use a small common library for the low level pin setting. After reading the documentation this library should work for the other chips if single mode is chosen.

I've also implemented it primarily as QSPI but normal SPI mode should work. As the guts of it had QSPI in mind it bitbangs the data too and from the slave device.

Seems the QSPI is quite new as didn't find any other libraries using it.




Title: Re: Winbond SPI Flash library
Post by: Marzogh on Nov 03, 2015, 03:00 am
I've never looked at those chips before. They'd be an useful addition to the library. :) My plan's to add support for ATMEL's flash chips sometime in the future and support for Spansion's flash chips would make it more widely useful.

I've never seen QSPI being used in any other libraries either. The Winbond Chips support DSPI and QSPI. Its something I'd like to integrate into the library if I can.

P.S. Is your code on Github? I'd love to get a look at it if that's ok :)
Title: Re: Winbond SPI Flash library
Post by: chucktodd on Nov 03, 2015, 06:29 am
I've never looked at those chips before. They'd be an useful addition to the library. :) My plan's to add support for ATMEL's flash chips sometime in the future and support for Spansion's flash chips would make it more widely useful.

I've never seen QSPI being used in any other libraries either. The Winbond Chips support DSPI and QSPI. Its something I'd like to integrate into the library if I can.

P.S. Is your code on Github? I'd love to get a look at it if that's ok :)
But,
   The whole point of DSPI and QSPI is speed.  Bit banging QSPI uses more resources (4bit databus + SCK + SS). And it is slower.  Using software to build the nibbles, output them, stimulate the Clock, cannot be twice as fast as 4mhz one bit SPI?  A single byte SPI at 4mhz takes 32 clock cycles, how many op codes are executed to emulate QSPI?

I realize the SPI.h code is not interrupt driven, I wrote a version that does the transfers in a background interrupt setting.  As long as I code the foreground code to politely handle atomic access to the SPI hardware I can do two things at once.  If I were to used a bit banged QSPI function I believe it would slow down my code.

What benefit do you receive using QSPI?

Chuck.
Title: Re: Winbond SPI Flash library
Post by: Hoek on Nov 14, 2015, 02:16 am
I've never looked at those chips before. They'd be an useful addition to the library. :) My plan's to add support for ATMEL's flash chips sometime in the future and support for Spansion's flash chips would make it more widely useful.

I've never seen QSPI being used in any other libraries either. The Winbond Chips support DSPI and QSPI. Its something I'd like to integrate into the library if I can.

P.S. Is your code on Github? I'd love to get a look at it if that's ok :)
Sorry for the long delay in answering. I've only just started testing the library as the breakout boards took so long to arrive "fast aussie delivery". Anyway got the normal serial stuff to work finally. Got the guts working, setting and reading status, read byte(s), verify byte(s), write buffer to location, page dump function for debugging.

I can set quad mode enable (QE) and it sets the correct bit however the quad read function is returning rubbish from my test page which simply has the values 0-255 on the page. I've looked at the datasheet a zillion times, rechecked pin connections but at best the 1st 10 are correct then it goes all bad. I want to eventually put this on github, but when at least the quad mode is working. If it was working, the speed is about 2.5x faster than serial mode. However, it could be faster if the 4 data pins were sequential on the same port and they were all read/set as a single operation.

At the moment I want it just to work... then I'll optimize it and add a few options.

My code at the moment is just a single .ino file with everything in it for testing. If you want a copy pm me and I'll email a copy.

Also found the following link useful http://www.corelis.com/education/SPI_Tutorial.htm (http://www.corelis.com/education/SPI_Tutorial.htm) as talks about quad speed SPI. It mentions io1, io2 and io3 need to be tristated (high impedance) from what I could figure this means their pinmode should be "input". I have a feeling this is the cause of the problem.

Title: Re: Winbond SPI Flash library
Post by: A_Solis on Nov 17, 2015, 08:21 am
I have recently started using the Spiflash library and need some help with the getAdress() section.   I read the .cpp file and a bit confused on how it works in terms of practical application. 

If I have 5 strings 
s1="one",
s2= "two",....
...
..
s5 = "five"

 and if I want to write them in consecutive order ,so that s1 is on page 0,section 0 , s2 will be on page 0,section (s1.length +1).... or the next available address after the end of string s1. How can I utilize the getAddress() function to indicate the next address?  I may be using it out of context but any help to get me started would be appreciated. 

Thanks in advance. 

Adam
Title: Re: Winbond SPI Flash library
Post by: Marzogh on Nov 25, 2015, 04:44 am
Hi Adam,

My apologies for the delay in getting back to you - I am not usually very active on the forums.

Coming to your issue, I'd recommend you update your version of SPIFlash to the latest version - 2.2.0. It has an example called 'getAddressEx.ino' which should walk you through the process. The latest version also simplifies the getAddress() function when it comes to Strings.

If it still doesn't work, feel free to let me know here - I'll keep an eye on this thread for your reply. :)

Cheers,

Praj
Title: Re: Winbond SPI Flash library
Post by: Marzogh on Nov 25, 2015, 04:58 am
Just pushed through an update to v2.2.0

- When #RUNDIAGNOSTIC is uncommented, the _troubleshoot() function is now optimised for different µCs
- Added the ability to check if the address has been previously written to before initiating a write operation.
- Added a sizeofStr() function to get sizes of String objects, to use with the getAddress() function
- Fixed a bug with getAddress()
- Added the ability get the chip's name via getChipName() (Refer to Diagnostics.ino to see how it can be used)
- Diagnostics.ino has been made more and efficient and provides a cleaner Serial output
- Added getAddressEx.ino to examples show how getAdress() works.

As always, you can find this version on Github here --> SPIFlash Library for Arduino v2.2.0 (https://github.com/Marzogh/SPIFlash/releases/tag/v2.2.0)
A ZIP file is also attached to the first post on this thread. :)

@Chuck, I have barely scratched the surface of QSPI or DSPI and as I have a functioning library for a chip that supports both those protocols, I'm curious to see how I can make it work on an Atmega328. My interest is purely academic - unless a miracle happens and bitbanging QSPI turns out to be faster than hardware SPI :P.

@Hoek, I'm quite curious about how far you've gotten it working. Will PM you now :) Thanks for the link as well! :)
Title: Re: Winbond SPI Flash library
Post by: A_Solis on Nov 27, 2015, 09:44 pm
Thanks for the Reply:

I found what I was looking for by the example posted below.  I will store coordinates from a gps module and just needed single increments of the address block versus using the (page,offset) method.  Just helps to keep the code clean. 

... The following will successively write to the memory chip and all I would need to do is keep track of which element was last written to. 



 //globals


uint32_t addy =0x0000;
uinit8_t cnt=0;


// This will count to 0x3eb ...(decimal 1000) and the counter will increment by 1 and reset at 250: repeats 4 times


 for (addy = 0x0000; addy <= 0x3eb; addy+=0x1) {
 
  flash.writeByte(addy, cnt, true);
  if(cnt==250){
    cnt=0;
  }
  else  cnt++;
}

for (addy= 0x0000; addy <= 0x3eb; addy+=0x1) {
  Serial.println();
  Serial.println(flash.readByte(addy, false));
}




The SPI library you have made is amazing... I will update to the latest version and look forward to utilizing the last known memory allocation to make things easier. 

Title: Re: Winbond SPI Flash library
Post by: Marzogh on Dec 01, 2015, 01:00 am
I'm glad you find the library useful. :)

I'm also a little confused, I thought you'd said you needed to store Strings and not Bytes... if you let the address increment by 1 you're just moving forward by one bytespace and it won't work for strings or floats or pretty much anything larger than a byte.

Also in your code when you say
Code: [Select]
flash.writeByte(addy, cnt, true);
...
Serial.println(flash.readByte(addy, false));

- the boolean arguments you are supplying at the end are unnecessary. The library defaults to using errorChecking and not using fastRead. Your code will look cleaner as well. :)

So,
Code: [Select]
flash.writeByte(addy, cnt);
...
Serial.println(flash.readByte(addy));

will work just the same.

Another note: 0x3EB is 1003 dec. 0x3E8 is 1000

Edit: Also, the functions you are setting up in your code effectively duplicate parts of the getAddress() function. Using the builtin getAddress() makes it easier to get addresses for every function in the library.

Your code could be easily re-written as follows:
Code: [Select]

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

#define cs 10

//declare an array to hold data
uint8_t counter[1000];
//This is the library constructor
SPIFlash flash(cs);
void setup() {

  //Fill array with bytes
  uint8_t j = 0;
  while (j < 4) {
    for (uint8_t i = 0; i < 250; i++) {
      counter[(250 * j) + i] = i;
    }
    j++;
  }

  //Get address for array
  uint32_t arrayAddr = flash.getAddress(sizeof(counter));

  //Now write the array to memory
  if (flash.writeByteArray(arrayAddr, counter, 1000)) {  //1000 or 0x3E8 is the size of the array
    Serial.println("Data successfully written to chip");
  }
  else {
    Serial.println("Data write unsuccessful");
  }
  //declare a new array to hold the data being read in
  uint8_t counterRead[1000];

  flash.readByteArray(arrayAddr, counterRead, 1000);    //1000 or 0x3E8 is the size of the array
  //print out the data that has been read in to the Serial port
  for (int i = 0; i < sizeof(counterRead); i++) {
    Serial.print(counterRead[i]);
    Serial.print(", ");
    if ((i%16) == 0) {              //This code just formats the serial output to be neat
      Serial.println();
    }
  }
}

void loop() {}

Doing it this way means your code executes a lot faster.

Cheers,

Praj

P.S. When you insert code, could you please wrap it in [ code ]...[ /code ] (without the spaces)? It makes it easier to read the forums. :)
Title: Re: Winbond SPI Flash library
Post by: Okio on Jan 04, 2016, 07:50 pm
Excellent Lib. Using it with a single 25Q128FVSG (16MB) on a Nano testbed but will try with 2x 25Q128FVSG on a Due tomorrow.
Using this wiring without the decoupling cap:
(http://mylcd.sourceforge.net/tmp/25Q128FVSG.png)
Title: Re: Winbond SPI Flash library
Post by: Clemi_81 on Feb 04, 2016, 03:30 pm
This library really offers some functionality, other flash libraries do not have.

Unfortunately, I cannot get it running on Teensy 3.2.

Has anyone out there been able to run this library on Teensy?

If not maybe some can help me doing it on my own.

First interesting thing, I would like to know is, which SPI library is used? The SPI libraries that come with Arduino IDE or Teensyduino seem to have different function parameters than the ones called from this SPIFlash library.

Second question may sound a little bit naive but I need to know.
Everywhere in the code I find
#if defined (__arm__) && defined (__SAM3X8E__)
action 1
#else
action 2

I would assume for me the path of __arm__ should be the correct one. But I would like to have a more experienced second opinion.

Thank you for reading.
Title: Re: Winbond SPI Flash library
Post by: Marzogh on Feb 20, 2016, 04:55 am
I have yet to get around to testing the library on a Teensy, so I cannot guarantee that it will work there. The library uses the standard SPI.h that comes by default with the Arduino IDE. Which version of the IDE are you running? I've only got this working till 1.6.5. Any version > 1.6.5 causes too many issues for me to bother with adding compatibility.

The bit that says
Code: [Select]
#if defined (__arm__) && defined (__SAM3X8E__)
action 1
#else
action 2
in the library, is to support the Arduino Due. Both the Due and Teensy use ARM uCs. However, the Due uses the Atmel SAM3X / SAM3A Series ARM uC while the Teensy uses the Freescale MK20DX256VLH7 ARM uC and so, what works for the Due will not work for the Teensy.
Title: Re: Winbond SPI Flash library
Post by: Robotti on Feb 24, 2016, 08:37 pm
Thank you! Your library worked fine with Arduino Pro Mini ATmega328 3V3 and W25Q40BVNIG chip that was included in this eBay-module:

http://www.ebay.com/itm/262054312026?_trksid=p2057872.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT 

The W25Q40BVNIG is the hardware SPI flash chip of my ESP8266 modules. That is the reason why I am interested in it.

Unfortunately I couldn't make your library and W25Q40BVNIG work with my ESP-07 module.

Would you have any suggestions for me how to go further? I am trying to connect an external W25Q40BVNIG chip to an ESP8266.

(Win 10; Arduino 1.6.7; Board: NodeMCU 1.0; /CS connected to GPIO2 of the ESP8266; other pins to normal SPI-pins of ESP8266; eBay module includes 10 kohm pullup resistors to DO, /WP, /HOLD, CLK and DI).
Title: Re: Winbond SPI Flash library
Post by: Robotti on Feb 24, 2016, 10:16 pm
My problem is solved. I modified this program

http://www.instructables.com/id/How-to-Design-with-Discrete-SPI-Flash-Memory/step5/Code-Code-Code/

and now I can use W25Q40xxx with ESP8266 :-) This will be good enough for me at the moment.
Title: Re: Winbond SPI Flash library
Post by: mcnobby on Mar 02, 2016, 02:51 pm
Thank you, I am looking forward to using this library. Excellent !!
Title: Re: Winbond SPI Flash library
Post by: Marzogh on Mar 09, 2016, 02:39 am
@Robotti: I haven't had the time to add ESP8266 support but it is in the works. The instructable you have linked in is a fantastic way of learning to communicate over SPI - I'm glad it helped. Keep an eye out here on the Github page for updates. I'm working on adding both Teensy and ESP8266 support and should have them going in the next couple of months.

@mcnobby Cheers! I'm glad you find it useful! :)
Title: Re: Winbond SPI Flash library
Post by: wsteelmanj on Apr 08, 2016, 06:25 pm
@Okio is that also the correct wiring for the W25Q256FV with an ATMega328p? And couldn't you save a pin by wiring the Chip Select (Pin 1) straight to GND? There's no harm in always keep the chip selected right? The project I am working on requires a lot of pins and I'm trying to conserve if possible.



Title: Re: Winbond SPI Flash library
Post by: CrossRoads on Apr 08, 2016, 06:45 pm
If you keep chip select always low, than MISO may always be driven by the chip and may interfere with other SPI devices.

Can always add a shift register (or two or three) and create up to 8 (16, 24, etc.) chip selects that way using just 3 IO pins.
Title: Re: Winbond SPI Flash library
Post by: chucktodd on Apr 09, 2016, 08:51 am
@Okio is that also the correct wiring for the W25Q256FV with an ATMega328p? And couldn't you save a pin by wiring the Chip Select (Pin 1) straight to GND? There's no harm in always keep the chip selected right? The project I am working on requires a lot of pins and I'm trying to conserve if possible.
No,
 you must toggle the CS pin at the start and end of each transaction.  the SPI interface is just a bit stream, the CS pin is used to alert the device that It should start watching the SCK and MOSI pins.

Without an active CS pin, you can only do ONE command either a READ or WRITE, then you would have to power down and start over.

This is because the chip (W25xx) expects a command byte, possibly address bytes, then an unknown number of data bytes. the digitalWrite(CS,HIGH) terminates the transmission which causes the chip to recycle it's machine state back to where it is expecting a command byte.

If you have many SPI devices you can use a 2:4 decoder which allows 2 Arduino Pins to select one of three SPI devices.  Or you can use a 3:8 decode which allows 3 arduino pins to control seven SPI devices.

Here is a schematic of how I use a 3:8 decoder to control 5 devices with 3 pins.
(http://s5.postimg.org/51t2h7eaf/SPI_Selector.jpg)

With this circuit, D8..D10 are my CS pins, of the 8 possible value 0x07 is reserved to mean NONE are selected.  I keep D8..D10 high to unselect all SPI devices I can Select my SDCard, FLASH, or RAM devices by changing only one pin to low, to Select my RS232 or RS485 I have to do two or three digitalWrite() commands.  Between the digitalWrite() commands, the WRONG device is selected.  After I set D8..D10 to the correct value, I delay for short time(500ns) to let the chips settle out.

Chuck.
Title: Re: Winbond SPI Flash library
Post by: wsteelmanj on Apr 29, 2016, 03:24 pm
Thanks Chuck. I got my chip all wired up and now I have another question about programming.

I am using a W25Q128FVSIG which is 16MB. So how would I go about putting say 5MB of data on the chip? I'm thinking I want to read the data from a text file on my pc via the serial port, but I don't want it to take several hours if possible. Is there a way for the arduino to access and read a file on my computer? Or should I be writing some code on my computer which sends the data through the serial monitor? And if the latter than what is the best software to do that with? Thanks guys.
Title: Re: Winbond SPI Flash library
Post by: chucktodd on Apr 30, 2016, 07:15 am
Thanks Chuck. I got my chip all wired up and now I have another question about programming.

I am using a W25Q128FVSIG which is 16MB. So how would I go about putting say 5MB of data on the chip? I'm thinking I want to read the data from a text file on my pc via the serial port, but I don't want it to take several hours if possible. Is there a way for the arduino to access and read a file on my computer? Or should I be writing some code on my computer which sends the data through the serial monitor? And if the latter than what is the best software to do that with? Thanks guys.
You'll have to write software, That is what I am doing.  I have a similar setup.  AtMega2560, SPIram(64kB) SPIFlash(8MB).  I am writing a simple block transmission client and server.  It is part of a bigger project.
the client (Mega2560) watches for for single byte control characters, all data is transmitted as ASCII coded HEX with using the Intel Hex format. with a few extra commands to specify chip,type, offset.

Chuck.
Title: Re: Winbond SPI Flash library
Post by: frackers on May 09, 2016, 02:21 am
I've been trying to use an array in the first page of a block to indicate which pages in a block are available for use. To do this I've attempted to set the array elements to 1 or 2 depending on usage and then change to 0 to say that page is now junk.

On EVERY NOR flash I've used in the last 20 years, any '1' can be programmed down to a '0' but is it really true that for the Winbond W25Q series (and I quote the spec):

"The Page Program instruction allows from one byte to 256 bytes (a page) of data to be programmed at
previously erased (FFh) memory locations. "

which means that an arbitrary value can't be changed to a '0' and my whole design is stuffed (I was hoping to use 'spiffs' at some point which relies on this property of NOR flash).

I've tried it and it certainly appears to be the case that a byte MUST be 0xff to be programmed :(
Title: Re: Winbond SPI Flash library [SOLVED]
Post by: frackers on May 09, 2016, 03:33 am
On EVERY NOR flash I've used in the last 20 years, any '1' can be programmed down to a '0' but is it really true that for the Winbond W25Q series (and I quote the spec):
It appears that I misinterpreted how "SPIFlash::_notPrevWritten" is supposed to work - by putting the code into "HIGHSPEED" mode all my problems go away. Can't help thinking that this function is dangerous!!

Found another potential bug - if the address is 0x0000000 then _prepRead & _prepWrite return this value which just happens to be 'false' !!

Title: Re: Winbond SPI Flash library
Post by: Marzogh on Jun 04, 2016, 08:08 am
Just pushed through an update to v2.3.0. This one is for everyone who has been asking for ESP8266 compatibility! :)

- ESP8266 compatibility added
- Compatible with Arduino Fio and Micro
- Now compatible with Arduino IDE <= v1.6.9
- Compatible with Arduino-Makefile (https://github.com/sudar/Arduino-Makefile) (Thanks Raphael (https://github.com/rnestler)!)

As always, you can find this version on Github here --> SPIFlash Library for Arduino v2.3.0 (https://github.com/Marzogh/SPIFlash/releases/tag/v2.3.0)
A ZIP file is also attached to the first post on this thread. The easiest way, as always, is to open up Library Manager on your Arduino IDE and update the libary to v2.3.0 :)
Title: Re: Winbond SPI Flash library
Post by: kozlik-cze on Jun 17, 2016, 05:41 pm
Hello, I have slight trouble with W25Q64. When I using Arduino board switched to 3.3V everything is working well. But when I test this same type of memory on my own datalogger board the memory return inconsistent output as shown below. Board has main power supply rail 5V and second one 3.3V and for data there is also logic level converter (unipolar transistors). I also tried different frequency dividers to slow things down but nothing really helps.

Schematic was inspired by sparkfun bi-directional logic level converter. There are no other devices on SPI bus. Everything was tested for shorts and bad connections. Also on the schamatic there is no 0.1uF cap across VCC and GND, on the actual board there is one but with no difference when present.


Code: [Select]

Initialising Flash memory..........
----------------------------------------------------------------------------------------------------------------------------------
                                                           Get ID                                                                 
----------------------------------------------------------------------------------------------------------------------------------
                                                       Winbond W25Q64BV
----------------------------------------------------------------------------------------------------------------------------------
JEDEC ID: ef4017h
Manufacturer ID: efh
Memory Type: 16h
Capacity: 4017h
Maximum pages: 32768
----------------------------------------------------------------------------------------------------------------------------------
                                                          Write Data                                                             
----------------------------------------------------------------------------------------------------------------------------------
Data written without errors
----------------------------------------------------------------------------------------------------------------------------------
                                                          Data Check                                                             
----------------------------------------------------------------------------------------------------------------------------------
Data Written || Data Read || Result
----------------------------------------------------------------------------------------------------------------------------------
35 || 35 || Pass
-110 || -110 || Pass
4520 || 4520 || Pass
-1250 || -1250 || Pass
876532 || 876532 || Pass
-10959 || -10959 || Pass
3.1415 || 3.1415 || Pass
123 Test !@# || 123 Test !@# || Pass
inputStruct || outputStruct || Pass
0 - 255 || 0 - 255 || Pass
----------------------------------------------------------------------------------------------------------------------------------
                                                     Check Other Functions                                                       
----------------------------------------------------------------------------------------------------------------------------------
Function || Result
----------------------------------------------------------------------------------------------------------------------------------
powerDown || Error code: 0x04Pass
powerUp || Pass
sectorErase || Pass
chipErase ||

Initialising Flash memory..........
Error code: 0x04
Error code: 0x02



but sometimes when i try this test i have 5 times error and then normal output with errors.

Code: [Select]
Initialising Flash memory..........
Error code: 0x04
Error code: 0x02
Initialising Flash memory..........
Error code: 0x04
Error code: 0x02
Initialising Flash memory..........
Error code: 0x04
Error code: 0x02
Initialising Flash memory..........

----------------------------------------------------------------------------------------------------------------------------------
                                                           Get ID                                                                 
----------------------------------------------------------------------------------------------------------------------------------
                                                       Winbond W25Q64BV
----------------------------------------------------------------------------------------------------------------------------------
JEDEC ID: ef4017h
Manufacturer ID: efh
Memory Type: 16h
Capacity: 4017h
Maximum pages: 32768
----------------------------------------------------------------------------------------------------------------------------------
                                                          Write Data                                                             
----------------------------------------------------------------------------------------------------------------------------------
Data written without errors
----------------------------------------------------------------------------------------------------------------------------------
                                                          Data Check                                                             
----------------------------------------------------------------------------------------------------------------------------------
Data Written || Data Read || Result
----------------------------------------------------------------------------------------------------------------------------------
35 || 35 || Pass
-110 || -110 || Pass
4520 || 4520 || Pass
-1250 || -1250 || Pass
876532 || 876532 || Pass
-10959 || -10959 || Pass
3.1415 || 3.1415 || Pass
123 Test !@# || 123 Test !@# || Pass
inputStruct || outputStruct || Pass
0 - 255 || 0 - 255 || Pass
----------------------------------------------------------------------------------------------------------------------------------
                                                     Check Other Functions                                                       
----------------------------------------------------------------------------------------------------------------------------------
Function || Result
----------------------------------------------------------------------------------------------------------------------------------
powerDown || Error code: 0x04
Pass
powerUp || Pass
sectorErase || Pass
chipErase || Error code: 0x04
Fail
----------------------------------------------------------------------------------------------------------------------------------


For some reason it often tellign that there is 0x04 error, but I can't find the reason. Could it be a error like slow logic converter? Thank you for any advice! Michal
Title: Re: Winbond SPI Flash library
Post by: chucktodd on Jun 17, 2016, 09:58 pm
Hello, I have slight trouble with W25Q64. When I using Arduino board switched to 3.3V everything is working well. But when I test this same type of memory on my own datalogger board the memory return inconsistent output as shown below. Board has main power supply rail 5V and second one 3.3V and for data there is also logic level converter (unipolar transistors). I also tried different frequency dividers to slow things down but nothing really helps.

Schematic was inspired by sparkfun bi-directional logic level converter. There are no other devices on SPI bus. Everything was tested for shorts and bad connections. Also on the schamatic there is no 0.1uF cap across VCC and GND, on the actual board there is one but with no difference when present.


Code: [Select]

Initialising Flash memory..........
----------------------------------------------------------------------------------------------------------------------------------
                                                           Get ID                                                                
----------------------------------------------------------------------------------------------------------------------------------
                                                       Winbond W25Q64BV
----------------------------------------------------------------------------------------------------------------------------------
 JEDEC ID: ef4017h
 Manufacturer ID: efh
 Memory Type: 16h
 Capacity: 4017h
 Maximum pages: 32768
----------------------------------------------------------------------------------------------------------------------------------
                                                          Write Data                                                              
----------------------------------------------------------------------------------------------------------------------------------
 Data written without errors
----------------------------------------------------------------------------------------------------------------------------------
                                                          Data Check                                                              
----------------------------------------------------------------------------------------------------------------------------------
 Data Written || Data Read || Result
----------------------------------------------------------------------------------------------------------------------------------
 35 || 35 || Pass
 -110 || -110 || Pass
 4520 || 4520 || Pass
 -1250 || -1250 || Pass
 876532 || 876532 || Pass
 -10959 || -10959 || Pass
 3.1415 || 3.1415 || Pass
 123 Test !@# || 123 Test !@# || Pass
 inputStruct || outputStruct || Pass
 0 - 255 || 0 - 255 || Pass
----------------------------------------------------------------------------------------------------------------------------------
                                                     Check Other Functions                                                        
----------------------------------------------------------------------------------------------------------------------------------
 Function || Result
----------------------------------------------------------------------------------------------------------------------------------
 powerDown || Error code: 0x04Pass
 powerUp || Pass
 sectorErase || Pass
 chipErase ||

Initialising Flash memory..........
Error code: 0x04
Error code: 0x02



but sometimes when i try this test i have 5 times error and then normal output with errors.

Code: [Select]
Initialising Flash memory..........
Error code: 0x04
Error code: 0x02
Initialising Flash memory..........
Error code: 0x04
Error code: 0x02
Initialising Flash memory..........
Error code: 0x04
Error code: 0x02
Initialising Flash memory..........

----------------------------------------------------------------------------------------------------------------------------------
                                                           Get ID                                                                
----------------------------------------------------------------------------------------------------------------------------------
                                                       Winbond W25Q64BV
----------------------------------------------------------------------------------------------------------------------------------
 JEDEC ID: ef4017h
 Manufacturer ID: efh
 Memory Type: 16h
 Capacity: 4017h
 Maximum pages: 32768
----------------------------------------------------------------------------------------------------------------------------------
                                                          Write Data                                                              
----------------------------------------------------------------------------------------------------------------------------------
 Data written without errors
----------------------------------------------------------------------------------------------------------------------------------
                                                          Data Check                                                              
----------------------------------------------------------------------------------------------------------------------------------
 Data Written || Data Read || Result
----------------------------------------------------------------------------------------------------------------------------------
 35 || 35 || Pass
 -110 || -110 || Pass
 4520 || 4520 || Pass
 -1250 || -1250 || Pass
 876532 || 876532 || Pass
 -10959 || -10959 || Pass
 3.1415 || 3.1415 || Pass
 123 Test !@# || 123 Test !@# || Pass
 inputStruct || outputStruct || Pass
 0 - 255 || 0 - 255 || Pass
----------------------------------------------------------------------------------------------------------------------------------
                                                     Check Other Functions                                                        
----------------------------------------------------------------------------------------------------------------------------------
 Function || Result
----------------------------------------------------------------------------------------------------------------------------------
 powerDown || Error code: 0x04
Pass
 powerUp || Pass
 sectorErase || Pass
 chipErase || Error code: 0x04
Fail
----------------------------------------------------------------------------------------------------------------------------------


For some reason it often tellign that there is 0x04 error, but I can't find the reason. Could it be a error like slow logic converter? Thank you for any advice! Michal

More than likely, your N-Mosfet level converter using 10k pullups is too slow.

How fast are you running the SPI bus?
Depending on the capacitance of the bus, it may take too long for the voltage to rise from 0v to 5v.  This would cause transmission errors.

There are two things you can try:  
1.  Reduce the resistance to 1K.
2.  Reduce the speed of the SPI bus SPI.beginTransaction(SPISettings(100000L,MSBFIRST,SPI_MODE0));
 this would set the SPI bus to 100Kbits from the 4Mbits default.

Chuck.
Title: Re: Winbond SPI Flash library
Post by: kozlik-cze on Jun 18, 2016, 11:59 am
chucktodd Thank you for your answer! This is what I tought it can be, because when I measure logic transistor voltage on low side just with 1second pulse it took little too much time to settle the switched value, but I cannot tell exactly because I don't have an oscilloscope :( Unfortunately I can't find any 1k resistor net, bud I desolder 2 4.7k from other device to try it out. Same issue, so i have to try order 1k nets.

By the SPIlib library default, there was no actual divider, so I think the frequency was actual maximum 4MHz. But even if I try all available dividers to 2,4,8,...,128 nothing realy solve the issue, on some frequencies there was even stranger errors like 0x07, 0x06 etc..

I hope this is not circuit design issue, the winbond memory is placed like inch from MCU and on the way there is logic shifter. So i will order 1k nets and try it out again next week. Thank you, cheers :)

ADD: maybe this is good link for everyone who is solving same issue insane level shifter (http://electronics.stackexchange.com/questions/18457/is-my-mosfet-based-bidirectional-level-shifter-insane)
Title: Re: Winbond SPI Flash library
Post by: chucktodd on Jun 18, 2016, 10:36 pm
chucktodd Thank you for your answer! This is what I tought it can be, because when I measure logic transistor voltage on low side just with 1second pulse it took little too much time to settle the switched value, but I cannot tell exactly because I don't have an oscilloscope :( Unfortunately I can't find any 1k resistor net, bud I desolder 2 4.7k from other device to try it out. Same issue, so i have to try order 1k nets.

By the SPIlib library default, there was no actual divider, so I think the frequency was actual maximum 4MHz. But even if I try all available dividers to 2,4,8,...,128 nothing realy solve the issue, on some frequencies there was even stranger errors like 0x07, 0x06 etc..

I hope this is not circuit design issue, the winbond memory is placed like inch from MCU and on the way there is logic shifter. So i will order 1k nets and try it out again next week. Thank you, cheers :)

ADD: maybe this is good link for everyone who is solving same issue insane level shifter (http://electronics.stackexchange.com/questions/18457/is-my-mosfet-based-bidirectional-level-shifter-insane)
I use the Texas Instruments TXS104E as a SPI levelshifter. It's low side can go down to 1.65V and the High side up to 5.5V.  With the SPI bus's Push/Pull this translator is rated at 24Mhz, way above the possible Arduino Uno/Mega SPI frequencies.

The TXS104E is 4 bit, TXS108 is 8 bit.  The choice depending on how many 3.3V SPI devices you have.  You can also use these chips for I2C at reduced speed (2Mhz).  You can use the TXS108 for both you SPI bus and the I2C bus at the same time.

With shared usage, 2 bits for I2C, 6 bits for SPI,  you can have 3 SPI slaves.

Chuck.
Title: Re: Winbond SPI Flash library
Post by: miduchp on Jun 18, 2016, 11:27 pm
Dear Marzogh,

First of all, many thanks for this great library. I have started to work with your library using ATMega1284p and Winbond 25Q40BVNIG.
I works fine except one strange problem. If I understand everything correctly, proper addresses starts at 0, which means I can execute code below and flash.readByte(0) should return value 17.

Code: [Select]

flash.begin();
flash.eraseBlock32K(0);
flash.writeByte(0, 17);
flash.readByte(0); //returns 0, why ?


Unfortunately my tests shows that everything is working starting from address 1. Writes for address 0 are ok, but further reads returns 0. Do you have any idea what might be the reason behind this ?

Regards,
Piotr
 
Title: Re: Winbond SPI Flash library
Post by: Marzogh on Jun 19, 2016, 02:05 pm
It works fine except one strange problem. If I understand everything correctly, proper addresses starts at 0, which means I can execute code below and flash.readByte(0) should return value 17.

Unfortunately my tests shows that everything is working starting from address 1. Writes for address 0 are ok, but further reads returns 0. Do you have any idea what might be the reason behind this ?
Uh oh! ::) That shouldn't be happening. I'll take a look at it and sort it out asap and let you know when I've fixed it. Thanks for bringing this to my attention.

I'm glad you find the library useful!

Cheers,

Prajwal
Title: Re: Winbond SPI Flash library
Post by: Marzogh on Jul 01, 2016, 12:29 pm
Hi Piotr,

The Address 0x00 bug's been squashed. However, it is a part of the changes a release that isn't completely ready yet - even though its fully functional for now. Feel free to download the v2.4.0-w.i.p (https://github.com/Marzogh/SPIFlash/tree/v2.4.0-w.i.p) branch for now - it should work for all intents and purposes. Just remember tis is still a work-in-progress, so, things might not be as polished as in a final release.

Cheers,

Prajwal
Title: Re: Winbond SPI Flash library - Can't Read Address 0
Post by: tozz88 on Aug 03, 2016, 10:57 pm
Hi,

This is a great implementation. Thanks for all the work. i am using it to access a w25q32dw and it is
working fine. The issue I run into is when I try to read address 0x00000000. because of the way
_prepRead() is coded it returns false if the address is bad or "address" if it is okay. Therefore if you
pass in address 0x00000000 it returns 0 (false) and the read operation fails.

I can't believe this hasn't come up before so I am assuming I am missing something? The fix is easy
since no routines currently take advantage of the returned address so simply having _prepRead() return
true instead of address seems to do the trick.

Please let me know and thanks again for this great library.

Title: Re: Winbond SPI Flash library
Post by: Marzogh on Aug 19, 2016, 07:26 am
The issue I run into is when I try to read address 0x00000000. because of the way
_prepRead() is coded it returns false if the address is bad or "address" if it is okay. Therefore if you
pass in address 0x00000000 it returns 0 (false) and the read operation fails.
Hi mate,

I'm glad you find the library useful. :) I'm afraid the bug's a part of the v2.3.0-w.i.p (https://github.com/Marzogh/SPIFlash/tree/v2.3.0-w.i.p) release - it has been fixed in the v2.4.0-w.i.p (https://github.com/Marzogh/SPIFlash/tree/v2.4.0-w.i.p) release that's available on Github. Please use that and you won't have this problem anymore. I will make some time over the next couple of weekends to clean & polish up v2.4.0 and push it through as a proper release.

Cheers!

Praj
Title: Re: Winbond SPI Flash library
Post by: Marzogh on Sep 10, 2016, 06:45 pm
Just pushed through an update to v2.4.0. This one has had a bunch of bugs squashed and another bunch of optimizations performed on it

Bugs Squashed
- Fixed bug preventing writing to Address 0x00
- Fixed bug in _notPrevWritten() which did not perform a thorough enough check to see if a location had been previously written to.
- Fixed errorchecking bug - it now works for all data types - not just byte/char as in 2.3.0 & 2.3.1.

Enhancements & Optimizations
- Added a function 'error()' to enable users to check for errors generated at any point in their program.
- Optimized writePage() so it doesn't depend on other functions and so runs faster than before.
- Diagnostics.ino now outputs time taken for each function as a part of its and provides additional diagnostic data.
- Now have a common set of private functions - _prep(), _beginSPI(), _nextByte() & _endSPI() - to replace _prepWrite(), _prepRead(), _beginRead(), _readNextByte(), _beginWrite(), _writeNextByte() & _endProcess();
- Changed the way _addressCheck() works. It now checks all addresses involved in writing the data rather than one address block at a time and returns the correct address to write to in case overflow is enabled. Also, this function is now built into _prep().
- Reading and writing using page numbers + offset has been optimised to be faster than before.
- Optimized the way address and error checking is done so its more efficient and uses fewer system resources and runs faster.
- Using this library with an ESP8266 board defaults to using GPIO15 as the Slave Select - unless something different is explicitly specified in the constructor.

As always, you can find this version on Github here --> SPIFlash Library for Arduino v2.4.0 (https://github.com/Marzogh/SPIFlash/releases/tag/v2.4.0)
A ZIP file is also attached to the first post on this thread. The easiest way, as always, is to open up Library Manager on your Arduino IDE and update the libary to v2.4.0 :)
Title: Re: Winbond SPI Flash library
Post by: Gary_chien on Sep 14, 2016, 01:12 pm
Hi,
I have tried your library (V2.3) for reading data on my Due board.
That's really friendly to use with my W25Q16.

Because of mass data needed to be read, readByteArray function is what I use.
About 95ms for reading 60,000 byte data, which is the fastest condition for me so far.
But it still too slow to use for data reading in my project (image plotting).

The frequency measure by scope in SPI SCK pin is only 330KHz in my the test condition.
Is it correct for getting this number, which is much less Due' working frequency? 
I have set SPI devider to 2 (in SPIFlash.cpp, line 704) to get better performance.

Is there any way to speed up for reading data with your library?

Any suggestion is appreciated.
Title: Re: Winbond SPI Flash library
Post by: Marzogh on Sep 16, 2016, 08:31 pm
Hi Gary,

I'm glad you're finding the library useful. Try out the pre-release [SPI-Transactions-w.i.p (https://github.com/Marzogh/SPIFlash/tree/SPI-Transactions-w.i.p)] branch. I've been getting consistent clock speeds of 44MHz with the Due, using the code committed to this branch as of today. That should - on paper at least - bring down the read time for 60kb of data to ~10.90 ms. :)

Hope that helps!

Cheers,

Praj

P.S. Don't worry about SPI_DIV2 any more. This branch has SPI Transactions support and will run as fast as the MCU allows it to. :)
Title: Re: Winbond SPI Flash library
Post by: Gary_chien on Sep 19, 2016, 03:33 am
Hi Marzogh,
Thanks for your rapid reply and new library.
After trying [SPI-Transactions-w.i.p] you provided, the processing time increase to 132 ms in my test sketch :o
I just replace your library (V2.3) with the new one(w.i.p) without other modification.
Is there anything I should do to use it correctly?

BRs
Title: Re: Winbond SPI Flash library
Post by: Gary_chien on Sep 20, 2016, 04:18 am
Both of the SCK frequency in SPI are about 42MHz measured by scope.
But the interval between two"readByteArray" command is slightly longer in [SPI-Transactions-w.i.p] library.
That should be the reason why it takes more processing time for running my test sketch.
Is it possible to shorten that duration?
Code: [Select]

void loop()
{
  StartTime = millis();

  DrawImage(0);

  EndTime = millis();
  Duration = EndTime - StartTime;
  myGLCD.setColor(0, 0, 0);
  myGLCD.setBackColor(255, 255, 255);
  myGLCD.printNumI(Duration, 130, 110);
  //delay(5000);
}
void DrawImage(int header)
{
  uint8_t bufrow[60000];
  flashread.readByteArray(16 + header, bufrow, 60000);
  //flashread.readByteArray(16 + header, bufrow, 60000);
 }
Title: Re: Winbond SPI Flash library
Post by: Marzogh on Sep 20, 2016, 11:24 am
Ah. That must be all the address checking that happens at the beginning of readByteArray().

Try replacing the function in your library (Just Variant A) with this:

Code: [Select]
bool  SPIFlash::readByteArray(uint32_t address, uint8_t *data_buffer, uint16_t bufferSize, bool fastRead) {
  if(!fastRead) {
    if (!_prep(READDATA, address, bufferSize)) {
    return false;
}
  }
    _beginSPI(READDATA);
 
  for (uint16_t a = 0; a < bufferSize; a++) {
    data_buffer[a] = _nextByte(READDATA);
  }
  _endSPI();
return true;
}


So when you call readByteArray() in your code, the first time, say this instead

Something along the lines of:
Code: [Select]

bool repeat = 0;

...

void setup() {
...
}

void loop()
{
  StartTime = millis();

  DrawImage(0, repeat);

  EndTime = millis();
  Duration = EndTime - StartTime;
  myGLCD.setColor(0, 0, 0);
  myGLCD.setBackColor(255, 255, 255);
  myGLCD.printNumI(Duration, 130, 110);
  repeat = 1;
  //delay(5000);
}
void DrawImage(int header, bool repeat)
{
  uint8_t bufrow[60000];
  flashread.readByteArray(16 + header, bufrow, 60000, repeat);
  //flashread.readByteArray(16 + header, bufrow, 60000);
 }
Title: Re: Winbond SPI Flash library
Post by: Gary_chien on Sep 20, 2016, 01:51 pm
Thanks Marzogh,
These modification make the same result of processing time (95 ms) as in Library V2.3. :)
Do you mean the first time for calling readByteArray should with normal read(repeat=0).
Then the following calls with fastRead(repeat=1), something like this?
 
Code: [Select]


bool repeat = 0;

...

void setup() {
...
}

void loop()
{
  StartTime = millis();

  DrawImage(0, repeat);

  EndTime = millis();
  Duration = EndTime - StartTime;
  myGLCD.setColor(0, 0, 0);
  myGLCD.setBackColor(255, 255, 255);
  myGLCD.printNumI(Duration, 130, 110);
  repeat=1
}
void DrawImage(int header, bool repeat)
{
  uint8_t bufrow[60000];
  flashread.readByteArray(16 + header, bufrow, 60000, repeat);
 }

But I still found no improvement in processing time, am I using it correctly?
Title: Re: Winbond SPI Flash library
Post by: Gary_chien on Sep 20, 2016, 02:05 pm
Well, a stupid mistake.
I replaced the wrong library....
Actually the result of processing time is 116 ms after modifying from w.i.p library.
And the original result is 95 ms in V2.3 library.
But still no improvement in changing repeat to 1.  :smiley-confuse:
Title: Re: Winbond SPI Flash library
Post by: Marzogh on Sep 22, 2016, 06:35 am
Hmmm... I suspect that has something to do with how SPI transactions are handled in the SPI library (or not - I'm just guessing here.). I'm currently in the middle of no where on a field trip (and still have the internet! Hurrah for the 21st century!) and will be back by the end of the week. I'll see if I can do a custom high speed function for you :)
Title: Re: Winbond SPI Flash library
Post by: Marzogh on Sep 23, 2016, 08:23 pm
Here we go :)

The current version of the SPI-Transactions-w.i.p (https://github.com/Marzogh/SPIFlash/commit/e12248ce62c6e03461e14ee8f45f2835156b7d0d) branch is consistently giving me a 40-44MHz clock frequency and I'm able to get the code below to write 60000kb of data to the flash chip and read it back in under 32ms. Each read takes a little under 1.5ms and two consecutive reads take ~12ms.

This high speed mode is courtesy some DMA magic with SPI on the Arduino Due - borrowed gratefully from manitou48 (https://github.com/manitou48/DUEZoo/blob/master/dmaspi.ino). The SPI-Transactions-w.i.p branch currently only supports the DMA mode in the Due and this can be activated by uncommenting the #define DUE_DMA_MODE in SPIFlash.cpp.

The DUE_SPI_CLK definition in defines.h controls the clock speed of the Due. Running the board on a clock divisor of 1 resulted in a lot of instability. a clock divisor of 2 appears to be stable - but I haven't been very exacting in testing this. If stability issues occur, just up the divisor to 3 or 4 and you should be fine :)

Code used for testing the current version of the SPI-Transactions-w.i.p (https://github.com/Marzogh/SPIFlash/commit/e12248ce62c6e03461e14ee8f45f2835156b7d0d) branch:
Code: [Select]
#include<SPIFlash.h>

uint8_t _array[256];

SPIFlash flash;

void fillArray() {
  for (int i = 0; i < 256; ++i) {
    _array[i] = i;
  }
}

void writeImage(int header) {
  for (uint8_t i = 0; i < 235; i++) {
    flash.writeByteArray(header, _array, 256);
  }

}
void readImage(int header) {
  uint8_t bufrow[60000];
  flash.readByteArray(16 + header, bufrow, 60000);
  flash.readByteArray(16 + header, bufrow, 60000, TRUE);
}

void setup() {
  fillArray();
  flash.begin();
  flash.eraseChip();
  writeImage(0);
  readImage(0);
}

void loop() {
  // put your main code here, to run repeatedly:

}
Title: Re: Winbond SPI Flash library
Post by: Gary_chien on Sep 26, 2016, 03:58 am
After trying the DMA version, the processing time is just 11ms in my test sketch, about 9 times faster than before.
With your library, showing image(320 x 480 pixels) from external flash memory is about 400ms,
which is almost the same as showing from Due's internal memory (390ms).
And there is a significant improvement when comparing to normal SPI (800ms).
That really helps for high speed images display with my LCD module.
Thanks a lot, Marzogh. :)
Title: Re: Winbond SPI Flash library
Post by: Marzogh on Sep 26, 2016, 06:29 am
Cheers mate. Glad it worked. :)

I'll roll the DMA SPI update into the next release and make it the default method of SPI access on the Due. I'm just trying to make the library Arduino Zero compatible before releasing a new version.

P.S. For anyone trying to get high speed DMA SPI going on their UNOs, I'm afraid the library will only support DMA on the Due. (For now)
Title: Re: Winbond SPI Flash library
Post by: Gary_chien on Sep 29, 2016, 01:32 pm
Hi,
Beside the memory, there is another IC need to be connected to DUE with SPI interface in my project.
But I found a conflict in using DMA library and general SPI communication.
It doesn't happen in V2.3 SPIFlash library however.
A part of my sketch is as below, and my IC_V only works in the 1st loop.
Anything I need to do when switching in DMA and general SPI ?
 
Code: [Select]

#include<SPI.h>

#include<SPIFlash.h>

const int cs_flash = 52;//////Flash memory
const int cs_v = 10;///////IC_V

SPIFlash flashread(cs_flash);

void setup() {
  //////////setting SPI for CS_V/////////////
  SPI.begin(cs_v);
  SPI.setBitOrder(cs_v, MSBFIRST);
  SPI.setDataMode(cs_v, SPI_MODE0);
  SPI.setClockDivider(cs_v, 255);
       
  flashread.begin();//DMA begin
  delay(200);
}

void loop()
{
  DrawImage(0);

  delay(3000);

  SPI.transfer16(cs_v, 0x9800);//Giving command to IC_V
  delay(5000);


}
void DrawImage(int header)
{
  uint8_t bufrow[60000];
  flashread.readByteArray(16 + header, bufrow, 60000);

}
Title: Re: Winbond SPI Flash library
Post by: Marzogh on Sep 30, 2016, 06:09 am
Hi Gary,

A couple of points to note:

A. flashread.readByteArray() makes an SPI.begin() call and an SPI.beginTransaction() call and that's probably overwriting your SPI Bus settings for IC_V that you make in void setup().

which brings me to,

B. The extended SPI methods for the Due have been deprecated [details (https://www.arduino.cc/en/Reference/DueExtendedSPI)] Have you tried implementing your comms with the other IC through transactions? I'd try replacing the current code with something like this:
Code: [Select]

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

const uint8_t cs_flash = 52;
const uint8_t cs_v = 10;

#define v_SPI_CLK    4000000 //Change this to whatever the maximum speed of IC_V is
SPISettings v_settings;

SPIFlash flashread(cs_flash);

void v_SPIbegin(uint8_t chipSelect) {
  pinMode(chipSelect, OUTPUT);
  digitalWrite(chipSelect, HIGH);
}

void DrawImage(int header) {
  uint8_t bufrow[60000];
  flashread.readByteArray(16 + header, bufrow, 60000);

}

void transferToIC(void) {
  SPI.beginTransaction(IC_V_settings);
  SPI.transfer16(0x9800);
  SPI.endTransaction();
}

void setup() {
  flashread.begin();
  v_SPIbegin(cs_v);
  v_settings = (v_SPI_CLK, MSBFIRST, SPI_MODE0)
}

void loop() {
  DrawImage(0);
  delay(3000);

  transferToIC();
  delay(5000);
}


Also, could you use this with the latest comit to the library SPI-Transactions-w.i.p (https://github.com/Marzogh/SPIFlash/tree/04b6afd502a40494d6251b2d2546c6d50809625b) branch please? Its got a few more things moved around to make life easier to use multiple slaves on the SPI bus and its got an SPI Transactions related bug fixed from the version you have been using.

P.S. The reason why v2.3 works is probably because I had put no fail-safes in place to prevent interruptions to SPI bus and you are able to communicate with two SPI slaves without any signalling errors. If one of your SPI slaves' comms relied on generating an interrupt, it is likely it would have disrupted comms with the other slave if you used v2.3. v2.4.0 was more of a stepping stone towards full SPI Transactions support (in v2.5.0) that will hopefully fix this problem before it happens and so has some SPI bus access protection built in.
Title: Re: Winbond SPI Flash library
Post by: Gary_chien on Oct 03, 2016, 06:25 am
The reason why I use in Extended SPI library is that the SPI transaction and SPISettings don't work on me.(Have tried on IDE 1.6.8 and IDE 1.6.13 Hourly Build)
There are no CS and Clock signals captured by scope.
Code: [Select]

#include<SPI.h>
const uint8_t cs_v=10;

void v_SPIbegin(uint8_t chipSelect) {
  pinMode(chipSelect, OUTPUT);
  digitalWrite(chipSelect, HIGH);
}
void transferToIC(void) {
  SPI.beginTransaction(SPISettings(4000000,MSBFIRST, SPI_MODE0));
  SPI.transfer16(0x9800);
  SPI.endTransaction();
}
void setup()
{
  v_SPIbegin(cs_v);
}

void loop()
{
  delay(3000);
  transferToIC();
}


So I just tried your plan.B but with Extended SPI below, still no function in IC_V.
I think you are right, the DMA setting overwrites my general SPI setting.
 
Code: [Select]

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

#define cs_flash = 52;
#define cs_v = 10;


SPIFlash flashread(cs_flash);


void DrawImage(int header)
{
  uint8_t bufrow[60000];
  flashread.readByteArray(16 + header, bufrow, 60000);

}

void transferToIC(void) {
  delay(5);
  SPI.begin(cs_v );
  SPI.setBitOrder(MSBFIRST);
  SPI.setDataMode(cs_v , SPI_MODE0);
  SPI.setClockDivider(cs_v , 255);       // Due: (pin,divider: 1 to 255)
}

void setup() {
  flashread.begin();
  v_SPIbegin(cs_v);
}

void loop() {
  DrawImage(0);
  delay(3000);

  transferToIC();
  delay(5000);
}
Title: Re: Winbond SPI Flash library
Post by: Marzogh on Oct 04, 2016, 06:27 am
The reason why I use in Extended SPI library is that the SPI transaction and SPISettings don't work on me.(Have tried on IDE 1.6.8 and IDE 1.6.13 Hourly Build)
There are no CS and Clock signals captured by scope.
Code: [Select]

#include<SPI.h>
const uint8_t cs_v=10;

void v_SPIbegin(uint8_t chipSelect) {
  pinMode(chipSelect, OUTPUT);
  digitalWrite(chipSelect, HIGH);
}
void transferToIC(void) {
  SPI.beginTransaction(SPISettings(4000000,MSBFIRST, SPI_MODE0));
  SPI.transfer16(0x9800);
  SPI.endTransaction();
}
void setup()
{
  v_SPIbegin(cs_v);
}

void loop()
{
  delay(3000);
  transferToIC();
}
Try replacing your code above with this:

Code: [Select]


#include<SPI.h>
const uint8_t cs_v=10;

void v_SPIbegin(uint8_t chipSelect) {
  pinMode(chipSelect, OUTPUT);
  digitalWrite(chipSelect, HIGH);
  SPI.begin();
}
void transferToIC(void) {
  SPI.beginTransaction(SPISettings(4000000,MSBFIRST, SPI_MODE0));
  SPI.transfer16(0x9800);
  SPI.endTransaction();
}
void setup()
{
  v_SPIbegin(cs_v);
}

void loop()
{
  delay(3000);
  transferToIC();
}


SPI.beginTransaction(...) just initiates the SPI comms with the slave. You still need to initialize the SPI bus before you call SPI.beginTransaction() - so, I've just added the SPI.begin() to your void v_SPIbegin(uint8_t chipSelect) function.

This trips up a lot of people, from what I can see. I thought SPI Transactions didn't work for me too - till I discovered that I needed to still call SPI.begin() first. Once the bus is initialised, you can talk to multiple devices as show in the pseudocode below:

Code: [Select]

...

SPI.begin(); //Initialise the SPI bus

SPI.beginTransaction(_settings1);//Start comms with first SPI slave
...
//Comms with SPI slave 1
...
SPI.endTransaction(); //End comms with the first SPI slave

SPI.beginTransaction(_settings2);//Start comms with second SPI slave
...
//Comms with SPI slave 2
...
SPI.endTransaction(); //End comms with the second SPI slave

...
...
//and so on...


You don't need to call SPI.begin() if you call flashread.begin() because the library initialises the SPI bus. Also, the library calls SPI.endTransaction() at the end of every function so you are free to start up comms with another SPI slave. Just remember to call SPI.endTransaction() after you are done and before you call another SPIFlash function. :)
Title: Re: Winbond SPI Flash library
Post by: Gary_chien on Oct 05, 2016, 01:32 pm
Well....
That additional "SPI.begin()" do really help me.
Now with your DMA and SPI transaction, I can reach high speed reading from flash memory and do normal SPI communication with other IC.
Everything now works fine, thanks a lot, Marzogh :)   
Title: Re: Winbond SPI Flash library
Post by: Marzogh on Oct 07, 2016, 02:09 pm
Fantastic! Glad I could help :)
Title: Re: Winbond SPI Flash library
Post by: Marzogh on Nov 13, 2016, 04:26 pm
Just pushed through an update to v2.5.0. This update squashes a couple of major bugs, adds support for SPI Transactions, works some DMA magic on the Arduino Due, loses a couple of unnecessary functions and has a number of optimizations for speed and stability.

Bugs Squashed
- Errorchecking on writeByteArray() and writeCharArray() was broken in 2.4.0 and is fixed now.
- Previous versions (< 2.5.0) suffered from the inability to write datasets that spanned page boundaries. This has now been fixed (Ref. Enhancements section below)

Deletions
- flash.writePage() & flash.readPage() have been retired as they can be duplicated - more effectively - by other functions. Refer to pageDiag() in Diagnostics.ino to see how the same results can be obtained by using flash.writeByteArray() & flash.readByteArray().

Enhancements & Optimizations
- Added support for SPI Transactions.
- Added an upgrade for Arduino Due users to read and write large arrays of data at very high speeds - previously reading 60kb of data would take ~108ms - it now takes ~525uS. In this mode, the time between consecutive reads has been reduced to <12ms (needs more work!).
- Completely re-written writeByteArray() and writeCharArray() functions. They no longer breakdown when writing arrays that span multiple pages.
- All functions that write more than 1 byte of data now take into account page boundaries when writing across pages. In previous versions writing across a page boundary would cause the remainder of the data to wrap around to the beginning of the page. Now the data is written seamlessly from one page over to the next.
- Calling flash.begin() now instantiates the SPI bus. Comms with other SPI slaves do not need to call SPI.begin() if flash.begin() has already been called first in the user's code.
- Sped up _beginSPI(). Code in _beginSPI() instantiates the SPI bus if another SPI comms library has shut it down.
- Added function allowing setting SPI clock speeds - call the function ```flash.setClock(uint32_t clockSpeed);``` straight after ```begin();```.
- Made _beginSPI() & _nextByte() shorter and faster.
- Replaced all calls to SPI.transfer() with xfer() to make the code more human readable and to enable simplicity when switching platforms.
- Added the ability to change Chip Erase wait times depending on the chip (supported chips only).
- Don't need to ```#include <SPI.h>``` in user code anymore. Just ```#include<SPIFlash.h>``` will do. Examples are now updated.
- Now supports & uses SPI.transfer(*buf, count) along with the standard SPI.transfer(), speeding up the read/write of anything larger than an byte (AVR Boards only)
- Reduces the program storage space in the uC's flash (AVR Boards)

As always, you can find this version on Github here --> SPIFlash Library for Arduino v2.5.0 (https://github.com/Marzogh/SPIFlash/releases/tag/v2.5.0)
A ZIP file is also attached to the first post on this thread. The easiest way, as always, is to open up Library Manager on your Arduino IDE and update the libary to v2.5.0 :)
Title: Re: Winbond SPI Flash library
Post by: Stephan_uino on Nov 13, 2016, 05:09 pm
Excellent job and Thanks!
Title: Re: Winbond SPI Flash library
Post by: wsteelmanj on Nov 16, 2016, 08:14 pm
I'm having a slight problem getting my chip to work. I have an Arduino Nano ATMega328p board and an SPI chip (W25Q256FV) wired to the board according to this schematic posted by Okio

(http://mylcd.sourceforge.net/tmp/25Q128FVSG.png)

Since my board runs on 5V I have several voltage dividers for the pins. Anyways when I run the SPI TestFlash.ino or Diangostics.ino it just says "Initialising Flash memory.........." and never gets past the flash.begin(). Thanks!

(Also Marzogh, thanks for all your work in building this library!)
Title: Re: Winbond SPI Flash library
Post by: CrossRoads on Nov 16, 2016, 08:34 pm
Post your code please. Use the code tag button </>, or Reply and Attach it (selected under the Reply box) if the code exceeds the forum character limit.
Title: Re: Winbond SPI Flash library
Post by: Marzogh on Nov 16, 2016, 11:46 pm
Hi wsteelmanj,

That's unfortunate. Which version of the library are you using? Also, could you uncomment the #define RUNDIAGNOSTIC in SPIFlash.cpp and find the _chipID(void) function in SPIFlash.cpp and uncomment the Serial.print lines as shown below.

Code: [Select]
bool SPIFlash::_chipID(void) {
//Get Manfucturer/Device ID so the library can identify the chip
    uint8_t manID, capID, devID ;
    //_getManId(&manID, &devID);
    _getJedecId(&manID, &capID, &devID);

    Serial.println(manID, HEX);
    Serial.println(capID, HEX);
    Serial.println(devID, HEX);

    if (manID != WINBOND_MANID && manID != MICROCHIP_MANID){ //If the chip is not a Winbond Chip
      errorcode = UNKNOWNCHIP; //Error code for unidentified chip
    #ifdef RUNDIAGNOSTIC
    _troubleshoot();
    #endif
    while(1);
    }


Save the modified file, re-compile and upload Diagnostics.ino and could you then post the Serial output here?
Title: Re: Winbond SPI Flash library
Post by: wsteelmanj on Nov 17, 2016, 02:24 am
I'm using SPIFlash-2.4.0 (Sorry I meant to put that in my first post..)

and here's the output after changing the edited serial lines:

Code: [Select]
Initialising Flash memory..........
0
0
0
Error code: 0x02


Thanks!
Title: Re: Winbond SPI Flash library
Post by: Marzogh on Nov 17, 2016, 07:10 am
Well, the chip isn't responding at all. The three zeros should be - in your case - 0xEF, 0x40, 0x19 respectively. Which is what the chip should return to the library when flash.begin() runs. This is why the Error code 0x02 - meaning 'Unknown Chip' - is returned.

Could you check your wiring please? And post a couple of photos of how it is wired up? I suspect it might be a dud chip, but no harm in checking the wiring  :) (Something similar happened to Stephan_Duino here --> link (http://forum.arduino.cc/index.php?topic=324009.15) and it turned out to be a bad chip.)
Title: Re: Winbond SPI Flash library
Post by: wsteelmanj on Nov 18, 2016, 04:42 am
I checked the wiring and tried it again with a new chip and it still didn't work.

Here are the wiring pics. You can ignore all the wires on the left (they're for several encoders and a LCD). Also I'm using a surface mounted SPI chip so the chip is on an adapter. The top row of the adapter pins are pins 8 to 5 (left to right) from the SPI chip and the bottom row is pins 1 to 4.

(http://i.imgur.com/RF7d37s.jpg)

(http://i.imgur.com/ltoVPbq.jpg)

Sorry I know it's a sloppy board. I will also attach the excel file I used to plan it out before soldering which will hopefully help you find my error. I already tested all the voltage dividers with a simple program that set the data pins at 5V and they were outputting 2.8V which is sufficient for the SPI chip. Thanks!
Title: Re: Winbond SPI Flash library
Post by: Marzogh on Nov 18, 2016, 11:40 pm
Ah. Good old voltage dividers. They can cause some serious performance issues.

All signals have capacitance, partly from the IC pins and partly from the wires/PCB traces connecting the devices. When you throw a resistor into the mix, you are creating an RC filter which smooths out the sharp edges in your signals - especially hurting the clock pulse.

Now, this is usually ok if the resistance is small enough. I have, in a pinch, thrown in a <150 Ohm total resistance to create a voltage divider. Anything higher than that degrades the signal quality too much. Also, voltage divider resultant signal degradation will not affect your MISO, MOSI and CS lines as much as the CLK line. Any clock pulse needs a clean sharp digital transition between low and high. I'd recommend throwing in a Voltage Level converter from Sparkfun or Adafruit. They're cheap and high quality - I've never had issues with them degrading SPI signals.
Title: Re: Winbond SPI Flash library
Post by: wsteelmanj on Nov 19, 2016, 10:57 pm
So if I use a smaller resistance for my clock voltage divider it should work? Or do I need to reduce the resistances for the other pins as well? I'll try reducing the clock resistance first and let you know how it goes! Thanks!
Title: Re: Winbond SPI Flash library
Post by: Marzogh on Nov 19, 2016, 11:04 pm
It might work. For clock signals I'd personally recommend against voltage dividers and recommend the use of a proper level shifting set up. However, if you've got an oscilloscope, you should be able to see the high to low transitions clearly and that should help with picking the right resistors to use.
Title: Re: Winbond SPI Flash library
Post by: Marzogh on Nov 22, 2016, 03:39 am
For those of you that have managed to get your hands on ESP32 dev boards, I've got v2.6.0-w.i.p (https://github.com/Marzogh/SPIFlash/tree/v2.6.0-w.i.p) currently working with the ESP32 core (as it stands at commit 67fd652 (https://github.com/espressif/arduino-esp32/tree/67fd6521777a16e406639a0eb0d113bf2e896f97)). :D

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 (I'm testing with the Sparkfun ESP32 Thing - it has a max speed of 80MHz) - if you have any issues, check your board's speed first and change the SPICLK define in defines.h to your (board clock speed)/4.
Title: Re: Winbond SPI Flash library
Post by: wsteelmanj on Nov 30, 2016, 09:48 pm
So I finally got back in the lab after thanksgiving to check out the clock pulse on an o-scope and there is nothing coming off of pin 13 (SCK)... Do I have to add some code to output the clock pulse on this pin or is my arduino just dead or something?

Also I got an 8MHz signal on pin 9 using the instructions from here:
http://arduino.stackexchange.com/questions/16698/arduino-constant-clock-output

If I can't get pin 13 working can I just put my voltage divider on pin 9 and use it to drive the chip? Thanks!
Title: Re: Winbond SPI Flash library
Post by: CrossRoads on Nov 30, 2016, 10:12 pm
SCK would only be active for 8 clocks during an SPI.transfer().
Not continuously.
Title: Re: Winbond SPI Flash library
Post by: Marzogh on Dec 01, 2016, 02:23 am
The SCK pulse is started/ended by the library as needed, during an SPI transaction. I'd recommend that you try connecting another SPI based sensor (a 3.3V one, to be specific) to your board and see if it works. That should tell you if you have a busted chip.

Also as CrossRoads said, an SCK does not constantly pulse at 8MHz. This is what a typical SPI signal would look like --> SPI Signal on Logic Analyzer (http://gammon.com.au/images/SPI_logical_analyzer_1.png) (Image linked directly from Nick Gammon's post on SPI (http://gammon.com.au/spi))

I've tested a similar setup with my Arduino Nano & a Winbond W25Q128FV (I don't have a W25Q256FV, but the difference is only the amount of storage) and it works fine with v 2.5.0 - however, I always use a logic level converter in situations like this - this one (https://www.sparkfun.com/products/12009) to be precise
Title: Re: Winbond SPI Flash library
Post by: Marzogh on Apr 16, 2017, 07:06 pm
Just pushed through an update to v2.6.0. This update squashes one major bug, adds support forthe ESP32 and other boards, loses a superfluous function and has a large number of optimizations for speed, stability & ease of development.

Bugs Squashed
- Fixed issue with reading status register 2 and the Suspend operation where the library was not checking the suspend status correctly.

Deletions
- flash.getChipName() has been removed as it is superfluous now that the library is now on its way to multi-chip compatibility.
- The library is not compatible with the ATTiny85 anymore. Currently working on a fix which will hopefully be rolled out in v2.7.0

New Boards supported
- RTL8195A compatibility tested and enabled by @boseji (http://salearj@hotmail.com) on 02.03.17. Code modified to fit with the library structure by Prajwal Bhattaram on 14.04.17.
- Now supports the ESP32 core for Arduino as of the current commit 7d0968c (https://github.com/espressif/arduino-esp32/tree/7d0968c10dc540709d69a28eab2457075c1e4fa8) on 16.04.2017. The ESP32 core currently does not support analogRead and so 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.
- Added support for the Simblee module.

Enhancements & Optimizations
- 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 calling
Code: [Select]

if (!flash.begin()) {
      Serial.println(flash.error(VERBOSE));
}

 to identify a problem as soon as the library code is run.
- The internal _addressCheck() function now locks up usercode with appropriate error codes if

- Fixed powerDown() to be more efficient. The chip now powers down much faster than before.
- Added a new error code. Library can now detect non-responsive chips - bad wiring or otherwise.
- Streamlined variables to make code structure better.
- Changed library structure to enable the addition of multi-flash compatibility in the near future.
- moved `#define RUNDIAGNOSTIC` & `#define HIGHSPEED` to SPIFlash.h from SPIFlash.cpp.
- Now works with other Winbond modules (not in the official supported module list) (beta) by taking the flash memory size in bits as an argument in `flash.begin(_chipSize);`
- Formatted code to be better human readable.
- Changed the internal `_troubleshoot()` function to use fewer resources.

As always, you can find this version on Github here --> SPIFlash Library for Arduino v2.6.0 (https://github.com/Marzogh/SPIFlash/releases/tag/v2.6.0)
A ZIP file is also attached to the first post on this thread. The easiest way, as always, is to open up Library Manager on your Arduino IDE and update the libary to v2.6.0 :)
Title: Re: Winbond SPI Flash library
Post by: miduchp on Jul 15, 2017, 07:07 pm
Hi Marzogh

I've recenetly got back to your SPI Library. I've been using it previously on version 2.3.1 with chip Winbond 25q40bvnig.

After update to version 2.6.0 it throws random errors on diagnostics. Errors are showing up since version 2.4.0

It looks like this:


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


--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
                                                                   SPIFlash Library version: 2.6.0
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
                                                                               Get ID
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
JEDEC ID: ef4013h
Manufacturer ID: efh
Memory Type: 40h
Capacity: 524288 bytes
Maximum pages: 2048
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
                                                                              Data Check
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Data Written || Data Read || Result || Write Time || Read Time || Write Time || Fast Read Time
|| || || || || (No Error Chk) ||
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
35 || 35 || Pass || 52 us || 48 us || 52 us || 64 us
-110 || -110 || Pass || 52 us || 48 us || 52 us || 48 us
4520 || 4520 || Pass || 64 us || 60 us || 64 us || 56 us
-1250 || -1250 || Pass || 64 us || 56 us || 64 us || 56 us
876532 || 4294967075 || Fail || 64 us || 60 us || 68 us || 60 us
-10959 || -221 || Fail || 64 us || 60 us || 68 us || 68 us
3.14 || 3.14 || Pass ⸮⸮

Read values are completely random. Number of pass / fail tests are also completely random.

Did you dropped support for this particular chip ? Wiring is rather ok.
Title: Re: Winbond SPI Flash library
Post by: Marzogh on Aug 02, 2017, 03:00 pm
Hi Marzogh

I've recenetly got back to your SPI Library. I've been using it previously on version 2.3.1 with chip Winbond 25q40bvnig.

After update to version 2.6.0 it throws random errors on diagnostics. Errors are showing up since version 2.4.0

It looks like this:


Read values are completely random. Number of pass / fail tests are also completely random.

Did you dropped support for this particular chip ? Wiring is rather ok.
That is strange. I am not able to replicate the issue with a Q40BV chip that I have with me. Could you uncomment #RUNDIAGNOSTIC in SPIFlash.h and tell me what errors the library is throwing?

Also, I'm about to release v2.7.0 in a few minutes. Could you check and see if that fixes your issues?
Title: Re: Winbond SPI Flash library
Post by: Marzogh on Aug 02, 2017, 04:00 pm
Just pushed through an update to v2.7.0. With this update the library officially supports the Arduino Zero and derivants based on the SAMD21, squashes one major bug and brings back support for the ATTiny85 (Trinket) and updates support for the ESP32 (to the latest commit to the esp32-arduino core as of 02.08.17).

As always, you can find this version on Github here --> SPIFlash Library for Arduino v2.7.0 (https://github.com/Marzogh/SPIFlash/releases/tag/v2.7.0)
A ZIP file is also attached to the first post on this thread. The easiest way, as always, is to open up Library Manager on your Arduino IDE and update the libary to v2.7.0 :)
Title: Re: Winbond SPI Flash library
Post by: Marzogh on Aug 02, 2017, 04:17 pm
Update on future development:

I started working on SPIFlash as a little project to improve my programming skills (in 2015) but it has quickly turned into something that barely resembles the first release on the surface.

No matter how many new features I added, the fundamental functions of the library have remained the same from day one. This means any new features I would like to add today are hamstrung by sloppy coding from 2 years ago (Don't tell this to 2015 me. I thought it was the bees-knees when I figured out how to work `flash.writeAnything()` ! I'd never heard of templates before then). With all I have learnt about programming with C & C++ over the last two years, there are a number of changes I would like to bring in to make the library lean and efficient, support more chips, and add more features - all without any more bloat. As of v2.7.0 I appear to have hit a solid wall with improving I/O speeds. I know its possible to go faster, but not with the base code as clumsy as it is.

This brings us to the next major release milestone - v3.0.0. It is going to be a complete overhaul of the library. The changes I have made so far have resulted in a pretty dramatic increase of I/O speeds - especially when working with large chunks of data like structs, arrays and strings (>50% increase in speed with strings, for example). I am doing my best to preserve the functions currently in use, but, some will have to go the way of the dodo in the name of efficiency. The following changes will be made to the library as it stands. (This is a very preliminary list - more changes will happen before final release)


If any of you have any suggestions for improvement or a wishlist of features, I'd love to hear from you! -  MicroPython port anyone?  :smiley-cool:
Title: Re: Winbond SPI Flash library
Post by: pasaf on Aug 12, 2017, 09:55 pm
Hello,
Firstly want to thank you very much for your hard work, it's very helpful and useful.
Personally I have a wish. To be honest, main usage scenario of your library is to READ and WRITE SPI EEPROM. Mainly it means doing full backup and restore or upgrade some firmware or bios. That what programmer do. So, I think your library could be more popular if you supply with it crossplatform app to identify, read and flash ROMs. To turn Arduino into powerfull and easy to use programmer. 
Title: Re: Winbond SPI Flash library
Post by: mysource on Aug 16, 2017, 11:52 pm
Hi,
I try to change from SD to SPIFlash and all is working fine so far. Absolutly great Job!
I try to load some picture (bmp) into the flash. I imagine to convert the image content in a string and then store into the flash.

 think this is basically possible :smiley-roll: 

 Open requested file on SD card
Code: [Select]
  if ((bmpFile = SD.open(filename)) == NULL) {
    Serial.print("File not found");
    return;
  }



Convert to string 
Code: [Select]
String SD_Read;
  while (bmpFile.available()) {
    char ltr = bmpFile.read();
    SD_Read += ltr;
  }


Store to flash

Code: [Select]
  while (!flash.eraseSector(17, 0));


  if (flash.writeStr(17, 0, SD_Read)) {
    Serial.println("SAVED");
  } else {
    Serial.println("ERROR");
  }


then to display on the TFT, I have to read from Flash convert from String to File.  :smiley-confuse:


Did some one try this already?








Title: Re: Winbond SPI Flash library
Post by: Marzogh on Aug 17, 2017, 08:50 am
Hello,
Firstly want to thank you very much for your hard work, it's very helpful and useful.
Personally I have a wish. To be honest, main usage scenario of your library is to READ and WRITE SPI EEPROM. Mainly it means doing full backup and restore or upgrade some firmware or bios. That what programmer do. So, I think your library could be more popular if you supply with it crossplatform app to identify, read and flash ROMs. To turn Arduino into powerfull and easy to use programmer. 
Hi @pasaf, Thank you for the kind words. Your idea is a very interesting one. However, as much as I'd like to write code for a living, my main job actually involves dealing with stuff in a biology lab - I'm a geneticist by trade, so this library and the support I provide it are things I do in my free time. But, that is the beauty of Open Access/Free software - you can always take my code and turn it into whatever you wish  :smiley:  The main aim of this library is to provide you with the basic tools to build an app with any function you want, yourself. The upcoming release might help with what you want to do.

Release v3.0.0 will support read/write from/to multiple SPI Flash chips connected to one Arduino board. Using that version of the library it should be reasonably easy to put together a program that reads some data from Flash chip A and saves to to Flash chip B; repeating the process till all the data on chip A is on chip B. Afterward, the same program can be used to transfer the data from chip B to chip C. Easy backup & clone!  ???

I know you want to read of EEPROMs - as long as the EEPROMs communicate over SPI, getting them to work with this library is only a matter of modifying it slightly. Take a look at the opcodes in 'defines.h' and see if any need changing - then change the JEDEC ID (specifically the manufacturer ID) that the library recognises, to the one one from your EEPROM. Everything else should just work.

(If you wait till v3.0.0 comes out, you should be able to do this straight from your code, release 3.0.0 will come with the ability to define custom chip size/ID in user code.  :smiley:  )

Feel free to play around with the code in the developer branch on the Github repo. Its not stable yet and is a work in progress, but it already has some of the features you'll need.
Title: Re: Winbond SPI Flash library
Post by: Marzogh on Aug 17, 2017, 09:04 am
Hi,
I try to change from SD to SPIFlash and all is working fine so far. Absolutly great Job!
I try to load some picture (bmp) into the flash. I imagine to convert the image content in a string and then store into the flash.

 think this is basically possible :smiley-roll:

then to display on the TFT, I have to read from Flash convert from String to File.  :smiley-confuse:

Did some one try this already?

Hi mate, rather than working with a String object (especially on an 8-bit AVR, which I assume is what you're using?), how about you try and read the data on your SD into a byte array? Your code will be a lot more efficient and it'll be much easier to just feed an array to your TFT. Gary - HERE (http://forum.arduino.cc/index.php?topic=324009.60) - was using the readByteArray() function to read data off his flash chip and display it on a TFT.

There are two points to note though.

Title: Re: Winbond SPI Flash library
Post by: mysource on Aug 18, 2017, 07:15 pm
Hi mate, rather than working with a String object (especially on an 8-bit AVR, which I assume is what you're using?), how about you try and read the data on your SD into a byte array? 
This is just  a "one Time" action. I will store the pic in the flash instead of the SD card. Then to read the pic from flash to display on the TFT.
OK first I will tray to store the pic content in an array.
something like that.  bmpFile.read() returns an integer.
Code: [Select]
  char *arrayOfChars;
  uint16_t index = 0;
  while (bmpFile.available()) {
    arrayOfChars[index] = bmpFile.read();
    index++;
  }


Will see.....
After thet is done will check then -> TFT. Gary - HERE (http://forum.arduino.cc/index.php?topic=324009.60) 
THX for your info.
Title: Re: Winbond SPI Flash library
Post by: mysource on Aug 18, 2017, 09:05 pm
ok ...


 
Code: [Select]
Serial.println(read16(bmpFile), HEX);

  // pic size: 49208 bytes
  uint16_t _index = 0;
  uint8_t _page = 16;
  for (int i = _page; i < 209; i++) {
    flash.eraseSector(i, 0);
  }

  while (bmpFile.available()) {
    if (_index == 255) {
      _page++;
      _index = 0;
    }
    flash.writeByte(_page, _index, (byte)bmpFile.read());
    _index++;
  }

  Serial.println(read16(bmpFile), HEX);


Serial.println(read16(bmpFile), HEX); => 4D42 => BMP signature (read LSB and MSB) that is OK. but after flash erase I get C038 and after the while loop I get FFFF.  :smiley-roll-sweat:... but I'm not changing the file handler so far.

Title: Re: Winbond SPI Flash library
Post by: mysource on Aug 19, 2017, 03:55 pm
New start  :D


some calluclation about the image size.....
image size: 49208 bytes
1 page = 256 bytes
1 sector = 4k / 4096 bytes
1 sector = 16 pages
4096 bytes * 256 = 1'048'576 = 1MB


PIC Size = 49208/4096 = 12.01... 13 sectors
13 sectors * 16 Pages = 208 total Pages / 16..207
208 pages and the last page (208 )just 56 bytes.


Clear the Flash from page 16..208

Code: [Select]
  uint16_t _pageOfset = 16; // Start from page 16. First 16 pages are reserved for configuration
  for (uint16_t p = _pageOfset; p < _pageOfset + 208; p++) {
  while (!flash.eraseSector(p, 0));
  }



Read the file:
 
Code: [Select]
File bmpFileTmp;
  // Open requested file on SD card
  if ((bmpFileTmp = SD.open(filename)) == NULL) {
    Serial.print("File not found");
    return;
  }


Write to flash:
 
Code: [Select]
uint16_t _index = 0;
  uint8_t _page = _pageOfset;
  uint16_t maxPage = 0;
  uint16_t lastMaxIndex = 0;
  if (bmpFileTmp) {
    while (bmpFileTmp.available()) {
      if (_index == 256) {
        _page++;
        _index = 0;
      }
      flash.writeByte(_page, _index, (byte)bmpFileTmp.read());
      _index++;
    }
    bmpFileTmp.close();
  } 
maxPage = _page - _pageOfset;
lastMaxIndex = _index;


Check to first page (BMP signature) in the flash:

Code: [Select]
  printPage(16, 2);
  printPage(16, 1);



Code: [Select]
Reading page (0010)
066,077,056,192,000,000,000,000,000,000,054,000,000,000,040,000,
000,000,128,000,000,000,128,000,000,000,001,000,024,000,000,000,
000,000,002,192,000,000,229,076,000,000,229,076,000,000,000,000,
000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,
000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,
000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,
000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,
000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,
000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,
000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,
000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,
000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,
000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,
000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,
000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,
000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,
Reading page (0010)
424d38c0000000000000360000002800
00008000000080000000010018000000
000002c00000e54c0000e54c00000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000


First two bytes are signature for BMP.
066,077 or 0x424d

So far all ok.

Read back from flash to file handler:

Code: [Select]
  Serial.print("Page to loop: ");
  Serial.println(_pageOfset + maxPage);

  uint32_t _indexTotal = 0;
  for (uint16_t p = _pageOfset; p <= _pageOfset + maxPage; p++) {
    if (p == _pageOfset + maxPage) {
      for (uint16_t i = 0; i <= lastMaxIndex; i++) {
        Serial.print(p);
        Serial.print("\t");
        Serial.print(i);
        Serial.print("\t");
        bmpFile.write((byte)flash.readByte(p, i));
        Serial.println(_indexTotal);
        _indexTotal++;
      }
    } else {
      for (uint16_t i = 0; i <= 255; i++) {
        Serial.print(p);
        Serial.print("\t");
        Serial.print(i);
        Serial.print("\t");
        Serial.println(_indexTotal);
        bmpFile.write((byte)flash.readByte(p, i));
        _indexTotal++;
      }
    }
  }

last output...
pages  bytes  index
208      56         49208


but when I check first two bytes from the new file handler I get wrong values.
Code: [Select]
  uint16_t checkBMP = read16(bmpFile);
  Serial.println(checkBMP);


uint16_t read16(File f) {
  uint16_t result;
  ((uint8_t *)&result)[0] = f.read(); // LSB
  ((uint8_t *)&result)[1] = f.read(); // MSB
  return result;
}


Here I expect 0x424D (d16973) but I get 65535.  :smiley-roll:
The Bytes in the Flash looks good. In any case, the signature is correct.

Some Idea?
Title: Re: Winbond SPI Flash library
Post by: mixael on Oct 02, 2017, 12:18 pm
Hi, guys, please help me. I dont understand one simple thing.

I'm using W25Q64FVSSIG chip and trying to write a single byte, but i can't do it without preceding erasing the block.

my code (full sketch here https://gist.github.com/mix86/c9af8a35f7a2761144f57e7377f88386):

void loop() {
  sensorValue = byte(analogRead(A0));
 
  flash.eraseSector(page, 0); //<-- Does not work without this line (WTF?)
  flash.writeByte(page, offset, byte(sensorValue));
 
  dataByte = flash.readByte(page, offset);
  Serial.println(dataByte, HEX);
}

So, without erasing the block dataByte != sensorValue.

I know, that NAND flash needed to be erased before writing, but W25Q64FV is a NOR according to datasheet

Question: is it correct behaviour or i has a trouble in my code/connections?

Thank You)
Title: Re: Winbond SPI Flash library
Post by: chucktodd on Oct 03, 2017, 05:49 am
Hi, guys, please help me. I dont understand one simple thing.

I'm using W25Q64FVSSIG chip and trying to write a single byte, but i can't do it without preceding erasing the block.

my code (full sketch here https://gist.github.com/mix86/c9af8a35f7a2761144f57e7377f88386):

void loop() {
  sensorValue = byte(analogRead(A0));
 
  flash.eraseSector(page, 0); //<-- Does not work without this line (WTF?)
  flash.writeByte(page, offset, byte(sensorValue));
 
  dataByte = flash.readByte(page, offset);
  Serial.println(dataByte, HEX);
}

So, without erasing the block dataByte != sensorValue.

I know, that NAND flash needed to be erased before writing, but W25Q64FV is a NOR according to datasheet

Question: is it correct behaviour or i has a trouble in my code/connections?

Thank You)
You need to read the data sheet.

The W25Q64FV has a 4k sector erase AND can "program" up to 256 bytes at a time.  The Erase operation sets all of the sector's bits to 1.  A program operation can change one's to Zero's.  If you are programing the same memory byte multiple times, you can only change One's to Zero's UNLESS you erase the SECTOR (4k).

So, you can change from 255 to 127 but you cannot change a 127 to 128 without Erasing the whole 4KB sector.

It is a hassle, but that is how it is.  I am working on a FAT file system using theses 8MB and 16MB devices.  The 4k sector erase is difficult to work around with 8KB total RAM (MEGA:).

Chuck.
Title: Re: Winbond SPI Flash library
Post by: mixael on Oct 03, 2017, 03:08 pm
Thank you very much, Chuck. This is exhaustive explanation)
I'll try to read datasheets more thoroughly.
Thank you again)
Title: SPI Flash library - Now works with Winbond/Microchip/Spansion/Cypress
Post by: Marzogh on Nov 17, 2017, 03:57 am
Its finally here!!! Just pushed through an update to v3.0.0. This update is a major overhaul of the library and brings with it support for more flash memory manufacturers, more µC platforms, squashes a major bug, loses ATTiny85 support, and has a large number of optimizations for speed, stability & ease of development.

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.

Deletions
- 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 pseudocode to help
Quote
address = ( pagenumber << 8 ) + offset;
New Boards supported
- Nucleo-F091RC
- Adafruit Feather M0
- Adafruit Feather M0 Express (On board flash and external flash)

Flash memory chips supported
- Winbond (All SPI Flash chips)
- Microchip (SST25 & SST26 series)
- Cypress/Spansion (S25FL series)

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 (Refer to release notes (https://github.com/Marzogh/SPIFlash/releases/tag/v3.0.0) for details)
- 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


As always, you can find this version on Github here --> SPIFlash Library for Arduino v3.0.0 (https://github.com/Marzogh/SPIFlash/releases/tag/v3.0.0)
A ZIP file is also attached to the first post on this thread. The easiest way, as always, is to open up Library Manager on your Arduino IDE and update the libary to v3.0.0 :)
Title: Re: SPIFlash library - Now works with Winbond/Microchip/Spansion/Cypress
Post by: liolau on Nov 30, 2017, 12:17 am
Is the Arduino Nano known to not work, or is it a matter of testing?
Title: Re: SPIFlash library - Now works with Winbond/Microchip/Spansion/Cypress
Post by: Marzogh on Dec 10, 2017, 03:01 pm
@liolau: The Nano is just a matter of testing. It uses the same ATMega328 µC as in the Uno so it should work with no issues.
Title: Re: SPIFlash library - Now works with Winbond/Microchip/Spansion/Cypress
Post by: Marzogh on Dec 10, 2017, 03:09 pm
Hi all, just pushed through a major bug-fix release v3.0.1

@hanyazou identified a major bug (detailed here in issue 102 (https://github.com/Marzogh/SPIFlash/issues/102)) which has been fixed with v3.0.1

v3.0.1 also adds support for the S25FL127S from Spansion/Cypress.

As always, you can find this version on Github here --> SPIFlash Library for Arduino v3.0.1 (https://github.com/Marzogh/SPIFlash/releases/tag/v3.0.1)
A ZIP file is also attached to the first post on this thread. The easiest way, as always, is to open up Library Manager on your Arduino IDE and update the library to v3.0.1 :)
Title: Re: SPIFlash library - Now works with Winbond/Microchip/Spansion/Cypress
Post by: a7ashh14 on Dec 12, 2017, 04:19 pm
Hi,

Does this library support QSPI ? I have wired W25Q128JV in QSPI mode and was wondering if I could try that with this llibrary
Title: Re: SPIFlash library - Now works with Winbond/Microchip/Spansion/Cypress
Post by: mysource on Dec 14, 2017, 10:59 pm
Hi,
I get some error on save to flash. flash.writeAnything with char variables in struct fails.

I have two structs


Code: [Select]
struct Configuration {
  uint8_t tempHigh;         // store higher value for temperature
  uint8_t tempLow;          // store lower value for temperature
  bool parkingMode;         // store Parking Battery value boolean
  uint8_t chargingRange;    // store charging range status
  uint8_t chargingHigh;     // store charging higher value
  uint8_t chargingLow;      // store charging lower value
  boolean sendData;         // store send data flag
} configuration;

struct NetworkConfig {
  char ssid[50];            // Store network ssid from client
  char pwd[50];             // Store network password from client
  char userid[50];          // Store identification ID from client
} networkConfig;


set some values on both struct, and save to flash:


Code: [Select]
  Serial.print(">");
  Serial.print(networkConfig.ssid);
  Serial.println("<");
  Serial.print(">");
  Serial.print(networkConfig.pwd);
  Serial.println("<");
  Serial.print(">");
  Serial.print(networkConfig.userid);
  Serial.println("<");
 
  flash.eraseSector(0);
  if (flash.writeAnything(0, configuration)) {
    Serial.println ("Data write successful");
  } else {
    Serial.println ("Data write failed");
  }

  if (flash.writeAnything(1, networkConfig)) {
    Serial.println ("Data write successful");
  } else {
    Serial.println ("Data write failed");
  }
  flash.readAnything(0, configuration);
  flash.readAnything(1, networkConfig);

  Serial.println(networkConfig.ssid);
  Serial.println(networkConfig.pwd);
  Serial.println(networkConfig.userid);


Serial Monitor:
>MYSSID<
>thePassword<
>599bcc60e4942d4469d1c961<
Data write successful
Data write failed
⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮$⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮
⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮$⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮
⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮$⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮

All the values from struct "configuration" are OK.
Some has an Idea please.








Title: Re: SPIFlash library - Now works with Winbond/Microchip/Spansion/Cypress
Post by: mysource on Dec 15, 2017, 06:10 pm
after changing struct to nested struct, all is good.
Title: Re: SPIFlash library - Now works with Winbond/Microchip/Spansion/Cypress
Post by: supscientist on Dec 20, 2017, 03:01 am
Hi - thanks for a fantastic library! I know this is a pretty big ask but maybe someone here can help out. I'd love to use this library on an STM32 MCU in the Particle ecosystem. Particle is a fork of Arduino/Wiring, in my understanding, so I don't think a ton would need to change but it's hard to tell. Has anyone tried this or perhaps have any advice for where I could start? Thank you!
Title: Re: SPIFlash library - Now works with Winbond/Microchip/Spansion/Cypress
Post by: mysource on Dec 22, 2017, 03:58 pm
Hi, 
is there a conflict between EEPROM (mega2560 internal flash) and SPIFLASH Lib?
I tried to adjust the bootloader, then I noticed that the data on the winbond is gone, and the bootloader is not working as expected.

I tried this one (https://arduino-er.blogspot.ch/2016/06/arduin-uno-as-isp-to-burn-bootloader-to.html#comment-form).

Any idea?
Title: Re: SPIFlash library - Now works with Winbond/Microchip/Spansion/Cypress
Post by: Marzogh on Dec 24, 2017, 08:20 am
@a7ashh14: I'm afraid it does not yet support QSPI. What µC are you using with your W25Q128JV?

@supscientist: I've yet to play around with the Particle/Electron ecosystem. Feel free to play around with the code in the 'stable' branch of the library on Github and see if you can make it compatible with the Particle ecosystem. :)

@mysource: What pins are you connecting your Flash memory to? I don't think that the conflict is between the EEPROM and the Flash - its the probably because you use the SPI bus to program your Mega. If somehow, during the programming the Slave Select pin (that you have your flash connected to) is a) pulled low or b) the voltage drops and the µC enters Brown-out mode - then the data that's being sent into your Mega might a) get piped into your Flash memory as well or b) be interrupted unexpectedly. This could very easily cause corruption of the data on both the Mega's internal flash and the external SPI Flash you are using.
Title: Re: SPIFlash library - Now works with Winbond/Microchip/Spansion/Cypress
Post by: Marzogh on Dec 24, 2017, 12:51 pm
@supscientist As a place to start, take a look at how Particle's SPI Library works and see how you can replace the calls to the Arduino SPI Library with calls to the Particle SPI Library in FLASHIO.cpp. Every function in SPIFlash is built on top of the private functions in FLASHIO.cpp that make calls to the SPI Library - so the majority of your work should be done with this step. You might also have to modify some defines in defines.h.
Title: Re: SPIFlash library - Now works with Winbond/Microchip/Spansion/Cypress
Post by: ManlyEchidna on Dec 31, 2017, 05:23 am
Hi Marzogh,

Thanks for creating SPIFlash -- I can see a tremendous amount of work has gone into it.

I am new to SPI Flash memory so I may be asking a stupid question but here goes.  My basic question is: does SPIFlash support the "JV" series of chips from Winbond, specifically the W25Q32JVSSIQ and W25Q64JVSSIQ?  Or is there something about the JV series that makes them incompatible, and I should try to find the BV of FV series mentioned in the wiki?

The details:

I got some Winbond chips from DigiKey: W25Q32JVSSIQ and W25Q64JVSSIQ.  I soldered them on some SMT breakout boards from Adafruit and wired them up to an Adafruit Feather M0.  The pinouts are:

3V --> 8 (VCC)
GND --> 4 (GND)
SCK --> 6 (CLK)
MOSI --> 5 (DI / IO0)
MISO --> 2 (DO / IO1)
GPIO #11 --> 1 (/CS)

At first, I did not hook up pins 3 (IO2) or 7 (IO3) to anything since it seemed they were not needed in this configuration.

I modified the readWriteString example sketch to tell it to use pin 11 for chip select in the SPIFlash constructor:

Code: [Select]

//SPIFlash flash;
SPIFlash flash(11);


However, when I run I get an endless stream of this error message:


Unable to Enable Writing to chip.
Please make sure the HOLD & WRITEPROTECT pins are pulled up to VCC


According to the Winbond data sheet, the JV series of chips do not have HOLD and WRITEPROTECT pins:

https://www.winbond.com/resource-files/w25q32jv%20spi%20revc%2008302016.pdf (https://www.winbond.com/resource-files/w25q32jv%20spi%20revc%2008302016.pdf)

Unlike the FV series, which state that pin 3 is both /WP and IO2, and pin 7 is both HOLD and IO3, the JV series just calls them IO2 and IO3.  Looks like write protection is enabled/disabled only via the status registers.

I tried various combinations of tying pins 3 and/or 7 to Vdd and Vcc, but always got the same error.  Then, based on the error message, I tried putting pullup resistors between 3 and 7 and Vcc, with values of 5.1K and then 100K, but I admit I'm just guessing there.  Same result.

So ... am I out of luck?  Is this chip series not supported? 

Should I add pullup resistors between pins 3 and/or 7 to Vcc?  If so, any suggestion on what values?

Thanks!
Title: Re: SPIFlash library - Now works with Winbond/Microchip/Spansion/Cypress
Post by: Marzogh on Jan 07, 2018, 02:12 pm
Hi ManlyEchidna, I'm afraid I have not tested the JV series of flash memory with the library. I've just quickly glanced over the datasheet you've linked to and I don't see any reason why they shouldn't work. The Error message that you are getting is only meant for chips with HOLD or WP pins, so, if you don't have them, you can ignore it.

Could you please run the following steps and let me know what output you get?


- Make sure #define RUNDIAGNOSTIC is uncommented in your SPIFlash.h file and save it.
- Upload the Diagnostics.ino sketch to your Feather M0 after setting
Code: [Select]

SPIFlash flash(11);

- Paste the serial output from the sketch in your reply.

Let's see if we can get the library working with your chips :)
Title: Re: SPIFlash library - Now works with Winbond/Microchip/Spansion/Cypress
Post by: compucat on Jan 12, 2018, 09:32 pm
Hey there! I'm having a hard time getting SPIFlash to work with a Spansion S25FL127S (MCU is an ATMega328p with Uno bootloader running at 16 MHz, 3.3v). I keep getting various errors, including 0x0B and 0x06; I suspect a wiring issue, however everything seems OK. Power and ground are OK, SPI lines are correct, CS is pulled high with a 10kohm resistor, and write protect and hold are both tied high. Any idea what's going wrong? Other devices on that same SPI bus work fine. (SPIFlash still errors out even with nothing else on the SPI bus.)
Title: Re: SPIFlash library - Now works with Winbond/Microchip/Spansion/Cypress
Post by: Marzogh on Jan 16, 2018, 09:05 am
@compucat have you tried removing the pull up on the CS pin?
Title: Re: SPIFlash library - Now works with Winbond/Microchip/Spansion/Cypress
Post by: compucat on Jan 16, 2018, 06:55 pm
Yup, I've tried with CS pulled up, no pullup, write protect and hold floating, tied high, tied low. Nothing seems to work. Only change I've made to the FlashDiagnostics code is to set an alternative CS pin. Do you have a working schematic for an ATMega328p+Spansion setup?

EDIT: I've also tried wiring it to a stock Arduino Uno with resistors as level shifters, no dice. I might try again with a fresh chip just to rule out bad silicon.

EDIT 2: Tried a fresh chip, no dice.
Title: Re: SPIFlash library - Now works with Winbond/Microchip/Spansion/Cypress
Post by: TrekRider on Feb 10, 2018, 12:21 pm
Hi I am trying to use this library to access an LC W25Q80B memory modules with a Winbond 25Q80  from a BluePill STM32F103.
http://www.chinalctech.com/index.php?_m=mod_product&_a=view&p_id=1066
It looks like a great library but I cant get anything from the FlashDiagnostics example.
Reading the instructions I should remove the // from #define RUNDIAGNOSTIC in SPIFlash.cpp but I cant find it there  but it is in the SPIFlash.h but it is already un-commented so I leave everything as is.
The examples builds and runs on the STM but I only get the following output:
Code: [Select]
Initialising Flash memory..........
Chip Diagnostics initiated.

No Chip size defined by user



--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
                                                                    SPIFlash Library version: 3.0.0
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
                                                                                Get ID
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
...JEDEC ID: ef4014h


If I connect using Arduino Pro Mini 3.3, I get:
Code: [Select]
Opening port
Port open
Initialising Flash memory..........
Chip Diagnostics initiated.

No Chip size defined by user



--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
                                                                    SPIFlash Library version: 3.0.0
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
                                                                                Get ID
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
JEDEC ID: ef4014h
Manufacturer ID: efh
Memory Type: 40h
Capacity: 1048576 bytes
Maximum pages: 4096
Unique ID: 1153678118893824, 0x608414039E763900
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Erase Chip: Data I/O test PASS Time: 1.274 s
Erase 64KB Block: Data I/O test PASS Time: 128.920 ms
Erase 32KB Block: Data I/O test PASS Time: 109.400 ms
Erase 4KB Sector: Data I/O test PASS Time: 42.328 ms

Byte: Data I/O test PASS Write Time: 320 us, Read Time: 128 us
Char: Data I/O test PASS Write Time: 328 us, Read Time: 128 us
Word: Data I/O test PASS Write Time: 352 us, Read Time: 128 us
Short: Data I/O test PASS Write Time: 360 us, Read Time: 128 us
ULong: Data I/O test PASS Write Time: 384 us, Read Time: 136 us
Long: Data I/O test PASS Write Time: 376 us, Read Time: 144 us
Error code: 0x0A
Float: Data I/O test FAIL Write Time: 0 us, Read Time: 160 us
Struct: Data I/O test PASS Write Time: 160 us, Read Time: 160 us
Byte Array: Data I/O test PASS Write Time: 5.288 ms, Read Time: 888 us
String: Data I/O test PASS Write Time: 424 us, Read Time: 152 us
Power Down: Data I/O test FAIL Not all chips support power down. Please check your datasheet.
Power Up: Data I/O test PASS Time: 176 us
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


Any suggestions please

Title: Re: SPIFlash library - Now works with Winbond/Microchip/Spansion/Cypress
Post by: kucukkose on Feb 16, 2018, 03:16 pm
Hi I am trying to use this library to access W25Q64JV with Arduino MEGA. But i coldn't be successful.
W25Q64BV is obsolete and i used W25Q64JV.
Do you have any relevant ideas about this?

Thanks

Title: Re: SPIFlash library - Now works with Winbond/Microchip/Spansion/Cypress
Post by: Gosh on Feb 19, 2018, 12:58 pm
W25Q64BV is obsolete? Hmmm... why do you think so?

I have a funny problem with this kind of memory. Namely, I can't find any sketch which demonstrates the simpliest read/write operations with W25 chips. Can someone help with this? 
Title: Re: SPIFlash library - Now works with Winbond/Microchip/Spansion/Cypress
Post by: Marzogh on Feb 28, 2018, 04:53 am
@ Compucat : I'm afraid I can't explain why that's happening with you. The library appears to work fine with the S25FL127S I have. I'll try out a few other chips this weekend and let you know if I face any issues.

@ TrekRider: I'm afraid the library does not officially support the BluePill. I have had a lot of trouble getting the USB bootloader working on my boards and gave up just before Christmas. However, I'm still keen on supporting the board, so, could you do me a favour and raise an issue on the Github page [here (https://github.com/Marzogh/SPIFlash/issues/new)]? I'll get going started again on getting the Blue pill supported. :D

@ kucukkose: Thanks for raising an issue on Github about this. Could you please refer to my comments there and provide a little more information on what exactly the problem seems to be?

@ Gosh: What do you mean by simple sketch to demonstrate read/write operations? Are you looking for code that works with the SPIFlash library or SPI level code?
Title: SPIFlash library (Update: Will be renamed soon)
Post by: Marzogh on Mar 09, 2018, 06:36 am
Update: Library will be renamed in a couple of months.

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 [in 2015], 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, Felix Rusu of LowPowerLab (https://lowpowerlab.com/) raised an issue [#83 (https://github.com/Marzogh/SPIFlash/issues/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.

Felix'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 Felix's customers.

Quote
On a side note, if you did not know already, Felix makes and sells a fantastic line of Arduino compatible boards - the Moteino (https://lowpowerlab.com/shop/) 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 (https://github.com/arduino/Arduino/issues/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.:

The only change will have to be made in end-user code will be to change the "#include SPIFlash.h" to "#include SPIMemory.h" (or whatever the new name will be). 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 - the end user - but, given the facts, it is the only thing I can do to be fair to Felix.

Thanks again for using SPIFlash and I hope you will continue to find it useful in whatever new name it will take on.
Title: Re: SPIFlash library - Now works with Winbond/Microchip/Spansion/Cypress
Post by: enkoopa on Mar 18, 2018, 03:24 am
I'm scratching my head on how to use SPIFlash and some sort of Serial function at the same time. I'd like to dump the contents of my flash chip via Serial (FTDI).

I've tried with both SoftwareSerial (on a different pin) and Serial on an ATTINY841. Behaviour is as follows

- Loop with a .println("Hello"); outputs serial data.
- As soon as I add flash.begin(); in setup(), no serial data is ever sent.

I've spent a few hours trying to search for various things, including using SPI and Serial at the same time... which led me to trying SoftwareSerial, but that has no effect. I'm trying various things now... trying to end the serial before using SPIFlash, then using powerDown() after... but that seems to have no effect.

Thanks!
Title: Re: SPIFlash library - Now works with Winbond/Microchip/Spansion/Cypress
Post by: enkoopa on Mar 18, 2018, 02:27 pm
Here's working/broken code.

Code: [Select]
#include <SPIFlash.h>

SPIFlash flash;

void setup()
{
}

void loop()
{
  Serial.begin(19200);
  Serial.println("HELLO");
  Serial.flush();
  Serial.end();
 
  // Commented out - works. Uncommented - broken.
  flash.begin();
}
Title: Re: SPIFlash library - Now works with Winbond/Microchip/Spansion/Cypress
Post by: enkoopa on Mar 18, 2018, 02:37 pm
Update - I think is related to RAM consumption. This code works on a 328P. The TINYT841 only has 512b of RAM. Using SPIFlash puts it way over that.

Not sure if there are any ways to trim memory consumption?
Title: Re: SPIFlash library - Now works with Winbond/Microchip/Spansion/Cypress
Post by: Marzogh on Mar 19, 2018, 10:42 am
Hi mate, If you go back to the very first few versions of the library the memory consumption should be low enough to work. Give it a go and let me know. :) The old versions also had Attiny support (for the Attiny85) so that should help.
Title: Re: SPIFlash library - Now works with Winbond/Microchip/Spansion/Cypress
Post by: aseelye on Mar 20, 2018, 12:04 am
Hey, just a heads up, I got a few of the W25Q64JV chips in today.  They seem to be working, except power down is reported in the FlashDiagnostics sketch as failing.  I'm not sure that it's been implemented in the library, but it seems the Winbond line is your preferred supplier, and they have support in the datasheet (section 8.2.24).  Perhaps this is done otherwise by driving CS high, and the chip knows to power down while it's not selected?

Also, the current library coming via the integrated library download in the Arduino IDE is giving 3.0.1.  Github looks like you're at 3.1.0 currently, so not sure if that was an oversight or the Arduino guys are slow in updating.

Last, is there anything for rudimentary file systems with this?  I'm looking to record periodic environmental data (wind speed & direction, temp, light intensity, barometer, etc) every X minutes, and then ship the data home once per day via cellular.  Being able to save the data as a collection of strings in a file would make this much simpler for people who aren't used to banging bits around manually and all that.

Thanks!
Title: Re: SPIFlash library - Now works with Winbond/Microchip/Spansion/Cypress
Post by: Marzogh on Mar 20, 2018, 05:44 am
Hi mate,

Thanks for the heads up. I've got some JV series coming in from AliExpress, but this being AliExpress, they're probably a month or so away form getting to me in Australia. :/

I'll see if I can figure out what's going wrong (in theory) by looking at the timing on the datasheet and get back to you as soon as I can.

The current release version is v3.0.1 and that's what is available from the library manager. I'm still testing v3.1.0 is all platforms that library supports and should hopefully have it out before this week ends.

Feel free to pull down a zip of the development branch to test with your hardware. The code is pretty much good to go and just needs some battle testing before I sign off on a release.

If you are looking at using filesystems, Adafruit's SPI Flash library  (https://learn.adafruit.com/adafruit-feather-m0-express-designed-for-circuit-python-circuitpython/using-spi-flash) has quite good filesystem support with the ability to mount the chip up as a mass storage device. However, this is something I've only ever played around with on the M0 Express line of boards and I don't know how it works (or if it does) outside of the M0 / SAMD21 line.

I would like to - someday incorporate a filesystem into my library, but I have two problems with that:



I use the library with my environmental sensor units as a way of storing lots of data as (byte arrays) on an SPI Flash chip. When it fills up I write all of that data to an SD card in one go. This saves a ton of power when you have a low-power environmental sensing / logging system deployed in remote areas for extended periods of time. I borrowed this idea from EKMallon (https://forum.arduino.cc/index.php?action=profile;u=248653)'s fantastic Cave Pearl project (https://thecavepearlproject.org/). He uses EEPROMs to buffer data but I've found that using SPI Flash in combination with an SD card works equally well - especially when I use a TPL5110 timer to cut power to the entire system when it doesn't need to be operational. :)
Title: Re: SPIFlash library - Now works with Winbond/Microchip/Spansion/Cypress
Post by: Marzogh on Mar 26, 2018, 07:32 am
Just pushed an update through to v3.1.0 with the following changes:

- Library name change notice (http://forum.arduino.cc/index.php?topic=324009.msg3639804#msg3639804) has been inserted into flash.begin(). This notice can be dismissed by commenting out the instance of `#define PRINTNAMECHANGEALERT` in SPIFlash.h. Please refer to the README.md for further details.

Bugs squashed:
- 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 (https://github.com/Marzogh/SPIFlash/issues/112)

- An error with how _writeErrorCheck() worked has been resolved. Writing structs is now as stable as other functions are. Fixes Issue #106 (https://github.com/Marzogh/SPIFlash/issues/106)

- All compilation-time, non-critical errors have been fixed.

Enhancements:
- 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().


New flash memory chips supported:
- S25FL127S

Last but not least, the wiki is finally finished and up to date.  8)
Title: Re: SPIFlash library - Now works with Winbond/Microchip/Spansion/Cypress
Post by: sikletiya on Mar 28, 2018, 05:28 am
Hey, just a heads up, I got a few of the W25Q64JV chips in today.  They seem to be working, except power down is reported in the FlashDiagnostics sketch as failing.  I'm not sure that it's been implemented in the library, but it seems the Winbond line is your preferred supplier, and they have support in the datasheet (section 8.2.24).  Perhaps this is done otherwise by driving CS high, and the chip knows to power down while it's not selected?

Also, the current library coming via the integrated library download in the Arduino IDE is giving 3.0.1.  Github looks like you're at 3.1.0 currently, so not sure if that was an oversight or the Arduino guys are slow in updating.

Last, is there anything for rudimentary file systems with this?  I'm looking to record periodic environmental data (wind speed & direction, temp, light intensity, barometer, etc) every X minutes, and then ship the data home once per day via cellular.  Being able to save the data as a collection of strings in a file would make this much simpler for people who aren't used to banging bits around manually and all that.

Thanks!
Hi Aseelye and Marzogh.

I am using W25Q64JV. The code fails to run. The error (0x0B) suggests that Arduino is not able to recognize the W25Q64JV. and I am not able to understand what is causing this error. I believe I am not wiring the chip properly. Could you please post your pin connection?

I have setup the pins following way:

W25Q64JV (PIN1) ---- Arduino Mega (PIN53)
W25Q64JV (PIN2) ---- Arduino Mega (PIN50)
W25Q64JV (PIN3) ---- Arduino Mega (GND)
W25Q64JV (PIN4) ---- Arduino Mega (GND)
W25Q64JV (PIN5) ---- Arduino Mega (PIN51)
W25Q64JV (PIN6) ---- Arduino Mega (PIN52)
W25Q64JV (PIN7) ---- Arduino Mega (VCC 3.3 V)
W25Q64JV (PIN8) ---- Arduino Mega (VCC 3.3 V)

Thanks in advance,
Apoorva
Title: Re: SPIFlash library - Now works with Winbond/Microchip/Spansion/Cypress
Post by: Marzogh on Mar 29, 2018, 11:34 am
Hi Apoorva,

The 0x0B code indicates that the µC is not able to raise the chip on SPI comms - not that it is unable to recognise it. Try wiring both PIN3 & PIN7 of the W25Q64JV to VCC instead of wiring one to GND and one to VCC. From what I understand, the IO2 (PIN3) and IO3 (PIN7) need to be pulled up, not down, when they are not in use.

Let me know if that works.

Cheers!
Title: Re: SPIFlash library - Now works with Winbond/Microchip/Spansion/Cypress
Post by: rafamangualde@gmail.com on Mar 29, 2018, 08:34 pm
Hello guys, I'm using this library for quite a bit with arduino mega, and have never had a problem, it work just fine.

Now i'm trying to migrate my system for ESP32 and it seens to not work with this plataform. I used a logic analyzer to see the data transfer, and it shows no data at all. Only the CS pin shows some oscillation.

I'm using the ESP32-WROOM devkit.
Arduino IDE 1.8.10.0
Win 10
Winbond W25Q64FV

The connections:
Winbond chip > ESP32 devikit
DI    > MOSI (GPIO23)
DO  > MISO (GPIO19)
SCK > SCK (GPIO18)
CS   > GPIO10

I user the constructor: SPIFlash flash(10);
And initialized it with: flash.begin(MB(64));

I tryed the library example "TestFlash", and other examples and no success. I understand it is in beta version yet, but is there any sugestion i can do to make it work with ESP32?
Title: Re: SPIFlash library - Now works with Winbond/Microchip/Spansion/Cypress
Post by: Marzogh on Apr 05, 2018, 02:05 pm
Hi mate, I've just tested it with the Adafruit ESP32 Feather and it works fine. I don't have the ESP32-WROOM dev kit but, the ESP32 Feather uses the same WROOM32 module as the dev kit.

My set up on the ESP32 Feather is as follows:

Arduino IDE 1.8.5
Mac OSX 10.13.3
Winbond W25Q64FV
ESP32 core as of commit 25dff4f (https://github.com/espressif/arduino-esp32/tree/25dff4f044151f7f766c64b9d2ad90398472e6b3)

DI    > MOSI (GPIO18)
DO  > MISO (GPIO19)
SCK > SCK (GPIO5)
CS   > GPIO33


I used the constructor: SPIFlash flash(33);

There's no need to say flash.begin(MB(64)); the W25Q64FV should be recognised by >v3.0.0 of the library automatically.

FlashDiagnostics.ino will not work - I have not re-written it to support the ESP32, but TestFlash works fine and every function works as it should.

A couple things to note in what you said:

Title: Re: SPIFlash library - Now works with Winbond/Microchip/Spansion/Cypress
Post by: Saikiran25 on May 02, 2018, 01:41 pm
Hi,
I am writing a code for w25q16bv flash memory. it had commands to erase the data upto 4Kb, sector erase upto 64Kb and total chip erase. but I only need to erase 256 bytes in a specified location. i tried writing 0xFF by using SPI.transfer(); function but no use. is there any way to resolve this problem?
Title: Re: SPIFlash library - Now works with Winbond/Microchip/Spansion/Cypress
Post by: Marzogh on May 12, 2018, 01:36 pm
You cannot write 0xFF to locations that already have data in them - they need to be erased properly.

The only way for you to erase a memory section that is smaller than 4KB would be to use a buffer. Roughly speaking, your code should do the following:



Et voilà! The 256 bytes you want to erase will have been erased.  ;D
Title: Re: SPIMemory library - Formerly SPIFlash - now supports basic SFDP!
Post by: Marzogh on May 16, 2018, 02:40 pm
Just pushed an update through to v3.2.0 with the following changes:

- The Library is now called SPIMemory, not SPIFlash. The reason for this change can be found here. (http://forum.arduino.cc/index.php?topic=324009.msg3639804#msg3639804)

Enhancements:
- 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.
- The library now does the following - if the flash memory chip is compatible with the SFDP standard
  - Identifies the flash memory chip using the Serial Flash Discoverable Parameters standard. (JESD216B)
  - Identifies the following opcodes from the SFDP tables and uses them to read/write data:
         - eraseSector, eraseBlock32K, eraseBlock64K
  - Reads timing information from SFDP to accurately time the following operations:
         - eraseSector, eraseBlock32K, eraseBlock64K


New flash memory chips supported:
- 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

New Microcontrollers supported:
- ATSAMD51J19 ARM Cortex M4 (Adafruit Metro M4)

I've started work on proper documentation. As polaroi8d pointed out here (https://github.com/Marzogh/SPIMemory/issues/129), the old ReadMe was getting far too unwieldy and the Github Wiki is not the easiest thing to poke around. By the time the next release rolls around I hope to have the documentation done - (Rst + Sphinx). Check out the progress of the documentation here! (http://spimemory.readthedocs.io/en/latest/) Any recommendations are welcome  8)
Title: W25Q64JV
Post by: kucukkose on May 18, 2018, 01:44 pm
Hi Marzogh

Did you received your JV series.
I am using W25Q64JV and i updated the library 3.2.0.
But library gives Error code: 0x0B

Thanks
Ergun

Hi mate,

Thanks for the heads up. I've got some JV series coming in from AliExpress, but this being AliExpress, they're probably a month or so away form getting to me in Australia. :/

I'll see if I can figure out what's going wrong (in theory) by looking at the timing on the datasheet and get back to you as soon as I can.

The current release version is v3.0.1 and that's what is available from the library manager. I'm still testing v3.1.0 is all platforms that library supports and should hopefully have it out before this week ends.

Feel free to pull down a zip of the development branch to test with your hardware. The code is pretty much good to go and just needs some battle testing before I sign off on a release.

If you are looking at using filesystems, Adafruit's SPI Flash library  (https://learn.adafruit.com/adafruit-feather-m0-express-designed-for-circuit-python-circuitpython/using-spi-flash)has quite good filesystem support with the ability to mount the chip up as a mass storage device. However, this is something I've only ever played around with on the M0 Express line of boards and I don't know how it works (or if it does) outside of the M0 / SAMD21 line.

I would like to - someday incorporate a filesystem into my library, but I have two problems with that:

  • I have no idea how filesystems work, much less how to implement one on the Arduino platform :P
  • My main aim with this library has been to get it to work as fast as it can while maintaining read/write integrity. AFAIK, putting a filesystem in there reduces this speed enormously.


I use the library with my environmental sensor units as a way of storing lots of data as (byte arrays) on an SPI Flash chip. When it fills up I write all of that data to an SD card in one go. This saves a ton of power when you have a low-power environmental sensing / logging system deployed in remote areas for extended periods of time. I borrowed this idea from EKMallon (https://forum.arduino.cc/index.php?action=profile;u=248653)'s fantastic Cave Pearl project (https://thecavepearlproject.org/). He uses EEPROMs to buffer data but I've found that using SPI Flash in combination with an SD card works equally well - especially when I use a TPL5110 timer to cut power to the entire system when it doesn't need to be operational. :)
Title: Re: SPIMemory library - Formerly SPIFlash - now supports basic SFDP!
Post by: Marzogh on May 21, 2018, 06:49 am
Hi Ergun,

As I replied on your bug report on Github (https://github.com/Marzogh/SPIMemory/issues/115#issuecomment-381479606), I have received my W25Q64JV and tested it with v3.1.0 & with v3.2.0 and they work fine - no errors thrown at all. Could you please respond to my reply there?
Title: Re: SPIMemory library - Formerly SPIFlash - now supports basic SFDP!
Post by: Marzogh on May 21, 2018, 07:17 am
Just pushed an update through to v3.2.1 with the following changes:

Bugs squashed:
- Fixes issue #135 (https://github.com/Marzogh/SPIMemory/issues/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 might not be 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.

Enhancements:
- 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'.
- The way the basic functions execute has been modified to keep the function runtime the same (or improved) while reducing their memory footprint.

Test sketch - FlashDiagnostics.ino from v3.2.0 with #RUNDIAGNOSTIC commented out
Test platform - Arduino Pro Mini 8MHz 3.3V

Library versionCompiled code sizeSFDP discovery% Difference from v3.1.0
v3.1.017652 bytesNot supported0%
v3.2.020104 bytesSupported & enabled by default+13.9%
v3.2.117854 bytesSupported & enabled+1.1%
v3.2.115316 bytesSupported & disabled-13.75%
Title: Re: SPIMemory library - Formerly SPIFlash - now supports basic SFDP!
Post by: jaholmes on Jun 13, 2018, 09:31 pm
(Low-priority / Feature request)

Not sure if this has been entertained before and dismissed for some reason, but:  It would be cool if the library API explicitly supported sequential access.  E.g. readNextByte() or similar.  It seems that most (all?) of these devices auto-increment addresses following accesses, meaning that they're optimized for sequential access.  Meanwhile, the library steers you toward random access, which is kind of worst-case scenario.  Supporting random access is fine, of course, but supporting and documenting the access pattern that the hardware is actually designed for seems important too.  Otherwise, people who need to stream bytes from memory are going to do things like readByte(addr++) and be severely punished for it when the library does 4x as many transfers as necessary.
Title: Re: SPIMemory library - Formerly SPIFlash - now supports basic SFDP!
Post by: walterpre on Jun 22, 2018, 11:44 am
Hi Marzogh,

I've problems with reading and writing to SST26VF064B from Microchip.

I'm using a SAMD21 sparkfun mini breakout.

If I run the sketch "FlashDiagnostics" the chip is recognized and I get the following output:
SPIMemory Library version: 3.2.1

JEDEC ID: 0xBE5237
Man ID: 0xBE
Memory ID: 0x52
Capacity: 0
Max Pages: 0

-----------------------------------------------------------------------------------------------------------------------------
                     Testing library code
-----------------------------------------------------------------------------------------------------------------------------
         Function      Test result              Runtime
-----------------------------------------------------------------------------------------------------------------------------
         Power Down         FAIL         Not all chips support power down. Check your datasheet.
         Power Up         PASS                  0 us

         Erase Chip         PASS                  0 us
         Erase 72KB         FAIL   
         Erase 64KB         FAIL   
         Erase 32KB         FAIL   
         Erase 4KB         FAIL   
-----------------------------------------------------------------------------------------------------------------------------
         Data type      I/O Result         Write time         Read time
-----------------------------------------------------------------------------------------------------------------------------
         Byte            FAIL                  0 us
         Char            FAIL                  0 us
         Word            FAIL                  0 us
         Short            FAIL                  0 us
         ULong            FAIL                  0 us
         Long            FAIL                  0 us
         Float            FAIL                  0 us
         Struct            FAIL                  0 us
         Byte Array         FAIL   0,       FAIL   1,       FAIL   2,       FAIL   3,       FAIL   4,       FAIL   5,       FAIL   6,       FAIL   7,       FAIL   8,       FAIL   9,       FAIL   10,       FAIL   11,       FAIL   13,       FAIL   14,       FAIL   15,       FAIL   16,       FAIL   17,       FAIL   18,       FAIL   19,       FAIL   20,       FAIL   21,       FAIL   22,       FAIL   23,       FAIL   24,       FAIL   25,       FAIL   26,       FAIL   27,       FAIL   28,       FAIL   29,       FAIL   30,       FAIL   31,       FAIL   32,       FAIL   33,       FAIL   34,       FAIL   35,       FAIL   36,       FAIL   37,       FAIL   38,       FAIL   39,       FAIL   40,       FAIL   41,       FAIL   42,       FAIL   43,       FAIL   44,       FAIL   45,       FAIL   46,       FAIL   47,       FAIL   48,       FAIL   49,       FAIL   50,       FAIL   51,       FAIL   52,       FAIL   53,       FAIL   54,       FAIL   55,       FAIL   56,       FAIL   57,       FAIL   58,       FAIL   59,       FAIL   60,       FAIL   61,       FAIL   62,       FAIL   63,       FAIL   64,       FAIL   65,       FAIL   66,       FAIL   67,       FAIL   68,       FAIL   69,       FAIL   70,       FAIL   71,       FAIL   72,       FAIL   73,       FAIL   74,       FAIL   75,       FAIL   76,       FAIL   77,       FAIL   78,       FAIL   79,       FAIL   80,       FAIL   81,       FAIL   82,       FAIL   83,       FAIL   84,       FAIL   85,       FAIL   86,       FAIL   87,       FAIL   88,       FAIL   89,       FAIL   90,       FAIL   91,       FAIL   92,       FAIL   93,       FAIL   94,       FAIL   95,       FAIL   96,       FAIL   97,       FAIL   98,       FAIL   99,       FAIL   100,       FAIL   101,       FAIL   102,       FAIL   103,       FAIL   104,       FAIL   105,       FAIL   106,       FAIL   107,       FAIL   108,       FAIL   109,       FAIL   110,       FAIL   111,       FAIL   112,       FAIL   113,       FAIL   114,       FAIL   115,       FAIL   116,       FAIL   117,       FAIL   118,       FAIL   119,       FAIL   120,       FAIL   121,       FAIL   122,       FAIL   123,       FAIL   124,       FAIL   125,       FAIL   126,       FAIL   127,       FAIL   128,       FAIL   129,       FAIL   130,       FAIL   131,       FAIL   132,       FAIL   133,       FAIL   134,       FAIL   135,       FAIL   136,       FAIL   137,       FAIL   138,       FAIL   139,       FAIL   140,       FAIL   141,       FAIL   142,       FAIL   143,       FAIL   144,       FAIL   145,       FAIL   146,       FAIL   147,       FAIL   148,       FAIL   149,       FAIL   150,       FAIL   151,       FAIL   152,       FAIL   153,       FAIL   154,       FAIL   155,       FAIL   156,       FAIL   157,       FAIL   158,       FAIL   159,       FAIL   160,       FAIL   161,       FAIL   162,       FAIL   163,       FAIL   164,       FAIL   165,       FAIL   166,       FAIL   167,       FAIL   168,       FAIL   169,       FAIL   170,       FAIL   171,       FAIL   172,       FAIL   173,       FAIL   174,       FAIL   175,       FAIL   176,       FAIL   177,       FAIL   178,       FAIL   179,       FAIL   180,       FAIL   181,       FAIL   182,       FAIL   183,       FAIL   184,       FAIL   185,       FAIL   186,       FAIL   187,       FAIL   188,       FAIL   189,       FAIL   190,       FAIL   191,       FAIL   192,       FAIL   193,       FAIL   194,       FAIL   195,       FAIL   196,       FAIL   197,       FAIL   198,       FAIL   199,       FAIL   200,       FAIL   201,       FAIL   202,       FAIL   203,       FAIL   204,       FAIL   205,       FAIL   206,       FAIL   207,       FAIL   208,       FAIL   209,       FAIL   210,       FAIL   211,       FAIL   212,       FAIL   213,       FAIL   214,       FAIL   215,       FAIL   216,       FAIL   217,       FAIL   218,       FAIL   219,       FAIL   220,       FAIL   221,       FAIL   222,       FAIL   223,       FAIL   224,       FAIL   225,       FAIL   226,       FAIL   227,       FAIL   228,       FAIL   229,       FAIL   230,       FAIL   231,       FAIL   232,       FAIL   233,       FAIL   234,       FAIL   235,       FAIL   236,       FAIL   237,       FAIL   238,       FAIL   239,       FAIL   240,       FAIL   241,       FAIL   242,       FAIL   243,       FAIL   244,       FAIL   245,       FAIL   246,       FAIL   247,       FAIL   248,       FAIL   249,       FAIL   250,       FAIL   251,       FAIL   252,       FAIL   253,       FAIL   254,       FAIL   255,       PASS                  0 us
         String            FAIL                  0 us
-----------------------------------------------------------------------------------------------------------------------------

Could you give me a hint, what to do/test?
Title: Re: SPIMemory library - Formerly SPIFlash - now supports basic SFDP!
Post by: BigEyeTuna on Jul 19, 2018, 09:38 pm
Getting a similar result with the Adafruit feather SAMD and a 16MB Microchip SST26. Seems like it can erase and read, but not write. Any suggestions?

I also swapped to another 16MB Microchip SST26 with the same result.

Code: [Select]
Initialising..........

SPIMemory Library version: 3.2.1

JEDEC ID: 0xBF2641
Man ID: 0xBF
Memory ID: 0x26
Capacity: 16777216
Max Pages: 4294967295

-----------------------------------------------------------------------------------------------------------------------------
Testing library code
-----------------------------------------------------------------------------------------------------------------------------
Function Test result     Runtime
-----------------------------------------------------------------------------------------------------------------------------
Power Down   FAIL Not all chips support power down. Check your datasheet.
Power Up   PASS      0 us

Erase Chip   PASS      0 us
Erase 72KB   PASS      0 us
Erase 64KB   PASS      0 us
Erase 32KB   PASS      0 us
Erase 4KB   PASS      0 us
-----------------------------------------------------------------------------------------------------------------------------
Data type I/O Result      Write time      Read time
-----------------------------------------------------------------------------------------------------------------------------
Byte   FAIL      0 us
Char   FAIL      0 us
Word   FAIL      0 us
Short   FAIL      0 us
ULong   FAIL      0 us
Long   FAIL      0 us
Float   FAIL      0 us
Struct   FAIL      0 us
Byte Array   FAIL 0,   FAIL 1,   FAIL 2,   FAIL 3,   FAIL 4,   FAIL 5,   FAIL 6,   FAIL 7,   FAIL 8,   FAIL 9,   FAIL 10,   FAIL 11,   FAIL 12,   FAIL 13,   FAIL 14,   FAIL 15,   FAIL 16,   FAIL 17,   FAIL 18,   FAIL 19,   FAIL 20,   FAIL 21,   FAIL 22,   FAIL 23,   FAIL 24,   FAIL 25,   FAIL 26,   FAIL 27,   FAIL 28,   FAIL 29,   FAIL 30,   FAIL 31,   FAIL 32,   FAIL 33,   FAIL 34,   FAIL 35,   FAIL 36,   FAIL 37,   FAIL 38,   FAIL 39,   FAIL 40,   FAIL 41,   FAIL 42,   FAIL 43,   FAIL 44,   FAIL 45,   FAIL 46,   FAIL 47,   FAIL 48,   FAIL 49,   FAIL 50,   FAIL 51,   FAIL 52,   FAIL 53,   FAIL 54,   FAIL 55,   FAIL 56,   FAIL 57,   FAIL 58,   FAIL 59,   FAIL 60,   FAIL 61,   FAIL 62,   FAIL 63,   FAIL 64,   FAIL 65,   FAIL 66,   FAIL 67,   FAIL 68,   FAIL 69,   FAIL 70,   FAIL 71,   FAIL 72,   FAIL 73,   FAIL 74,   FAIL 75,   FAIL 76,   FAIL 77,   FAIL 78,   FAIL 79,   FAIL 80,   FAIL 81,   FAIL 82,   FAIL 83,   FAIL 84,   FAIL 85,   FAIL 86,   FAIL 87,   FAIL 88,   FAIL 89,   FAIL 90,   FAIL 91,   FAIL 92,   FAIL 93,   FAIL 94,   FAIL 95,   FAIL 96,   FAIL 97,   FAIL 98,   FAIL 99,   FAIL 100,   FAIL 101,   FAIL 102,   FAIL 103,   FAIL 104,   FAIL 105,   FAIL 106,   FAIL 107,   FAIL 108,   FAIL 109,   FAIL 110,   FAIL 111,   FAIL 112,   FAIL 113,   FAIL 114,   FAIL 115,   FAIL 116,   FAIL 117,   FAIL 118,   FAIL 119,   FAIL 120,   FAIL 121,   FAIL 122,   FAIL 123,   FAIL 124,   FAIL 125,   FAIL 126,   FAIL 127,   FAIL 128,   FAIL 129,   FAIL 130,   FAIL 131,   FAIL 132,   FAIL 133,   FAIL 134,   FAIL 135,   FAIL 136,   FAIL 137,   FAIL 138,   FAIL 139,   FAIL 140,   FAIL 141,   FAIL 142,   FAIL 143,   FAIL 144,   FAIL 145,   FAIL 146,   FAIL 147,   FAIL 148,   FAIL 149,   FAIL 150,   FAIL 151,   FAIL 152,   FAIL 153,   FAIL 154,   FAIL 155,   FAIL 156,   FAIL 157,   FAIL 158,   FAIL 159,   FAIL 160,   FAIL 161,   FAIL 162,   FAIL 163,   FAIL 164,   FAIL 165,   FAIL 166,   FAIL 167,   FAIL 168,   FAIL 169,   FAIL 170,   FAIL 171,   FAIL 172,   FAIL 173,   FAIL 174,   FAIL 175,   FAIL 176,   FAIL 177,   FAIL 178,   FAIL 179,   FAIL 180,   FAIL 181,   FAIL 182,   FAIL 183,   FAIL 184,   FAIL 185,   FAIL 186,   FAIL 187,   FAIL 188,   FAIL 189,   FAIL 190,   FAIL 191,   FAIL 192,   FAIL 193,   FAIL 194,   FAIL 195,   FAIL 196,   FAIL 197,   FAIL 198,   FAIL 199,   FAIL 200,   FAIL 201,   FAIL 202,   FAIL 203,   FAIL 204,   FAIL 205,   FAIL 206,   FAIL 207,   FAIL 208,   FAIL 209,   FAIL 210,   FAIL 211,   FAIL 212,   FAIL 213,   FAIL 214,   FAIL 215,   FAIL 216,   FAIL 217,   FAIL 218,   FAIL 219,   FAIL 220,   FAIL 221,   FAIL 222,   FAIL 223,   FAIL 224,   FAIL 225,   FAIL 226,   FAIL 227,   FAIL 228,   FAIL 229,   FAIL 230,   FAIL 231,   FAIL 232,   FAIL 233,   FAIL 234,   FAIL 235,   FAIL 236,   FAIL 237,   FAIL 238,   FAIL 239,   FAIL 240,   FAIL 241,   FAIL 242,   FAIL 243,   FAIL 244,   FAIL 245,   FAIL 246,   FAIL 247,   FAIL 248,   FAIL 249,   FAIL 250,   FAIL 251,   FAIL 252,   FAIL 253,   FAIL 254,   PASS      0 us
String   FAIL      0 us
Title: Re: SPIMemory library - Formerly SPIFlash - now supports basic SFDP!
Post by: siva_iot on Jul 20, 2018, 07:55 am
Im using this library for ESP8266 nodemcu with winbond external flash w25q32f but im frequently faced WDT reset. what should i do..? please help me
Title: Re: SPIMemory library - Formerly SPIFlash - now supports basic SFDP!
Post by: Marzogh on Aug 09, 2018, 06:42 am
Hi guys,

My apologies for the long delay in replying. I was away for health reasons and am slowly transitioning back into normality.

@walterpre & @BigEyetuna The problem with the SST26 series is top priority and I will try and get this sorted within a week and keep you posted here.

@siva_iot I find that WDT reset usually happens when your code does not allow the ESP8266 to carry out essential background functions. make sure you have enough delay() statements at the right places in your code. the delay() function in the ESP8266 is different to the normal one used for ATmega or ARM boards and lets background processes run while waiting for user code to execute.

@jaholmes The simplest way would be to use the built in readByteArray()/writeByteArray() or readCharArray()/writeCharArray() functions. They let you define the size of the block of data you want read/written - sequentially - and are very fast.
Title: Re: SPIMemory library - Formerly SPIFlash - now supports basic SFDP!
Post by: Marzogh on Aug 10, 2018, 02:53 am
@walterpre & @BigEyetuna This issue has been addressed with the code in the development branch on GitHub. I will roll these changes into the next release of the library
Title: Re: SPIMemory library - Formerly SPIFlash - now supports basic SFDP!
Post by: Srmojo on Aug 22, 2018, 10:54 pm
hello @Marzogh.

Im having some issues with the SPImemory library, specifically it doesn't work.

Hardware:
Adafruit Feather adalogger
W25Q64JV

Wiring:
1cs    ----> pin11
2DO   ----> MISO
3WP   ----> VCC 3.3v
4GND  ----> GND
5DI     ----> MOSI
6CLK   ----> SCK
7HOLD ----> VCC 3.3v
8VCC   ----> VCC 3.3v

FlashDiagnostics line 40 has been changed to:
     SPIFlash flash(11);

I have some very basic code which works fine to manually handle reading and writing to the flash chip so I know it is not a hardware or wiring issue, but I would like to implement your library since it seems to work so well for others. I have tried version 3.2.1 and 3.2.0 to no avail.


Obviosuly it thinks the chip is not powered on so all of the other tests will fail.

getAddressex only returns the serial.print lines with blank spaces (0s?)where values should be.


Any help is appreciated.

The output is below
Code: [Select]

Initialising..........
Chip Diagnostics initiated.

Unable to identify chip. Are you sure this chip is supported?
Chip details:
If this does not help resolve/clarify this issue, please raise an issue at http://www.github.com/Marzogh/SPIMemory/issues with the details of what your were doing when this error occurred

SPIMemory Library version: 3.2.1

JEDEC ID: 0x8FFF8F
Man ID: 0x8F
Memory ID: 0xFF
Capacity: 0
Max Pages: 0

-----------------------------------------------------------------------------------------------------------------------------
 Testing library code
-----------------------------------------------------------------------------------------------------------------------------
 Function Test result     Runtime
-----------------------------------------------------------------------------------------------------------------------------
 Power Down   PASS      66 us
 Power Up   FAIL

 Erase Chip The Flash chip is currently powered down.
   FAIL
 Erase 72KB The Flash chip is currently powered down.
   FAIL
 Erase 64KB The Flash chip is currently powered down.
   FAIL
 Erase 32KB The Flash chip is currently powered down.
   FAIL
 Erase 4KB The Flash chip is currently powered down.
   FAIL
-----------------------------------------------------------------------------------------------------------------------------
 Data type I/O Result      Write time      Read time
-----------------------------------------------------------------------------------------------------------------------------
The Flash chip is currently powered down.
The Flash chip is currently powered down.
 Byte   FAIL 0 us 4.251 s
The Flash chip is currently powered down.
The Flash chip is currently powered down.
 Char   FAIL 0 us 4.292 s
The Flash chip is currently powered down.
The Flash chip is currently powered down.
 Word   FAIL 0 us 4.333 s
The Flash chip is currently powered down.
The Flash chip is currently powered down.
 Short   FAIL 0 us 4.374 s
The Flash chip is currently powered down.
The Flash chip is currently powered down.
 ULong   FAIL 0 us 4.415 s
The Flash chip is currently powered down.
The Flash chip is currently powered down.
 Long   FAIL 0 us 4.456 s
The Flash chip is currently powered down.
The Flash chip is currently powered down.
 Float   FAIL 0 us 4.497 s
The Flash chip is currently powered down.
The Flash chip is currently powered down.
 Struct   FAIL 0 us 4.539 s
The Flash chip is currently powered down.
The Flash chip is currently powered down.
 Byte Array   FAIL 0,   FAIL 1,   FAIL 2,   FAIL 3,   FAIL 4,   FAIL 5,   FAIL 6,   FAIL 7,   FAIL 8,   FAIL 9,   FAIL 10,   FAIL 11,   FAIL 12,   FAIL 13,   FAIL 14,   FAIL 15,   FAIL 16,   FAIL 17,   FAIL 18,   FAIL 19,   FAIL 20,   FAIL 21,   FAIL 22,   FAIL 23,   FAIL 24,   FAIL 25,   FAIL 26,   FAIL 27,   FAIL 28,   FAIL 29,   FAIL 30,   FAIL 31,   FAIL 32,   FAIL 33,   FAIL 34,   FAIL 35,   FAIL 36,   FAIL 37,   FAIL 38,   FAIL 39,   FAIL 40,   FAIL 41,   FAIL 42,   FAIL 43,   FAIL 44,   FAIL 45,   FAIL 46,   FAIL 47,   FAIL 48,   FAIL 49,   FAIL 50,   FAIL 51,   FAIL 52,   FAIL 53,   FAIL 54,   FAIL 55,   FAIL 56,   FAIL 57,   FAIL 58,   FAIL 59,   FAIL 60,   FAIL 61,   FAIL 62,   FAIL 63,   FAIL 64,   FAIL 65,   FAIL 66,   FAIL 67,   FAIL 68,   FAIL 69,   FAIL 70,   FAIL 71,   FAIL 72,   FAIL 73,   FAIL 74,   FAIL 75,   FAIL 76,   FAIL 77,   FAIL 78,   FAIL 79,   FAIL 80,   FAIL 81,   FAIL 82,   FAIL 83,   FAIL 84,   FAIL 85,   FAIL 86,   FAIL 87,   FAIL 88,   FAIL 89,   FAIL 90,   FAIL 91,   FAIL 92,   FAIL 93,   FAIL 94,   FAIL 95,   FAIL 96,   FAIL 97,   FAIL 98,   FAIL 99,   FAIL 100,   FAIL 101,   FAIL 102,   FAIL 103,   FAIL 104,   FAIL 105,   FAIL 106,   FAIL 107,   FAIL 108,   FAIL 109,   FAIL 110,   FAIL 111,   FAIL 112,   FAIL 113,   FAIL 114,   FAIL 115,   FAIL 116,   FAIL 117,   FAIL 118,   FAIL 119,   FAIL 120,   FAIL 121,   FAIL 122,   FAIL 123,   FAIL 124,   FAIL 125,   FAIL 126,   FAIL 127,   FAIL 128,   FAIL 129,   FAIL 130,   FAIL 131,   FAIL 132,   FAIL 133,   FAIL 134,   FAIL 135,   FAIL 136,   FAIL 137,   FAIL 138,   FAIL 139,   FAIL 140,   FAIL 141,   FAIL 142,   FAIL 143,   FAIL 144,   FAIL 145,   FAIL 146,   FAIL 147,   FAIL 148,   FAIL 149,   FAIL 150,   FAIL 151,   FAIL 152,   FAIL 153,   FAIL 154,   FAIL 155,   FAIL 156,   FAIL 157,   FAIL 158,   FAIL 159,   FAIL 160,   FAIL 161,   FAIL 162,   FAIL 163,   FAIL 164,   FAIL 165,   FAIL 166,   FAIL 167,   FAIL 168,   FAIL 169,   FAIL 170,   FAIL 171,   FAIL 172,   FAIL 173,   FAIL 174,   FAIL 175,   FAIL 176,   FAIL 177,   FAIL 178,   FAIL 179,   FAIL 180,   FAIL 181,   FAIL 182,   FAIL 183,   FAIL 184,   FAIL 185,   FAIL 186,   FAIL 187,   FAIL 188,   FAIL 189,   FAIL 190,   FAIL 191,   FAIL 192,   FAIL 193,   FAIL 194,   FAIL 195,   FAIL 196,   FAIL 197,   FAIL 198,   FAIL 199,   FAIL 200,   FAIL 201,   FAIL 202,   FAIL 203,   FAIL 204,   FAIL 205,   FAIL 206,   FAIL 207,   FAIL 208,   FAIL 209,   FAIL 210,   FAIL 211,   FAIL 212,   FAIL 213,   FAIL 214,   FAIL 215,   FAIL 216,   FAIL 217,   FAIL 218,   FAIL 219,   FAIL 220,   FAIL 221,   FAIL 222,   FAIL 223,   FAIL 224,   FAIL 225,   FAIL 226,   FAIL 227,   FAIL 228,   FAIL 229,   FAIL 230,   FAIL 231,   FAIL 232,   FAIL 233,   FAIL 234,   FAIL 235,   FAIL 236,   FAIL 237,   FAIL 238,   FAIL 239,   FAIL 240,   FAIL 241,   FAIL 242,   FAIL 243,   FAIL 244,   FAIL 245,   FAIL 246,   FAIL 247,   FAIL 248,   FAIL 249,   FAIL 250,   FAIL 251,   FAIL 252,   FAIL 253,   FAIL 254,   FAIL 255,   PASS 0 us 4.581 s
The Flash chip is currently powered down.
The Flash chip is currently powered down.
 String   FAIL 0 us 4.719 s
-----------------------------------------------------------------------------------------------------------------------------


Title: Re: SPIMemory library - Formerly SPIFlash - now supports basic SFDP!
Post by: timoteo_mendes on Sep 08, 2018, 10:38 am
Hello Srmojo,

Did you had any luck with your board?
I do have one also and would like to implement the library.
Thanks.

Tim
Title: Re: SPIMemory library - Formerly SPIFlash - now supports basic SFDP!
Post by: jacky4566 on Oct 24, 2018, 12:45 am
OK ive am at my wits end and come to the masters for help.

I have a Teensy LC and trying to communicate with a SST26VF064B Flash chip.

Using only raw SPI commands I can communicate with the chip. Get ID and read the status regs. But I cant write! Whey do they make it so damn hard to write!

Marzogh perhaps you can lend some insight into my SST26 chip.

Starting factory fresh with SPIMemory Library this is the result of the test code:

Code: [Select]
Initialising..........
Chip Diagnostics initiated.

No Chip size defined by user. Automated identification initiated.
Chip identified. This chip is fully supported by the library.

SPIMemory Library version: 3.2.1

JEDEC ID: 0xBF2643
Man ID: 0xBF
Memory ID: 0x26
Capacity: 8388608
Max Pages: 0
Unique ID: 04294967040, 0xFFFFFFFFFFFFFF00
-----------------------------------------------------------------------------------------------------------------------------
Testing library code
-----------------------------------------------------------------------------------------------------------------------------
Function Test result      Runtime
-----------------------------------------------------------------------------------------------------------------------------
Power Down This function is not supported by the flash memory hardware.
   FAIL Not all chips support power down. Check your datasheet.
Power Up    PASS       44 us

Erase Chip    PASS       60 us
Erase 72KB    PASS       176 us
Erase 64KB    PASS       68 us
Erase 32KB    PASS       76 us
Erase 4KB    PASS       76 us
-----------------------------------------------------------------------------------------------------------------------------
Data type I/O Result       Write time       Read time
-----------------------------------------------------------------------------------------------------------------------------
Byte    FAIL 0 us 40 us
Char    FAIL 0 us 40 us
Word    FAIL 0 us 44 us
Short    FAIL 0 us 40 us
ULong    FAIL 0 us 44 us
Long    FAIL 0 us 48 us
Float    FAIL 0 us 48 us
Write Function has failed errorcheck.
If this does not help resolve/clarify this issue, please raise an issue at http://www.github.com/Marzogh/SPIMemory/issues with the details of what your were doing when this error occurred
Struct    FAIL 0 us 112 us
Byte Array    FAIL 0,    FAIL 1,    FAIL 2,    FAIL 3,    FAIL 4,    FAIL 5,    FAIL 6,    FAIL 7,    FAIL 8,    FAIL 9,    FAIL 10,    FAIL 11,    FAIL 12,    FAIL 13,    FAIL 14,    FAIL 15,    FAIL 16,    FAIL 17,    FAIL 18,    FAIL 19,    FAIL 20,    FAIL 21,    FAIL 22,    FAIL 23,    FAIL 24,    FAIL 25,    FAIL 26,    FAIL 27,    FAIL 28,    FAIL 29,    FAIL 30,    FAIL 31,    FAIL 32,    FAIL 33,    FAIL 34,    FAIL 35,    FAIL 36,    FAIL 37,    FAIL 38,    FAIL 39,    FAIL 40,    FAIL 41,    FAIL 42,    FAIL 43,    FAIL 44,    FAIL 45,    FAIL 46,    FAIL 47,    FAIL 48,    FAIL 49,    FAIL 50,    FAIL 51,    FAIL 52,    FAIL 53,    FAIL 54,    FAIL 55,    FAIL 56,    FAIL 57,    FAIL 58,    FAIL 59,    FAIL 60,    FAIL 61,    FAIL 62,    FAIL 63,    FAIL 64,    FAIL 65,    FAIL 66,    FAIL 67,    FAIL 68,    FAIL 69,    FAIL 70,    FAIL 71,    FAIL 72,    FAIL 73,    FAIL 74,    FAIL 75,    FAIL 76,    FAIL 77,    FAIL 78,    FAIL 79,    FAIL 80,    FAIL 81,    FAIL 82,    FAIL 83,    FAIL 84,    FAIL 85,    FAIL 86,    FAIL 87,    FAIL 88,    FAIL 89,    FAIL 90,    FAIL 91,    FAIL 92,    FAIL 93,    FAIL 94,    FAIL 95,    FAIL 96,    FAIL 97,    FAIL 98,    FAIL 99,    FAIL 100,    FAIL 101,    FAIL 102,    FAIL 103,    FAIL 104,    FAIL 105,    FAIL 106,    FAIL 107,    FAIL 108,    FAIL 109,    FAIL 110,    FAIL 111,    FAIL 112,    FAIL 113,    FAIL 114,    FAIL 115,    FAIL 116,    FAIL 117,    FAIL 118,    FAIL 119,    FAIL 120,    FAIL 121,    FAIL 122,    FAIL 123,    FAIL 124,    FAIL 125,    FAIL 126,    FAIL 127,    FAIL 128,    FAIL 129,    FAIL 130,    FAIL 131,    FAIL 132,    FAIL 133,    FAIL 134,    FAIL 135,    FAIL 136,    FAIL 137,    FAIL 138,    FAIL 139,    FAIL 140,    FAIL 141,    FAIL 142,    FAIL 143,    FAIL 144,    FAIL 145,    FAIL 146,    FAIL 147,    FAIL 148,    FAIL 149,    FAIL 150,    FAIL 151,    FAIL 152,    FAIL 153,    FAIL 154,    FAIL 155,    FAIL 156,    FAIL 157,    FAIL 158,    FAIL 159,    FAIL 160,    FAIL 161,    FAIL 162,    FAIL 163,    FAIL 164,    FAIL 165,    FAIL 166,    FAIL 167,    FAIL 168,    FAIL 169,    FAIL 170,    FAIL 171,    FAIL 172,    FAIL 173,    FAIL 174,    FAIL 175,    FAIL 176,    FAIL 177,    FAIL 178,    FAIL 179,    FAIL 180,    FAIL 181,    FAIL 182,    FAIL 183,    FAIL 184,    FAIL 185,    FAIL 186,    FAIL 187,    FAIL 188,    FAIL 189,    FAIL 190,    FAIL 191,    FAIL 192,    FAIL 193,    FAIL 194,    FAIL 195,    FAIL 196,    FAIL 197,    FAIL 198,    FAIL 199,    FAIL 200,    FAIL 201,    FAIL 202,    FAIL 203,    FAIL 204,    FAIL 205,    FAIL 206,    FAIL 207,    FAIL 208,    FAIL 209,    FAIL 210,    FAIL 211,    FAIL 212,    FAIL 213,    FAIL 214,    FAIL 215,    FAIL 216,    FAIL 217,    FAIL 218,    FAIL 219,    FAIL 220,    FAIL 221,    FAIL 222,    FAIL 223,    FAIL 224,    FAIL 225,    FAIL 226,    FAIL 227,    FAIL 228,    FAIL 229,    FAIL 230,    FAIL 231,    FAIL 232,    FAIL 233,    FAIL 234,    FAIL 235,    FAIL 236,    FAIL 237,    FAIL 238,    FAIL 239,    FAIL 240,    FAIL 241,    FAIL 242,    FAIL 243,    FAIL 244,    FAIL 245,    FAIL 246,    FAIL 247,    FAIL 248,    FAIL 249,    FAIL 250,    FAIL 251,    FAIL 252,    FAIL 253,    FAIL 254,    PASS 0 us 512 us
Write Function has failed errorcheck.
If this does not help resolve/clarify this issue, please raise an issue at http://www.github.com/Marzogh/SPIMemory/issues with the details of what your were doing when this error occurred
String    FAIL 0 us 84 us


I have disable the WP and HOLD pins with the IOC Register but still not getting anywhere. What is next to investigate?
Thank you!
Title: Re: SPIMemory library - Formerly SPIFlash - now supports basic SFDP!
Post by: amirezz on Nov 07, 2018, 03:40 pm
hello thanks for your great work

are that library support  sst25vf010a or LE25U40CMDTWG   cause those are the parts i have

i also try to use sst25vf010a but it return 00h as chip id and manufacture id

thanks in advance
Title: Re: SPIMemory library - Formerly SPIFlash - now supports basic SFDP!
Post by: zhliao on Jan 04, 2019, 06:26 pm
hello @Marzogh.

Im having some issues with the SPImemory library, specifically it doesn't work for the writing operations.

Hardware:
Arduino UNO
W25Q80BV

Wiring:
1cs    ----> pin10
2DO   ----> MISO
3WP   ----> 3.3v
4GND  ----> GND
5DI     ----> MOSI
6CLK   ----> SCK
7HOLD ----> 3.3v
8VCC   ----> 3.3v

I interfaced the Arduino and Flash using the level shifter.
 and FlashDiagnostics line 40 has been changed to:
     SPIFlash flash(10);

The library version 3.2.1 and 3.2.0 both do not work.


Any help is appreciated.

The output is below



Code: [Select]
Initialising..........

SPIMemory Library version: 3.2.1

JEDEC ID: 0xEF4014
Man ID: 0xEF
Memory ID: 0x40
Capacity: 1048576
Max Pages: 4294967295
Unique ID: 2815588997737984, 0x60A88003660B2E00
-----------------------------------------------------------------------------------------------------------------------------
Testing library code
-----------------------------------------------------------------------------------------------------------------------------
Function Test result      Runtime
-----------------------------------------------------------------------------------------------------------------------------
Power Down    FAIL Not all chips support power down. Check your datasheet.
Power Up    PASS       0 us

Erase Chip    PASS       0 us
Erase 72KB    PASS       0 us
Erase 64KB    PASS       0 us
Erase 32KB    PASS       0 us
Erase 4KB    PASS       0 us
-----------------------------------------------------------------------------------------------------------------------------
Data type I/O Result       Write time       Read time
-----------------------------------------------------------------------------------------------------------------------------
Byte    FAIL       0 us
Char    FAIL       0 us
Word    FAIL       0 us
Short    FAIL       0 us
ULong    FAIL       0 us
Long    FAIL       0 us
Float    FAIL       0 us
Struct    FAIL       0 us
Byte Array    FAIL 1,    FAIL 2,    FAIL 3,    FAIL 4,    FAIL 5,    FAIL 6,    FAIL 7,    FAIL 8,    FAIL 9,    FAIL 10,    FAIL 11,    FAIL 12,    FAIL 13,    FAIL 14,    FAIL 15,    FAIL 16,    FAIL 17,    FAIL 18,    FAIL 19,    FAIL 20,    FAIL 21,    FAIL 22,    FAIL 23,    FAIL 24,    FAIL 25,    FAIL 26,    FAIL 27,    FAIL 28,    FAIL 29,    FAIL 30,    FAIL 31,    FAIL 32,    FAIL 33,    FAIL 34,    FAIL 35,    FAIL 36,    FAIL 37,    FAIL 38,    FAIL 39,    FAIL 40,    FAIL 41,    FAIL 42,    FAIL 43,    FAIL 44,    FAIL 45,    FAIL 46,    FAIL 47,    FAIL 48,    FAIL 49,    FAIL 50,    FAIL 51,    FAIL 52,    FAIL 53,    FAIL 54,    FAIL 55,    FAIL 56,    FAIL 57,    FAIL 58,    FAIL 59,    FAIL 60,    FAIL 61,    FAIL 62,    FAIL 63,    FAIL 64,    FAIL 65,    FAIL 66,    FAIL 67,    FAIL 68,    FAIL 69,    FAIL 70,    FAIL 71,    FAIL 72,    FAIL 73,    FAIL 74,    FAIL 75,    FAIL 76,    FAIL 77,    FAIL 78,    FAIL 79,    FAIL 80,    FAIL 81,    FAIL 82,    FAIL 83,    FAIL 84,    FAIL 85,    FAIL 86,    FAIL 87,    FAIL 88,    FAIL 89,    FAIL 90,    FAIL 91,    FAIL 92,    FAIL 93,    FAIL 94,    FAIL 95,    FAIL 96,    FAIL 97,    FAIL 98,    FAIL 99,    FAIL 100,    FAIL 101,    FAIL 102,    FAIL 103,    FAIL 104,    FAIL 105,    FAIL 106,    FAIL 107,    FAIL 108,    FAIL 109,    FAIL 110,    FAIL 111,    FAIL 112,    FAIL 113,    FAIL 114,    FAIL 115,    FAIL 116,    FAIL 117,    FAIL 118,    FAIL 119,    FAIL 120,    FAIL 121,    FAIL 122,    FAIL 123,    FAIL 124,    FAIL 125,    FAIL 126,    FAIL 127,    FAIL 128,    FAIL 129,    FAIL 130,    FAIL 131,    FAIL 132,    FAIL 133,    FAIL 134,    FAIL 135,    FAIL 136,    FAIL 137,    FAIL 138,    FAIL 139,    FAIL 140,    FAIL 141,    FAIL 142,    FAIL 143,    FAIL 144,    FAIL 145,    FAIL 146,    FAIL 147,    FAIL 148,    FAIL 149,    FAIL 150,    FAIL 151,    FAIL 152,    FAIL 153,    FAIL 154,    FAIL 155,    FAIL 156,    FAIL 157,    FAIL 158,    FAIL 159,    FAIL 160,    FAIL 161,    FAIL 162,    FAIL 163,    FAIL 164,    FAIL 165,    FAIL 166,    FAIL 167,    FAIL 168,    FAIL 169,    FAIL 170,    FAIL 171,    FAIL 172,    FAIL 173,    FAIL 174,    FAIL 175,    FAIL 176,    FAIL 177,    FAIL 178,    FAIL 179,    FAIL 180,    FAIL 181,    FAIL 182,    FAIL 183,    FAIL 184,    FAIL 185,    FAIL 186,    FAIL 187,    FAIL 188,    FAIL 189,    FAIL 190,    FAIL 191,    FAIL 192,    FAIL 193,    FAIL 194,    FAIL 195,    FAIL 196,    FAIL 197,    FAIL 198,    FAIL 199,    FAIL 200,    FAIL 201,    FAIL 202,    FAIL 203,    FAIL 204,    FAIL 205,    FAIL 206,    FAIL 207,    FAIL 208,    FAIL 209,    FAIL 210,    FAIL 211,    FAIL 212,    FAIL 213,    FAIL 214,    FAIL 215,    FAIL 216,    FAIL 217,    FAIL 218,    FAIL 219,    FAIL 220,    FAIL 221,    FAIL 222,    FAIL 223,    FAIL 224,    FAIL 225,    FAIL 226,    FAIL 227,    FAIL 228,    FAIL 229,    FAIL 230,    FAIL 231,    FAIL 232,    FAIL 233,    FAIL 234,    FAIL 235,    FAIL 236,    FAIL 237,    FAIL 238,    FAIL 239,    FAIL 240,    FAIL 241,    FAIL 242,    FAIL 243,    FAIL 244,    FAIL 245,    FAIL 246,    FAIL 247,    FAIL 248,    FAIL 249,    FAIL 250,    FAIL 251,    FAIL 252,    FAIL 253,    FAIL 254,    FAIL 255,    PASS       0 us
String    FAIL       0 us
-----------------------------------------------------------------------------------------------------------------------------
To see function runtimes ncomment RUNDIAGNOSTIC in SPIMemory.h.
Title: Re: SPIMemory library - Formerly SPIFlash - now supports basic SFDP!
Post by: ruslan_x3m on Jan 09, 2019, 09:52 am
Hi, Im using ESP8266, then executing flash.begin() and without spi flash connected ... >> getting WDT reset. I cant add delay(0) ... is in your library ...

... with spi flash inserted (connected) - all ok.

Code: [Select]

  ESP.wdtDisable();
  ESP.wdtFeed();

  if (!flash.begin()) {
    Serial.println(flash.error(VERBOSE));
  }

  ESP.wdtEnable(1000);


same with wdtDisable() after ~10 seconds  WDT reset .... your library stack in infinite loop on flash.begin()  .... any help ?



OK ... find the bug, in defines.h change  ... for esp8266 BUSY_TIMEOUT set ~2 seconds (was 1000 seconds)

Code: [Select]
// #define BUSY_TIMEOUT  1000000000L
#if defined (ARDUINO_ARCH_ESP8266)
#define BUSY_TIMEOUT  2000000L
#else
#define BUSY_TIMEOUT  1000000000L
#endif


... now work ok




and may be in this code must be done some fixes:

Code: [Select]
// Polls the status register 1 until busy flag is cleared or timeout
 bool SPIFlash::_notBusy(uint32_t timeout) {
   _delay_us(WINBOND_WRITE_DELAY);
   uint32_t _time = micros();

   do {
     #if defined (ARDUINO_ARCH_ESP8266)
     delay(0);
     #endif
     _readStat1();
     if (!(stat1 & BUSY))
     {
       return true;
     }

   } while ((micros() - _time) < timeout);
   if (timeout <= (micros() - _time)) {
     _troubleshoot(CHIPBUSY);
     return false;
   }
   return true;
 }



change code >

do {
     #if defined (ARDUINO_ARCH_ESP8266)
     delay(0);
     #endif
     _readStat1();





same with cheapErase() fix

Code: [Select]
//Erases whole chip. Think twice before using.
bool SPIFlash::eraseChip(void) {
  #ifdef RUNDIAGNOSTIC
    _spifuncruntime = micros();
  #endif
 if(_isChipPoweredDown() || !_notBusy() || !_writeEnable()) {
    return false;
  }

 _beginSPI(chipErase.opcode);
  _endSPI();

 while(_readStat1() & BUSY) {
  #if defined (ARDUINO_ARCH_ESP8266)
     delay(0);
  #endif
    //_delay_us(30000L);
  }
  _endSPI();

  #ifdef RUNDIAGNOSTIC
    _spifuncruntime = micros() - _spifuncruntime;
  #endif
 return true;

}
Title: Re: SPIMemory library - Formerly SPIFlash - now supports basic SFDP!
Post by: Marzogh on Apr 20, 2019, 08:21 am

Just pushed an update through to v3.3.0 with the following changes:

- The SPIMemory now supports SPI FRAM (one chip for now, but the list is going to grow.  :) )

Bugs squashed:
- Fixed a major bug causing issues with page boundaries in writeAnything and writeStr. Thanks for your help @jacky4566 (Issue #151 (https://github.com/Marzogh/SPIMemory/issues/151))
- Fixed a major bug with reading Strings (Issue #143 (https://github.com/Marzogh/SPIMemory/issues/143))
- Fixes a bug by initialising the SPIBusState to false
- Fixes bug that causes ballooning of pagesize when SFDP is not read. This is because no default _pageSize value was set in this scenario. This has now been fixed.
- Fixes a major bug in how SFDP data is used to calculate chip capacity. The previous version of the library returned a wrong value. This has now been fixed. Refer to comments in _getSFDPFlashParam(void) for further details.

Enhancements:

- Reduce SRAM footprint when running Diagnostics.ino. Thanks @rambo (PR #157 (https://github.com/Marzogh/SPIMemory/pull/151))
- Officially supports the ESP32 (tested on the ESP32 Feather)
- Now supports FRAM memory chips via the SPIFram constructor
- Changed Diagnostics output in _chipID() to match situation better.
- Fixed _chipID() to run more efficiently.


New flash memory chips supported:
- GD25Q16C from Giga devices (Used on the Adafruit ItsyBitsy M0 Express)
- W25Q64JV from Winbond
- SST26VF016B & SST26VF032B from Microchip.

New Fram memory chips supported:
- FM25W256 from Cypress


Work on proper documentation continues. As polaroi8d pointed out here (https://github.com/Marzogh/SPIMemory/issues/129), the old ReadMe was getting far too unwieldy and the Github Wiki is not the easiest thing to poke around. I hope to have the documentation done soon - (Rst + Sphinx). Check out the progress of the documentation here! (http://spimemory.readthedocs.io/en/latest/) Any recommendations are welcome  8)
Title: Re: SPIMemory library - Formerly SPIFlash - now supports SPI FRAM as well! :)
Post by: Marzogh on Apr 20, 2019, 03:56 pm
@walterpre (https://forum.arduino.cc/index.php?topic=324009.msg3780862#msg3780862),  @BigEyetuna (https://forum.arduino.cc/index.php?topic=324009.msg3811967#msg3811967) & @jacky4566 (https://forum.arduino.cc/index.php?topic=324009.msg3917716#msg3917716) : jetty840 identified the issue (https://github.com/Marzogh/SPIMemory/issues/164) with the SST26 series and its been fixed with v3.3.0.

@Srmojo (https://forum.arduino.cc/index.php?topic=324009.msg3849055#msg3849055) & @timoteo_mendes (https://forum.arduino.cc/index.php?topic=324009.msg3866612#msg3866612): I've just tested the latest version of the library - v3.3.0 - with the W25Q64JV on the Adafruit 328p feather and it works fine. I do not have an Adalogger handy, but AFAIK, the both of them use the same µC - hope it helps!

@amirezz (https://forum.arduino.cc/index.php?topic=324009.msg3936394#msg3936394): There was a bug in v3.2.1 that prevented the library from writing to the SST25 and SST26 series. This has been fixed in v3.3.0. Also, the library supports the LE25U40C.

@zhliao (https://forum.arduino.cc/index.php?topic=324009.msg4004644#msg4004644): Could you check and confirm that v3.3.0 also causes the same issue? If it does, please let me know and I will take a look at it right away.
Title: Re: SPIMemory library - Formerly SPIFlash - now supports SPI FRAM as well! :)
Post by: jacky4566 on Apr 21, 2019, 02:39 am
Marzogh you can probably update the compatibility tables. I haven't thoughly tested but it does seem to work just fine with Teensy 3.2 and Teensy LC.
I am also using the Adesto AT25SL641. Which won't be very popular at 1.8v but it passed all checks with the LC and works perfectly.
Title: Re: SPIMemory library - Formerly SPIFlash - now supports SPI FRAM as well! :)
Post by: Marzogh on Apr 21, 2019, 01:39 pm
@jacky4566: Thanks for the heads up. Its good to know its working with the Teensys and with the AT25SL641. Have you had to make any mods to get the library to run on the Teensy?
Title: Re: SPIMemory library - Formerly SPIFlash - now supports SPI FRAM as well! :)
Post by: jacky4566 on Apr 21, 2019, 07:10 pm
@jacky4566: Thanks for the heads up. Its good to know its working with the Teensys and with the AT25SL641. Have you had to make any mods to get the library to run on the Teensy?
No mods. Using default SPI pins since its a custom board I cant really test the alternate pins. CPU clock 48MHz, SPI clock speed 12MHz. Power down works fine as well.
Title: Re: SPIMemory library - Formerly SPIFlash - now supports SPI FRAM as well! :)
Post by: BobTrex on Apr 24, 2019, 01:25 pm
Any chance you will support CY15B104Q 4Mbit FRAM, I have one and have never got it working.

Thanks and Regards
Title: Re: SPIMemory library - Formerly SPIFlash - now supports SPI FRAM as well! :)
Post by: tfcroft4 on Apr 30, 2019, 05:39 pm
I have been able to run the FlashDiagnostics on the Sparkfun RedBoard Turbo. A M0 processor with W25Q32BV 32M-Bit Winbond memory chip. I had to modify the variant.h and variant.cpp files as Sparkfun had omitted to include Arduino access for the on board SPImemory.

I have posted details of the edits and a copy of the output obtained on the Sparkfun forum:

https://forum.sparkfun.com/viewtopic.php?f=145&t=49805 (https://forum.sparkfun.com/viewtopic.php?f=145&t=49805)

Thanks for the library
Ted
Title: Re: SPIMemory library - Formerly SPIFlash - now supports SPI FRAM as well! :)
Post by: Marzogh on May 10, 2019, 03:40 am
@tfcroft4 (https://forum.arduino.cc/index.php?topic=324009.msg4156553#msg4156553) Thank you for the heads up :) I'm glad the library works for you :smiley-grin:

@BobTrex (https://forum.arduino.cc/index.php?topic=324009.msg4148770#msg4148770) I add support for ICs based on the ones I can get my hands on. Please raise an 'feature request' issue on Github for support for this chip and I'll put it into the pipeline :)
Title: Re: SPIMemory library - Formerly SPIFlash - now supports SPI FRAM as well! :)
Post by: Marzogh on Jun 03, 2019, 05:10 am
Just pushed an update through to v3.4.0 with the following changes:


Bugs squashed:
- FastRead works properly now. All previous versions of the library has a FastRead bug that prevent it from doing what it was supposed to.

Enhancements:

-An alternate version of the constructor 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 issue #113 (https://github.com/Marzogh/SPIMemory/issues/113)
- Created new error code `NOCHIPSELECTDECLARED` for errors with declaring custom SPI pins.
- Using other SPI ports (HSPI, VSPI, SPI1, SPI2 etc.) is now also supported on ESP32 boards - along with SAMD and STM32 boards (supported since v3.0.0). Resolves issue #177 (https://github.com/Marzogh/SPIMemory/issues/177)
- The new version changes the way setClock() (http://(https://github.com/Marzogh/SPIMemory/wiki/Library-instantiation-functions#setclockclockspeed) works and allows for the definition of clock speed before the SPI Bus is instantiated. Refer to wiki (https://github.com/Marzogh/SPIMemory/wiki/Library-instantiation-functions#setclockclockspeed) for further details. Thanks @rambo.(PR #156 (https://github.com/Marzogh/SPIMemory/pull/156))

- Reduce SRAM footprint when running Diagnostics.ino. Thanks @rambo
- Officially supports the ESP32 (tested on the ESP32 Feather)
- Now supports FRAM memory chips via the SPIFram constructor
- Changed Diagnostics output in _chipID() to match situation better.
- Fixed _chipID() to run more efficiently.

New µCs supported:
- nRF52832 ARM Cortex M4F (Adafruit nRF52 Feather)
- STM32L0 ARM Cortex M0+ (Nucleo-L031K6)

New flash memory chips supported:
- MX25L4005 & MX25L4005 from Macronix



Work on proper documentation continues. As polaroi8d pointed out here (https://github.com/Marzogh/SPIMemory/issues/129), the old ReadMe was getting far too unwieldy and the Github Wiki is not the easiest thing to poke around. I hope to have the documentation done soon - (Rst + Sphinx). Check out the progress of the documentation here! (http://spimemory.readthedocs.io/en/latest/) Any recommendations are welcome  8)
Title: Re: SPIMemory library - Formerly SPIFlash - now supports SPI FRAM as well! :)
Post by: Cheetor on Jun 27, 2019, 04:48 am
Hi There
I'm in the process of designing a shield for an Arduino Due. and unfortunately after all our PCBs have been
manufactured I was shocked to find the Due has no EEPROM (I only need 90 bytes). Thats fine I thought, we
have plenty of SPI flash chips in the factory I can use.... only to notice the "4" SPI units the Due is supposed to have. One is connected to a silly header with 5V (instead of 3.3). I have to get my SPI working over some
pins that are actually on the regular pins. and I found the second SPI is only on the BGA version of the micro.
So I asked what about the other 2? Does your library support using the USARTs in SPI mod? and if so how?
Title: Re: SPIMemory library - Formerly SPIFlash - now supports SPI FRAM as well! :)
Post by: Etienne_07 on Jul 10, 2019, 11:40 am
Hi,

I didn't manage to make this library work on a NodeMCU v1.0 board, it uses an ESP12 (ESP8266 + 32Mbit Flash)). I don't understand as it's supposed to work with an Adafruit Feather HUZZAH board which is uses an ESP12 too.
I'm using the TestFlash example to test.
First I have to force the SPI to SPI_PINS_HSPI_OVERLAP mode, otherwise I get a watchdog reset.
Why is the SPI frequency set to 104 Mhz by default ? The Winbond-W25Q32 chip is not supposed to work above 80 MHz and the SPI library uses 40 Mhz...
The CS signal set to pin GPIO15 for the ARDUINO_ARCH_ESP8266, which is correct for user SPI, but on an ESP12 the SPI0 must be used (SPI_PINS_HSPI_OVERLAP mode), which has CS on GPIO11. When I try to change CS to 11 I get a watchdog reset.
I tried to access the flash directly without your library by trying to read Jedec ID, I can get all the signals correct (I think) except the SDIO_DATA3  (GPIO10) signal which is kept low, thus disabling the flash (this signal is connected to HOLD pin on the flash chip.
I compared to the signals I have when I call the SDK function spi_flash_get_id() (which works). If I try to force the SDIO_DATA3  (GPIO10) signal high in the code, I get a watchdog reset.
I've tried to post on the Espressif forum to ask for help, but after a few days my message has still not been validated by moderator...

I really don't know what to do now.
Title: Re: SPIMemory library - Formerly SPIFlash - now supports SPI FRAM as well! :)
Post by: Marzogh on Jul 14, 2019, 09:05 am
Hi There
I'm in the process of designing a shield for an Arduino Due. and unfortunately after all our PCBs have been
manufactured I was shocked to find the Due has no EEPROM (I only need 90 bytes). Thats fine I thought, we
have plenty of SPI flash chips in the factory I can use.... only to notice the "4" SPI units the Due is supposed to have. One is connected to a silly header with 5V (instead of 3.3). I have to get my SPI working over some
pins that are actually on the regular pins. and I found the second SPI is only on the BGA version of the micro.
So I asked what about the other 2? Does your library support using the USARTs in SPI mod? and if so how?
Hi Cheetor, The short answer is, I'm afraid not. Sorry. :( The latest version (3.4.0) does let you switch between existing SPI interfaces, so perhaps that might be helpful.
Title: Re: SPIMemory library - Formerly SPIFlash - now supports SPI FRAM as well! :)
Post by: Marzogh on Jul 14, 2019, 09:24 am
Hi Etienne, let me try to answer your questions in order:

Quote
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)[/u]