Reading datas from Flash memory without copying them to SRAM

Hello everyone,

I’m trying to store a buffer of 14000 uint16_t to Flash. I managed to do so, thanks to this great code:

The problem is the following:
each time I want to do something (e.g. read or use that for math operations) on that buffer stored in Flash, the code suggests me to copy the array to the SRAM (that functions simply copy structs from Flash to SRAM and from SRAM to Flash).
But doing so, i will quickly run out of space in SRAM.

So, is there a way to read (and work on) datas from Flash memory without having to copy them to SRAM?
I’m working on SARA AFF N211, so the MCU is the ATSAMD21J18A with 256KB of Flash and 32KB of SRAM.
Francesco Trombetta

Hi Francesco,

This is quite the predicament you’re in. Before I can give some good advice I do need to know why you need to store 28000 bytes to flash. I sincerely hope you’re not doing this very often.

I also wonder if you must load all information from flash into RAM, what’re you trying to do with it? Do you really need all information available at the same time in RAM?

You can also just create a pointer to your static information in your flash and work on that if need be, if possible. Do mind that this will be read-only.


Thanks Tom,
so my goal is to store a large array of uint_16t of samples coming from the ADC (i.e. 28000 bytes).
I’m trying to extend the length of that buffer (e.g. 18000 samples -> 36000 bytes) but there isn’t enough space in SRAM.
I want to compute the RMS of that sequence of samples.
For this reason I was trying to store the whole buffer of samples directly to Flash, where there are 256KB of space (including the program space).
If I manage to do this, I will compute the RMS of a sequence of samples that is store to Flash, without consuming SRAM space.
Is it possible or am I making some mistake?

Anyway, do you know how to store data to flash, working in the Arduino IDE, without using the code I mentioned in the previous message?

Thanks again,

Hi Francesco,

Before continuing I need to know how often you’re planning on doing this.