This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Problems allocating Constants in Flash

Other Parts Discussed in Thread: TMS320F28335

Hello!

My microcontroller is TMS320F28335.

I need to place a large data block (approx. 78k words) in the program memory area. My data array is defined like that:

const unsigned int Name[ ] = { ..., ..., ..., ...} ;

By default the .const section is 4k words. So it's not enough. And all the data memory also. I tried to modify the 28335_RAM_lnk.cmd file:

MEMORY
{
PAGE 0 :
...
  FLASHROM : origin = 0x30 0000, length = 0x14000

}
SECTIONS
{

...

  .econst : > FLASHROM, PAGE = 0

}

The data block now located at the 0x30 0000 address. But the program code near address 0x9000 is partially damaged by fragments of these data block.

I also tried to define data without  "const" word and use #pragma DATA_SECTION. But it also does not works, because compiler tries to generate instructions that initialize all these data like variables.

Please explain me what is the best and correct way to place me constant array in the program memory area starting from address 0x30 0000 ore higher.

Thanks.

  • You can use the following to define your constant table:

    #pragma DATA_SECTION(Name,"myconstants");

    const unsigned int Name[] = {...,....,...};

     

    This will instruct the compiler to put "Name" in the named section "myconstants". You need the const declaration as well as the initial values.

    Then in your linker command file, you will need to put the "myconstants" section in an appropriately sized area of FLASH.

    SECTIONS

    {

    myconstants   : > BIGFLASH     PAGE = 0

    }

    You'll probably need to reorganize your memory section to provide a block large enough to contain the section. You can consolidate several flash blocks.

    You could also just put the .const section in the larger block.

    Hope this helps

     

  • Thank you. But no difference. I can use pragma or modify .econst address. Result is the same - function in RAM at 0x9000 is corrupted. Should I use 28335.cmd instead of 28335_RAM_lnk.cmd and copy some functions into RAM with memcpy() ? Or there is some way to place large data block in Flash using standard 28335_RAM_lnk.cmd slightly modified?

  • With 78K constant data in a single table your program is too big to be working from RAM.

    You'll probably want to start with an example F28335.cmd example file and modify accordingly. My earlier comments apply to that. You can create a large block by combing FLASHH,FLASHG, FLASHF, etc. into one large block.

    It is possible to put your table into FLASH separately and continue to work with a RAM based program but it is usually best to get your system running properly out of flash unless the end system is not going to be run out of FLASH.

    If your system is small (other than the 78K table) or needs to run from RAM, you can create two projects and define the table in one and load it into FLASH with the debugger. In the other project you need to avoid erasing that table.

    The traditional approach is to define the functions that need to run out of RAM (for speed or in order to program flash), place them into a ramfuncs section, and copy them into ram at runtime as illustrated in the examples. F28335.cmd is already set up to do the right thing but you need to add your own runtime code to move the functions from flash to RAM.