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.

Compiler/TMS320F28388D: Memory Section Assignment: Store variables in Ram one by one

Part Number: TMS320F28388D


Tool/software: TI C/C++ Compiler

Hi all,

There are many ram variables in our appilcation codes which are auto-coding based on Matlab/Simulink. Now we want to store them in Ram one by one just like this:

For instance, a Ram section named MEASURE is made, and the start address is 0x0000 3000. Eight variables named var1~var8 are assigned to the section "MEASURE".

Assumption is that the date type of var1~4 is UINT16, with var5~6 UINT32, and var7~8 FLOAT. As we know that these variables have been defined in their own C filies, with no section assignment.

So they are stored in Ram in a random fashion. However, it is needed to assign these variables in MEASURE section one by one, just in the order of var1->var2->var3->var4->var5->var6->var7->var8.

In order to meet the requirement mentioned above, I tried several methods. First, I extrat these eight variables and print them in a head file with Python script. Then add PRAGMA instruction at the front of them like these below:

#pragma SET_DATA_SECTION("MEASURE")

extern UINT16 var1;

extern UINT16 var2;

extern UINT16 var3;

extern UINT16 var4;

extern UINT32 var5;

extern UINT32 var6;

extern FLOAT var7;

extern FLOAT var8;

#pragma SET_DATA_SECTION()

But the result is not what I expected, these eight variables are still stored in a random fashion. So are there any better methods to reassign these pre-defined variables to a continous ram range one by one with the order mentioned above.

Thanks a lot!

  • Unfortunately, there is no convenient way to control the order in which global variables are laid out in memory.  The only way to guarantee the order is to define the variables in hand-coded assembly.  

    I know that sounds hard.  But it can be done.  Here is one way to go about it.

    Write one simple C file that defines just a few global variables.

    int   int_var;
    long  long_var;
    float float_var;

    Compile that file like all your others, but add one more build option: --keep_asm.  By default, the compiler generated assembly file is deleted.  But this option tells the compiler to keep it.  It has the same name as the source file, with the extension changed to .asm.  Inspect that file and note the assembler directives used to define the variables.  It looks similar to ...

            .global _int_var
    _int_var:       .usect  ".ebss",1,1,0
            .global _long_var
    _long_var:      .usect  ".ebss",2,1,1
            .global _float_var
    _float_var:     .usect  ".ebss",2,1,1

    To learn how those assembler directives work, please search for them in the C28x assembly tools manual.  Use these directives in your hand-coded assembly file.  Experiment with writing them in a different order, and see how things change.  

    The compiler also emits lots of directives with names like .dwtag and .dwattr.  These are Dwarf debug directives.  That is now the compiler lets the debugger (Code Composer Studio) know about the types of the variables.  Please ignore them for now.

    Thanks and regards,

    -George

  • Thanks all the same. I try other way to cope with it.