Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

Metro M4 GC, using the flash storage
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Metro M4 GC, using the flash storage

by basrijn on Fri Mar 20, 2020 2:40 pm

Hi,

I have some data I want to store. Since the Metro has a nice big flash storage, I thought I would use that.

Doing this in Arduino code (not python), and finding it surprisingly hard. After looking (and trying) different examples, this one seems to be the most complete:

https://github.com/adafruit/Adafruit_SP ... _usage.ino

But that relies on the format example (https://github.com/adafruit/Adafruit_SPIFlash/tree/master/examples/SdFat_format) to actual continue past the trying to mount step.

Taking the code from the format example into my main code (taken from the full_usage example) fails because it missing ff.h etc. Those files are in the format example directory. copied those files over to the Adafruit_SpiFlash library directory, and now my compile fails on something that seems to be outside of my code :(

Does anybody have a full example of mounting flash, creating a filesystem and then reading and writing a file to it?

TX!
Bas

basrijn
 
Posts: 81
Joined: Tue Nov 28, 2017 11:24 pm

Re: Metro M4 GC, using the flash storage

by User_UMjT7KxnxP8YN8 on Sun Mar 22, 2020 12:22 am

I've been working on this problem and have working code but it's not quite ready to distribute widely yet. If you're interested in taking it for a test drive I'll be happy to share it for that purpose.

User_UMjT7KxnxP8YN8
 
Posts: 170
Joined: Tue Jul 17, 2018 1:28 pm

Re: Metro M4 GC, using the flash storage

by basrijn on Mon Mar 23, 2020 6:18 pm

Adafruit_UMjT7KxnxP8YN8 wrote:I've been working on this problem and have working code but it's not quite ready to distribute widely yet. If you're interested in taking it for a test drive I'll be happy to share it for that purpose.


Hi!

Would definitely be interested in giving it a try!

Bas

basrijn
 
Posts: 81
Joined: Tue Nov 28, 2017 11:24 pm

Re: Metro M4 GC, using the flash storage

by User_UMjT7KxnxP8YN8 on Tue Mar 24, 2020 12:54 am

Can you tell me a bit more about what you need to do? Are you writing a stream of samples to QSPI memory?

I needed to write discrete objects to QSPI memory from a C++ program then retrieve them in a bootloader that's written in C, so I converted the Adafruit SPIFlash library to a group of C functions. I divided QPSI memory into large chunks I called "zones", and write objects to the zones where each zone's objects are derived from a different struct type. When there's not enough room to write a new object to a particular zone, it is erased and the new object is written at the beginning of the zone.

I used the Scramble feature to make life difficult for anyone seeking to snoop in QSPI memory, which added some interesting wrinkles.

Since I (mostly) don't do random access writes and the loader is somewhat memory-constrained, I stripped out the buffering feature from Adafruit's library.

I plan to use the processor's XIP (eXecute In Place) capability, so I modified the C version of the library to always leave the QSPI interface in a state that permits this except during writes.

Let me know what part of that, if any, sounds potentially useful to you and I'll post code where you can get it.

User_UMjT7KxnxP8YN8
 
Posts: 170
Joined: Tue Jul 17, 2018 1:28 pm

Re: Metro M4 GC, using the flash storage

by User_UMjT7KxnxP8YN8 on Wed Mar 25, 2020 12:39 am

Here's the current version of my code. I made a sample sketch to demonstrate how it's used, and tested it on a Metro M4 Express before posting. I don't have a Grand Central but the processors are the same and the QPSI chip should be compatible (Adafruit uses a variety of QSPI chips and their code supports all of them).

I left scramble mode off by default, but you can turn it on manually via the menu or automatically by uncommenting the call to QSPIsetScrambleKey() in setup().

The mapping of files from Adafruit_SPIFlash-master to my C conversions is as follows:

Adafruit_FlashTransport_QSPI_SAMD.cpp -> QSPIT_SAMD.c
Adafruit_SPIFlash.cpp -> SPIFlash.c

As I mentioned previously, I don't need the cache feature and am trying to fit my code into a tight space, so I've omitted it.

QSPI.cpp contains the code that manipulates objects, erases QSPI, etc. I've temporarily made the "C" version a "CPP" to make it easy to use Serial.print() during debugging. If those are removed, it should build as a "C" file.

Feel free to post any questions you may have.
Attachments
QSPI_C_Functions.zip
(19.46 KiB) Downloaded 3 times

User_UMjT7KxnxP8YN8
 
Posts: 170
Joined: Tue Jul 17, 2018 1:28 pm

Re: Metro M4 GC, using the flash storage

by User_UMjT7KxnxP8YN8 on Wed Mar 25, 2020 2:04 am

Attachment updated to add MIT license.
Attachments
QSPI_C_Functions.zip
(21.48 KiB) Downloaded 4 times

User_UMjT7KxnxP8YN8
 
Posts: 170
Joined: Tue Jul 17, 2018 1:28 pm

Re: Metro M4 GC, using the flash storage

by adafruit_support_mike on Sun Mar 29, 2020 5:15 am

Remember that Flash has a nominal lifespan of 100,000 erase-write cycles. It's easy to burn through that if you're storing general, mutable data.

adafruit_support_mike
 
Posts: 61442
Joined: Thu Feb 11, 2010 2:51 pm

Re: Metro M4 GC, using the flash storage

by User_UMjT7KxnxP8YN8 on Sun Mar 29, 2020 11:36 am

Great point. I made my zones large enough to store many objects before having to erase. For instance, you can write seventy-four 110 byte objects to a zone consisting of two 4096 byte sectors before having to erase the zone. You can write 7,400,000 such objects before reaching the 100,000 erase cycle limit.

So... not the best place to store surveillance video captured 24/7/365, but a great place to store network settings and other data that change infrequently.

User_UMjT7KxnxP8YN8
 
Posts: 170
Joined: Tue Jul 17, 2018 1:28 pm

Re: Metro M4 GC, using the flash storage

by basrijn on Sun Mar 29, 2020 8:32 pm

In ended up creating a separate sketch to run a format on the flash. That ended up working ok

basrijn
 
Posts: 81
Joined: Tue Nov 28, 2017 11:24 pm

Please be positive and constructive with your questions and comments.