Constant data in flash memory / program space?

hwmaier
Posts: 31
Joined: Sun May 28, 2017 7:30 am

Constant data in flash memory / program space?

Postby hwmaier » Tue May 30, 2017 2:54 am

Does this CPU architecture allow to keep constant data in flash memory, similar to other Harvard CPU architectures (AVR for example) or is constant data always copied from flash to RAM on start-up?

If flash based constant data access is possible, what is the proper declaration to do this? Is there a PROGMEM attribute or something similar which can be added to a declaration?

ESP_igrr
Posts: 2072
Joined: Tue Dec 01, 2015 8:37 am

Re: Constant data in flash memory / program space?

Postby ESP_igrr » Tue May 30, 2017 3:49 am

Constant data is stored in flash by default, and can be accessed on byte, half-word and word basis. You need to use 'const' qualifier in your program to mark the data constant.

Internally, data in cache is mapped into the CPU address space via a transparent cache. See the chapter on Flash MMU in the TRM for more details.

hwmaier
Posts: 31
Joined: Sun May 28, 2017 7:30 am

Re: Constant data in flash memory / program space?

Postby hwmaier » Wed May 31, 2017 3:08 am

Thank you for the clarification. So I understand this architecture does not have to copy init data from flash to RAM but uses the MMU to map the memory segments into either IRAM or normal RAM. Very nice.

I ran some tests too and can confirm that

Code: Select all

const char constString[] = "0123456789";
places the string nicely in the drom0_0_seg segment which is flash and counting towards the "text" size.
Same applies for

Code: Select all

const char * const constString = "0123456789";
and

Code: Select all

char * const constString = "0123456789";
Compared to

Code: Select all

 char constString[] = "0123456789";
which places the string into dram0_0_seg segment which is RAM and counting towards the "data" size.

Who is online

Users browsing this forum: cdollar and 64 guests