Are static char arrays processed from flash or are they fetched to the RAM during execution?

Hello,
This is more of an architecture question. The particle P1 has a flash size of 1MB and a RAM of 128KB. While executing the code, I believe that most of the code gets executed straight from the flash starting at address 0x00000000. The instructions which can be modified are fetched to the RAM and are executed from there. Is this correct?

If I want to declare a static char array of size 300KB, does this get processed from the flash during runtime or will it be copied to the RAM and will crash my P1 due to insufficient space on RAM(being 128KB only)?

Thanks
Dheeraj

My experience is that if you declare the array as const it will live in Flash and you will be fine.

2 Likes

I agree with @bko. A initialized const array will live in flash while an initialized static array will live in both flash (initialization values) and RAM. Making vars static is not the same as const as it defines the scope of the variable, not whether it can change or not.

1 Like

I have something like this:

const char *firmware = {"AAAAAAAAAAAA",
":00000232342DA....."};

/firmware is 194 KB, 737 rows/
void setup()
{
for(int a=0; a<737; a++){
Serial.println(firmware[a]);
}
}

void loop()
{
}

This throws a linker error

/usr/local/gcc-arm-embedded/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld: /workspace/target/workspace.elf section .text' will not fit in region APP_FLASH'
/usr/local/gcc-arm-embedded/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld: region `APP_FLASH' overflowed by 75176 bytes

I want to sent this entire firmware image over UART.

@dheerajdake, though the STM32F205 has 1MB of flash, only 128KB or so is available to the use. Most is used by the Particle system firmware. For larger data, you may want to consider an external flash device.

Got it. When I build an application using the web IDE, under In a nutshell:

The max size for flash and RAM is 110592 bytes and 20480 bytes. This is the space available for application right?

@dheerajdake, the web IDE numbers are incorrect and reflect the values for an older Spark Core. The Photon has approx. 128KB of flash and 60-80KB of RAM available for the user. Compiling using the Particle CLI produces the correct usage values.

1 Like

Thank you

1 Like

Leave off the "*". You don't want a pointer here since firmware is already an address (pointing at the base of the array).

const char firmware[] = {"AAAAAAAAAA", 

This is from the stringImage.h generated by an application. The host bootloader API takes an argument of type const char *bootloadImagePtr[] which should match with const char *firmware[].