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/TMS320F28375D: Questions about Compiler

Part Number: TMS320F28375D


Tool/software: TI C/C++ Compiler

4137.section_test base.zip

First of all, I will tell you about the environment here
  Code Composer Studio Version: 6.1.0.00104
  Compiler Version: TI v6.2.8 (and v6.4.8)
  Test Target: F2837x controlCARD R1.3

I did some experiments with Debug Build Configuration(not Release).
I attached a set of base project files.

[Experiment 1] Simple main.c
Comment out SET_DATA_SECTION below from base project.
===
//#pragma SET_DATA_SECTION("MY_SECTION")

const int some_const = 10;

//#pragma SET_DATA_SECTION()
===

After build, I checked map file.
"some_const" symbol mapped in ROM.
===
0     000901c0  _some_const
===

If run via CCS Debug, LED works properly.
If boot standalone, LED works properly.

[Experiment 2] Use DATA_SECTION
Use the base project as it is.

After build, I checked map file.
"some_const" symbol mapped in RAM.
===
1     0000b800  _some_const
===

If run via CCS Debug, LED works properly.
If boot standalone, LED don't works because maybe some_const is 0.

[Experiment 3] Use DATA_SECTION (arrange)

Add new variable definition from base project.
===
#pragma SET_DATA_SECTION("MY_SECTION")

int some_variable;
const int some_const = 10;

#pragma SET_DATA_SECTION()
===

After build, I checked map file.
"some_const" symbol mapped in ROM.
===
0     000901c0  _some_const                          
1     0000b800  _some_variable
==

If run via CCS Debug, LED works properly.
If boot standalone, LED works properly.


[Question 1]

There is the a following sentence in spru514p 6.12.2.
"You can use the DATA_SECTION pragma to put the variable in a section other than .econst."

So, [Experiment 2] seems to be the correct.
In order to use standalone in this map, ROM data with an initial value needs to be created and loaded at startup.
How should I do?


[Question 2]

I expect [Experiment 2] and [Experiment 3] is same.
Why not?

  • I can explain what happened. I cannot tell you the best way forward.  That requires knowledge of the system, and expertise with system startup, which I lack.

    For some useful background, please search the C28x assembly tools manual for the sub-chapter titled How the Assembler Handles Sections. Read it well enough to get a clear understanding of the terms uninitialized section and initialized section.

    In experiment 1, the variable some_const is in the initialized section .econst. The linker command file allocates this section with this line …

       .econst             : >> FLASHF | FLASHG | FLASHH      PAGE = 0, ALIGN(4)

    While you don’t show it, I presume this initialized section is programmed into flash memory. Thus, when the system starts running, the section .econst is already present.

    In experiment 2, the variable some_const is in the initialized section MY_SECTION. The linker command file allocates this section with this line …

       MY_SECTION		: > RAMD1,		PAGE = 1

    CCS uses the built-in loader to copy the initialized section from the executable .out file to RAM. When you boot the system without CCS, how does such a copy occur? I presume there is no way to access the executable .out file.

    To further illustrate the problem of copying an initialized section from the .out file to RAM, consider how it is done for code. The linker command file contains these lines …

       ramfuncs            : LOAD = FLASHD,
                             RUN = RAMLS0 | RAMLS1 | RAMLS2 |RAMLS3,
                             LOAD_START(_RamfuncsLoadStart),
                             LOAD_SIZE(_RamfuncsLoadSize),
                             LOAD_END(_RamfuncsLoadEnd),
                             RUN_START(_RamfuncsRunStart),
                             RUN_SIZE(_RamfuncsRunSize),
                             RUN_END(_RamfuncsRunEnd),
                             PAGE = 0, ALIGN(4)

    This says the initialized code section ramfuncs has a load address in the memory range FLASHD, and a run address in one of the RAM memory ranges. The LOAD_START operator, along with the other similar operators, creates symbols which are used during system startup to copy the ramfuncs section from flash to RAM. A similar solution would be required to get the initialized data section MY_SECTION programmed into flash, then copied to RAM during system start. As far I am aware, no one does this. I don’t know why.

    In experiment 3, when I build the code I get this diagnostic …

    warning #849-D: The section MY_SECTION contains incompatible objects "some_variable" (data) and "some_const" (const), "some_const" will not be included in MY_SECTION

    The variable some_const is in the initialized section .econst, and the variable some_variable is in the uninitialized section MY_SECTION. That is why it acts like experiment 1.

    Thanks and regards,

    -George

  • Hello, George

      Thank you for your answer.
      I understand almost. But there are some additional questions.

    [Question 1']

    You wrote:
    A similar solution would be required to get the initialized data section MY_SECTION programmed into flash, then copied to RAM during system start. As far I am aware, no one does this. I don’t know why.

    I understand that TI compiler does not support DATA_SECTION for const.
    Is it correct?

    [Question 3]

    ln my [Experiment 3], I understand why const is not placed in MY_SECTION for your answer.
    However, these determinations are made on a file-by-file.
    If multiple files are SET_DATA_SECTION("MY_SECTION") specified, some const variable will be placed in .econst for c source files that have only const and other const variable will be placed in MY_SECTION for c source files that have non-const and const mixed.
    What I want to do is to place all non-const variables (RAM) in MY_SECTION.
    Is there any way to specify such?

    Thanks and best regards,
    Kento

  • You face two main limitations.

    One, within the same file (C or assembly) a section can only be initialized or uninitialized.  Never both.  Once a section is established as one, it cannot change to the other.

    Two, there is very little support for putting an initialized data section in RAM.  It is not impossible.  But you have to do it all yourself.

    user5931564 said:
    I understand that TI compiler does not support DATA_SECTION for const.
    Is it correct?

    You can put a const variable in a section you name.  But cannot then put a non-const variable in that same section.

    user5931564 said:
    What I want to do is to place all non-const variables (RAM) in MY_SECTION.
    Is there any way to specify such?

    Use different section names for const variables and non-const variables.  Never mix them.

    Thanks and regards,

    -George

  • Hello George.

    I use different section nemes for const variables and non-const variables.

    Thanks for good advice,
    Kento