<Solved>How to create a temporary SRAM copy of a PROGMEM array?

Sorry to bother, but I have hit a heavy roadblock on a school project:

  • I have an Arduino Due

  • I have multiple arrays of type "const volatile unsigned char" which are all pretty big, these arrays are stored in the Programm Memory

  • I need to load one of these arrays into the SRAM to do some operations with it, the SRAM is big enough to fit one or two of these arrays, but not all of them

  • Therefore my goal is to load one array into the SRAM, use it, have it "forgotten" and load in the next array, however I am unable to do this

const volatile unsigned char* pointer_data = 0; // points to array to be used

uint32_t data_length = 0; // length of array

const volatile unsigned char data_0[] PROGMEM = {

0x80,0x66,0x77,0x58 //and so on


const volatile unsigned char data_1[] PROGMEM = {

// lots more elements


// I have about 20 of these arrays, not all listed above for simplicity

void setup()


// unrelated stuff


void loop()




doStuff(); // my function that works with the array that I point to







// and so on


This gives me a ".bss not within field of ram" compile error, which as far as I know means I have used to much SRAM. Additional notes:

  • the error goes away if I only call do stuff on one or two arrays, but I need to call it on all of them

  • there is also no error when calling "doStuff()" multiple times with the same array

  • pointer_data and data_length are global variables that are used by "doStuff()" to find the correct array

  • my assumption is that the arrays get loaded into the SRAM when I assign it to "data_pointer" and then stays around after the function call, which I don't want, but also don't know how to get rid off.

  • I already tried putting data_pointer = 0; after I'm done with the array, which didn't work

  • I have also tried moving the assignment of the pointer into a function to create a temporary scope, that also didn't work

  • my endgoal is to "doStuff();" with all of the arrays in any possible order

Thank u very much!

Edit: Thank you all for your anwsers, the problem was making the PROGMEM arrays volatile. Having all the PROGMEM arrays as const unsigned char data_x[] PROGMEM did the trick for me, the rest of my code remained unchanged.

That's not doing what you think it is. The size of a pointer is 4 bytes on an ARM-based processor.

Here is the best tutorial on using PROGMEM you will ever find:

But, how applicable is it to a non-AVR processor?

For example, from pgmspace.h in Adafruit's Arduino core for their Feather M0 (SAMD processor):

#define PROGMEM

It does squat.

Not to mention that the concept of a 'volatile' variable in PROGMEM challenges the imagination.

The Feather is ARM-based. Why are you trying to use PROGMEM on an ARM? It is not supported, and completely pointless anyway. const arrays on ARM should ONLY ever exist in FLASH, so there is no need for PROGMEM.

My point was that the Arduino Due being used by @ asdf77 is also ARM-based. I just didn't have that core installed to check the source code when I wrote my reply. That's why I used the M0 Feather as an example.

So, to state again .... @ asdf77 is programming a Due. This is ARM-based. Using PROGRAM makes no sense.

And again, I can't figure out what a "volatile" variable stored in PROGMEM would mean .... even if PROGMEM meant any thing on the DUE.

A post was split to a new topic: Help with my smart attendance system sketch

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.