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.

TMS320F28375D: How to create a custom data section?

Part Number: TMS320F28375D


Hello,

I'd like to create a custom initialized data section so I've added this line to my command file:

   .cmds               : LOAD = FLASH, LOAD_START(_cmdsStart), LOAD_END(_cmdsEnd), PAGE = 0

Then in C my idea was to declare structures in that section like this:

#define DEFINE_COMMAND(name, execfn, desc) command name __attribute__((section(".cmds"))) = {#name, func, desc}

DEFINE_COMMAND(help, helpCmd, "Help command");

so I could then iterate from cmdsStart to cmdsEnd, much like libc does it with initializer functions.

But this doesn't seem to work. It creates the .cmds section and reserves memory of correct size, but the actual data in my .cmds section is uninitialized (all Fs).

Do you perhaps see something wrong with this?

Thank you

Jiri

  • Hi Jiri,

    You can define custom sections using the #pragma DATA_SECTION. If you are using EABI compiler all the uninitialized globals will be zero-intialized by default. IN case of COFF, they will remain uninitialized.

    Which compiler are you using?

    Regards,

    Veena

  • Hi Veena,

    I'm using TI's C2000 compiler (ti-cgt-c2000_20.2.2.LTS).

    #pragma DATA_SECTION seems to behave the same as __attribute__(section).

    Is there a way to have the data initialized at compile time? Or only .econst can have initialized data?

    Thank you

    Jiri

  • Hi Jiri,

    I meant, are you using EABI compiler or COFF compiler?

    Uninitialized variable -> uint32_t a;

    Initialized variable -> uint32_t b = 10;

    With COFF compiler, a will remain uninitialized and b will be initialized to 10 by the startup routine. In case of EABI compiler, a will be initilaized to 0 and b will be initialized to 10.

    You can either switch to EABI compiler or initialize the section using the linker. Please refer to the section "Initializing Static and Global Variables in COFF ABI Mode" in the compiler guide

    Regards,

    Veena

  • Ermm, I'm sorry I only know what executable I'm using as compiler.

    Are you perhaps asking for the output format? In which case that would be .obj = COFF.

    Yes, that is the problem I'm having.

    uint16_t b = 10; is 0xFFFF in memory browser.

    And it only does that when I put this variable into my custom .cmds section.

  • Oh okay, I see you are putting the section to FLASH region.

    In that case, you need to set the variable as const. In case of non-const variables (which is usually loaded in RAM region), the variables are initialized in the startup routine. Since Flash memory is not writable, it fails to update the value. In case of const variables (usually loaded in Flash), the initial values are loaded as part of program load. The Flash memory is updated using the Flash plugin.

    Please define the variable as const in case it is loaded to Flash.

    Regards,

    Veena

  • Ah, I see, yep that was the problem. Thanks a lot Veena!