MatrixPortal M4: can we write to the "512 flash" or "2 MB of

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
subatomic
 
Posts: 523
Joined: Wed May 11, 2005 3:12 pm

MatrixPortal M4: can we write to the "512 flash" or "2 MB of

Post by subatomic »

Question.
Does the MatrixPortal M4 have a non volatile ram or a way that I can write to the filesystem?
And how would I do that?
Can I use stdio.h file read/write, or something else?

I'd like to save state that the user can set using taps or clicking the 2 side buttons... So it powers up with the same config saved out. :)

User avatar
dastels
 
Posts: 15653
Joined: Tue Oct 20, 2015 3:22 pm

Re: MatrixPortal M4: can we write to the "512 flash" or "2 M

Post by dastels »

Flash isn't a good option for this. Using a one of the I2C FRAM or EEPROM breakouts is. The EEPROM breakout (https://www.adafruit.com/?q=eeprom&sort=BestMatch) has a STEMMA-QT connection which makes it even easier to connect to the Matrix Portal.

Dave

User avatar
subatomic
 
Posts: 523
Joined: Wed May 11, 2005 3:12 pm

Re: MatrixPortal M4: can we write to the "512 flash" or "2 M

Post by subatomic »

So is there no way to access the USB filesystem I can see when I plug in the MatrixPortal M4 to my computer?
The same place I can edit `core.py` and hit save a million times?
We know this filesystem exists on the device.
Are we saying it's just not available from within the Arduino Sketch (or circuit python) ?

If you're concerned with number of times wearing out this USB filesystem, then I am not worried there, I actually have a very limited use of 1 param that I think will almost never be toggled (set once and likely not again).

So you're saying to use FRAM or EEPROM as an attached add-on board... Noted. But, I'd rather avoid for this project, if possible (I'm not spending more, and I'm about to ship it out with or without toggling the one config param save out.)


Here's a better question: Is there someplace I can read up on how to access (read and write) the "512flash" or "2 MB of QSPI Flash" from Arduino? Docs or Examples? It says the 2MB is for Art and media... seems like I could use that... maybe

User avatar
dastels
 
Posts: 15653
Joined: Tue Oct 20, 2015 3:22 pm

Re: MatrixPortal M4: can we write to the "512 flash" or "2 M

Post by dastels »

You can certainly use the filesystem. Just open a file and read/write as desired. Look for guides on data logging for example. Also, for CircuitPython see https://learn.adafruit.com/circuitpytho ... on-storage. For Arduino., look at https://www.arduino.cc/reference/en/lib ... shstorage/ and https://www.arduino.cc/reference/en/libraries/fatfs/.

Dave

User avatar
subatomic
 
Posts: 523
Joined: Wed May 11, 2005 3:12 pm

Re: MatrixPortal M4: can we write to the "512 flash" or "2 M

Post by subatomic »

Oh awesome. So it’s just standard file IO. Niiiiiice. Thanks and thanks for the links to docs. Super helpful. I’ll be digging into this soon

User avatar
adafruit2
 
Posts: 22144
Joined: Fri Mar 11, 2005 7:36 pm

Re: MatrixPortal M4: can we write to the "512 flash" or "2 M

Post by adafruit2 »

@dastels this is the library we recommend for accessing the SPI flash memory
https://github.com/adafruit/Adafruit_SPIFlash

User avatar
subatomic
 
Posts: 523
Joined: Wed May 11, 2005 3:12 pm

Re: MatrixPortal M4: can we write to the "512 flash" or "2 M

Post by subatomic »

You can certainly use the filesystem. Just open a file and read/write as desired.
Well, I tried this with stdio.h, fopen, fread, fwrite, fclose methods... No dice. And it doesn't seem that it is this easy in the vein of "Use the Filesystem" and "Just open" in a C context, (at least to me), means to use ANSI C. It seems you have to format and use a special non-C API.

Reading around for datalogging, I found https://cdn-learn.adafruit.com/download ... ing-m4.pdf, which indicates this is NOT a standard (already mounted) fat filesystem that works with std C file io... Looks like you have to 1.) format the flash to appear as FAT, 2.) use a special SdFat lib to access it (rather than C file io...).

I'm Reading the examples here:
https://github.com/adafruit/Adafruit_SP ... r/examples

Thanks everyone. I think I am on a track now...

User avatar
subatomic
 
Posts: 523
Joined: Wed May 11, 2005 3:12 pm

Re: MatrixPortal M4: can we write to the "512 flash" or "2 M

Post by subatomic »

Got this working from the SPIFlash examples.

I created a Key / Value "Local Store" interface (somewhat similar in concept to Javascript's localStorage) meant for load/save of persistent configuration data.

Code: Select all

suba::LocalStore conf;
bool show_arrow;

void setup(void) {
  // initialize persistant configuration store
  conf.init();
  conf.getItem( "arrow", show_arrow, /* default value*/ false );  // read into show_arrow
}

void loop() {
    if (button_edge_state == suba::EdgeFilter::EDGE_DOWN) {
      show_arrow = !show_arrow;             // toggle
      conf.setItem( "arrow", show_arrow );
    }
}
My LocalStore will also auto-format the flash as FAT if the LocalStore finds that it cannot access the FAT fs. This kind of "batteries included" piece of code will be nice for others who may try to install my code, avoiding folks having to chase down and do manual steps to load up a separate .ino sketch to format their flash. :-)

I also included a #ifdef to compile out the formatting code easily in case people find the format() bloats their code. They may like to remove it once their device is formatted.

I'll post a link once I get into source control.
Thanks again for the tips everyone.

User avatar
subatomic
 
Posts: 523
Joined: Wed May 11, 2005 3:12 pm

Re: MatrixPortal M4: can we write to the "512 flash" or "2 M

Post by subatomic »

https://github.com/subatomicglue/Arduin ... calStore.h

By no means production code, but it got my project to do what I needed. Hopefully it helps someone looking to do the same.

Locked
Please be positive and constructive with your questions and comments.

Return to “Itsy Bitsy Boards”