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.

Flash memory storage using #pragma directives.

Other Parts Discussed in Thread: TMS570LS20216

Hi,

 

I need store constant configuration data (sample below) to the flash memory starting address as 0x00080000.

 

 

Example :

 

Config string : 8bytes : char data : 0x00080000 (start address)

Config ID     : 2bytes : int data  : 0x00080008

unit_type     : 1byte  : int  data : 0x0008000A   

sensor_type   : 2byte  : int  data : 0x0008000B

filer_const   : 4byte  : floatdata : 0x0008000C

 

I created a .config data section in the linker directive which starts at 0x00080000.

 

I used the #pragmas  to do this task as below in one of the source file.

 

#pragma DATA_SECTION (CFG_STR , ".config" )

const int8            CFG_STR[8] = {'1','1','3','8','V','A','0','1'};

 

#pragma DATA_SECTION (CFG_ID , ".config" )

const     uint16   CFG_ID = 0xABCD;

#pragma DATA_SECTION (UNIT_TYPE , ".config" )

const     uint8      UNIT_TYPE = 0x00;

#pragma DATA_SECTION (SENSOR_TYPE , ".config" )

const     uint16   SENSOR_TYPE=0x02;

#pragma DATA_SECTION (FILTER_COEFF , ".config" )

const     float32  FILTER_COEFF = 6.5;

 

 

I can see this data in flash but not in the required address as mentioned above. I see that memory address allocation

of these variables is in the order of definition i.e top to bottom.( CFG_STR.. UNIT_TYPE .. FILTER_COEFF )

 

1) Does it always allocates memory in the order of declaraion in source file ? What is the gurantee ?

Ex :For the above sample code, the memory address allocation and order is as below observed in debugger.

(CFG_STR = 0x00080000 , CFG_ID = 0x00080008, UNIT_TYPE=0x0008000A, SENSOR_TYPE= 0x0008000C, FILTER_COEFF = 0x00080010)

Is there any chance that FILTER_COEFF allocated immediately after CFG_STR instead of CFG_ID ? If so how to handle it ?

 

 

2) In the debugger, i see that there are some holes in between these variables memory allocation.

Is there any way to suppress this padding ? Ex : SENSOR_TYPE requires 2 bytes, after that 2 bytes are filled with 0x00.

 

[ i found variable attributes (gcc extensions) for this purpose and not working as i expect]

 

3) Actual configuration data to be stored as per my requirement is around 20K. I tried with strucure to do this job.

I need to do the explict initialization for that too. Any other suggestion apart from the above method ?

 

Processor : TMS570LS20216 (Cortex R4), Code Composer Studio : 4.2.0.10018,  TMS470 C/C++ CODE GENERATION TOOLS 4.6.3

  • Bindu Tanguturi said:
    1) Does it always allocates memory in the order of declaraion in source file ? What is the gurantee ?

    No.  Variables are not guaranteed to be laid out in memory in any particular order.  

    Your best bet is to define these data variables in hand-coded assembly.  That may sound difficult, but it isn't that hard.  Look at how the compiler defines that data.  That tells you which directives to read up on in the Assembly Language Tools book.  Then you can lay them out in the exact order and spacing you require.  Though be sure to honor any alignment requirements the compiler imposes, i.e. float on a 4-byte boundary etc.  

    Thanks and regards,

    -George

  • Could please provide me the exact section that i need to refer . and it would be helpful if you provide me some sample assembly code for my requirement.

    So if i write in assembly ,it guarantees the order of memory allocation and does it allow the pragmas ? and does assembly allow me to write to flash ?

  • I recommend you create a small toy project just for the purpose of learning how to write hand coded assembly that defines data.  Start with two files: main.c and data.c  In main.c you have the main program and a bit of code which uses one global variable that is externally declared ...

    extern const int one_global;

    In data.c you actually define that data like this ...

    const int one_global = 10;

    Build with --keep_asm so the compiler generated assembly file is not deleted.  Inspect data.asm.  See how one_global is defined.  It will be done with assembler directives that begin with a period, like .word.  Learn about those directives by searching for them in the assembly tools book.

    Next, get rid of data.c and replace it with a data.asm you write yourself.  Once you have this working, you just need to scale it up a bit to work in your actual project.

    Bindu Tanguturi said:
    So if i write in assembly ,it guarantees the order of memory allocation and does it allow the pragmas ?

    The order is guaranteed.  Pragmas are not needed or allowed in hand coded assembly.

    Bindu Tanguturi said:
    and does assembly allow me to write to flash ?

    I don't know anything about programming flash.  But I cannot imagine that defining the data in assembly will in any way prevent you from programming the flash.

    Thanks and regards,

    -George

  • Thanks Gorge. Your suggestion looks working for me. I will get back to you once i get the correct results.