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/CCSTUDIO: Placing variable at specific address without DATA_SECTION pragma

Part Number: CCSTUDIO
Other Parts Discussed in Thread: C2000WARE

Tool/software: TI C/C++ Compiler

For my application, I have numerous (like >50) RAM variables I want to put at specific addresses which are defined in some header file. I'm aware of the method of defining sections in the linker command file, but this requires a separate section to be declared for each independent address. With so many variables, this becomes incredibly tedious, since we have to manually enforce agreement between the .cmd file, the .c file where the variable is declared/defined, and the .h file where the memory locations are kept.

Numerous people have asked this same question, but it seems like the only answer that comes back is to use the above approach. Is there really no method that can be implemented purely in the .c and .h files? I'm using CCS 9.2, btw.

If the answer is no, is there any way to ensure that a set of variables which are put in the same .section are given addresses in a deterministic manner? It would make things a bit easier if I could declare them a specific order using DATA_SECTION(), and assume they are placed in memory in the same order with predictable alignment. 

  • Please search the C28x compiler manual for #pragma LOCATION.

    Thanks and regards,

    -George

  • The location pragma sounds almost ideal, but I don't know if switching to an EABI output is feasible for us... I'm extensively relying on C2000ware, including sfo() for calibration of HRPWM peripherals. Switching to EABI seems to break this. Is there any other alternative you can think of?

  • Your best alternative is to create these variables in hand-coded assembly.  Please see this forum post for the details.

    Thanks and regards,

    -George

  • Hmm, not a bad suggestion. I'll follow your steps and see what the asm output looks like.

    As a compromise, I've been grouping my variables into structures, and placing those structures into sections which are ordered with the GROUP directive in the linker command file. Carefully crafting structures such that all 32 bit members are aligned to even memory addresses, and so forth. At the very least, this greatly reduces the clutter in the cmd file, relative to having a section for each variable.

    This seems to work out pretty well, but in some cases the linker puts a bunch of padding between sections. Seems like it wants to align some variables to data pages, which is annoying.

    Are there any other pitfalls I should be aware of with this approach?

  • Mike Twieg said:
    in some cases the linker puts a bunch of padding between sections

    That's because of data blocking. So, I don't recommend this solution to your problem.

    Thanks and regards,

    -George

  • Ok, thanks for the reading material. Maybe padding my structures to 64 words is the safest/simplest approach right now, but I will continue looking into the other options.

    One other related question: Most of these variables are global (i.e. I declare them with extern) but I do not place them in the memory section for .ebss (many of them need to reside in message RAM). Will this cause an issue with code performance?