Writing audio data to SPI flash

Started by Lensdigital, June 24, 2015, 04:24:35 PM

Lensdigital

Has anyone ever tried to write audio or any other data from computer to SPI flash? I want to use flash chips to hold small WAV files instead of SD Card... AVR will serve as a flash controller in this case... 
I'm fine if whole flash chip needs to be erased to write the data, as it will be embedded and mostly static audio data...

TomWS

#1
Quote from: Lensdigital on June 24, 2015, 04:24:35 PM
Has anyone ever tried to write audio or any other data from computer to SPI flash? I want to use flash chips to hold small WAV files instead of SD Card... AVR will serve as a flash controller in this case... 
I'm fine if whole flash chip needs to be erased to write the data, as it will be embedded and mostly static audio data...
I've saved all kinds of data in the non-bootstrap portion of the flash memory and it has gobs of room by program storage standards, but not so much by WAV file standards.  It's only 4Mbit total (512KByte).  You can fit a small WAV file in it, but not much.  You don't need to erase the whole thing, it can be erased in 4K or 32K blocks depending on your needs.  Check out the SPIFlash.h file for various interface methods....

Tom

Felix

#2
I have not tried audio data but the SPIFlash lib has all the basic functions that would allow it. You probably need to create your own little function that will take some stream of bytes and write it to the FLASH MEM sectors usign the lib block-write function: void writeBytes(uint32_t addr, const void* buf, uint16_t len);

FWIW I think WAV may be too big. You can probably store MP3 data if you have some way of decoding it with a decoder chip.
Also there are many other SPI FLASH chips that are much larger and have the same pinout and command set so you can get a 128 or 256mbit chip to store larger files. So you could solder one of those instead of the standard 4MBIT provided by LPL. THe caveat is that those larger chips can take a very long time to erase. The 4mbit chip is very fast.

TomWS

Quote from: Lensdigital on June 24, 2015, 04:24:35 PM
Has anyone ever tried to write audio or any other data from computer to SPI flash? I want to use flash chips to hold small WAV files instead of SD Card... AVR will serve as a flash controller in this case... 
I'm fine if whole flash chip needs to be erased to write the data, as it will be embedded and mostly static audio data...
Actually, the problem you may run into isn't whether you can store a WAV file into the Flash, but whether you can read out the chunks into the anemic memory available on the 328P...  It could very well be that there isn't enough room for the chunk buffers you'd need.

Tom

Felix

Quote from: TomWS on June 24, 2015, 09:01:47 PM
Actually, the problem you may run into isn't whether you can store a WAV file into the Flash, but whether you can read out the chunks into the anemic memory available on the 328P...  It could very well be that there isn't enough room for the chunk buffers you'd need.
Tom
There's always the MoteinoMEGA :)

Lensdigital

#5
Thanks! I'll give it a try! :)
Yeah I plan to use flash chip that can hold at least 10 Megabytes (maybe like this). 128 Megabit should yield 16 megabytes, right?
Reading back data shouldn't be an issue. WaveShield library does that, only it reads data from SD card, and I want it to read it from SPI flash :)

TomWS

Well, Adafruit recommends (https://learn.adafruit.com/adafruit-wave-shield-audio-shield-for-arduino/wavehc-library) at least an ATmega328 to use this library so I guess it works.  Note that this is without any other code running, eg (RFM69 library).  Please let us know when you get it running.

Reading and writing from SPIflash instead of SD card isn't an issue technically, but the SD library uses a file system to access its memory whereas SPIflash uses raw address - reworking the library to work directly from flash will take some effort.  It shouldn't be too bad if you intersect the code at the point that the library reads a block into memory...  It probably uses file seek so you can use that parameter as an offset from your base address.

Tom

Lensdigital

Quote from: TomWS on June 27, 2015, 01:14:26 PM
Well, Adafruit recommends (https://learn.adafruit.com/adafruit-wave-shield-audio-shield-for-arduino/wavehc-library) at least an ATmega328 to use this library so I guess it works.  Note that this is without any other code running, eg (RFM69 library).  Please let us know when you get it running.

Reading and writing from SPIflash instead of SD card isn't an issue technically, but the SD library uses a file system to access its memory whereas SPIflash uses raw address - reworking the library to work directly from flash will take some effort.  It shouldn't be too bad if you intersect the code at the point that the library reads a block into memory...  It probably uses file seek so you can use that parameter as an offset from your base address.

Tom
Yeah I started with Uno, and quickly ran out of RAM. Now I'm using ATMega1284p. Besides WaveShield I use RFM, HT1632, Time, EEPROM, IRRemote, DallasTemperature and few other libraries, and still have sufficient RAM left :)
I'm talking about my Xronos Clock project.  Moteino based sensors send weather data to it from outside...
I currently use microSD cards to hold about 10 Mb of uncompressed WAV data, that takes care of all the "talking" functionality of the clock.
It's kind of a pain dealing with microSD cards tho, as it's hard to find low cost low capacity ones. SPI Flash is such a good candidate for this, thus my question.
Also I just found this promising library, that uses a file like system for storing WAV file data. I'm not sure how to get data to it from computer tho but one way seems to be is to copy it from SD Card, which means I'll need some kind of programming socket adapter...
BTW it seems to be compatible with Flash IC was looking at (S25FL127S), that's actually how I found this library in the first place, as google searches like "SPI Flash file system", etc. did not return any useful results...