Go Down

Topic: SPIMemory library - Formerly SPIFlash - now supports basic SFDP! (Read 60690 times) previous topic - next topic

kucukkose

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


Gosh

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? 

Marzogh

@ 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]? 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?

Marzogh

#123
Mar 09, 2018, 06:36 am Last Edit: Mar 09, 2018, 06:47 am by Marzogh
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 raised an issue [#83] about the problems the name of this library was causing the users of his library - also called SPIFlash. The fact that this library is in the Arduino Library manager meant that his users were being asked to upgrade their version of SPIFlash when the libraries were actually different. I can understand how much of an annoyance this can be for a user.

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 series - and has developed a fantastic IoT protocol to use with them to add smarts to your home. In January this year, I finally got around to getting my hands on some of his boards and have been playing around with them. They are fantastic! I'd strongly recommend you check them out - if you haven't already done so.
I asked the Arduino developers if there was a way to migrate this library to a new name without breaking the upgrade path [Issue #6904] and was told that it was not possible. The only way is to pull my version of SPIFlash from the library manager and ask for a renamed version to be included in the library manager after.

So, this is what I have decided to do.:
  • The upcoming version - v3.1.0 - will be the last version to be released under the SPIFlash name.
  • Anyone downloading v3.1.0 of the library will be able to read this notice in the ReadMe file.
  • Anyone using v3.1.0 of the library will also see a notice in their Serial output directing them to the notice in the ReadMe file. (this can be removed by commenting out the "#define PRINTNAMECHANGEALERT" in "SPIFlash.h")
  • Version 3.2.0 will be released in a couple of months (in May most likely) under a new name. I'm currently thinking of calling it SPIMemory - suggestions are welcome.
  • SPIFlash will be removed from the library manager then and replaced with the new one

The only change will have to be made in end-user code will be to change the "#include SPIFlash.h" to "#include SPIMemory.h" (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.

enkoopa

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!

enkoopa

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();
}

enkoopa

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?

Marzogh

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.

aseelye

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!

Marzogh

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 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's fantastic Cave Pearl project. 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. :)

Marzogh

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

- Library name change notice 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

- An error with how _writeErrorCheck() worked has been resolved. Writing structs is now as stable as other functions are. Fixes Issue #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)

sikletiya

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

Marzogh

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!

rafamangualde@gmail.com

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?

Marzogh

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

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:

  • AFAIK, there is no Arduino IDE v1.8.10.0 - the latest version available as of now is 1.8.5.
  • Also, from what I can see in the esp-wroom-32 datasheet, GPIO10 is not exposed, so, I'm not sure which pin you have your CS connected to. Could you double check that please?

Go Up