Utilizing Program Flash and Data RAM for Constant Data in C

There are many advantages and one disadvantage if constant data in C is flashed to program flash memory (pROM) and copied to data flash memory (xRAM) at startup, with the usual pROM-to-xRAM initialization.

The advantages are:

The disadvantage is that the xRAM is consumed for constant data at run-time.

If you wish to store constant data in program flash memory and have it handled by the pROM-to-xRAM startup process, a simple change is necessary to the pROM-to-xRAM LCF. Simply, place the constant data references into the data_in_p_flash_ROM section after the __xRAM_data_start variable like the other data references and remove the "data in xROM" section. See the following listing.

Listing: Using typical pROM-to-xRAM LCF
.data_in_p_flash_ROM : AT(__pROM_data_start)

 {

   __xRAM_data_start = .;

   * (.const.data.char) # move constant data references here

   * (.const.char)



   * (.data.char) 

   * (.data) 

   

   etc.