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.

CCS/F28M35H52C: set contents of global variable in same line as declaration

Part Number: F28M35H52C
Other Parts Discussed in Thread: CONTROLSUITE

Tool/software: Code Composer Studio

When I do the following the variable is zeroed out when I run the code instead of containing the data that I specified.

Uint16 myVar[2] = {1,2}; // this is in my main source file declared as a global before the main routine

In a source file can you no longer set a global variable in the same line as the declaration or is there some project setting which allows you to enable/disable this? I recently moved from CCS 6.1.1 using compiler 6.4.6 to CCS 7.4.0 using compiler 16.9.6. I started a new project pulling heavily from an old project and have noticed that I can no longer set a variable in the same line as I declared it.

  • If I put the const qualifier in front it maintains the values in the declaration. This is ok based on what I need to do, but I don't understand why not using the const qualifier results in the global not using the initialized values in the declaration.

    Uint16 myVar[2] = {1,2}; // at run time this global contains all zeros

    const Uint16 myVar2[2] = {1,2}; // at run time this global has the initialized values

  • rs said:
    Uint16 myVar[2] = {1,2}; // at run time this global contains all zeros

    Then something has gone wrong in the startup code which performs this initialization.  Please read about it in the section titled Automatic Initialization of Variables in the C28x compiler manual.  If that doesn't help you figure out what is wrong, then we need a test case.  If your code is organized as a Code Composer Studio project, then please submit the project.  Zip it up as described in the article Project Sharing, then attach that zip file to your next post.

    Thanks and regards,

    -George

  • concerto.zip

    So potentially something in the cmd file? Nothing jumped out at me in the compiler documentation but I'm not very familiar with the compiler and memory allocation. Attached is a project where I see the issue. If you break in main you can check the global variable and see that it contains all zeros. Thank you.

  • I think it has something to do with trying to use shared ram for the .ebss section on the C28.

    In the cmd file in the MEMORY section I have

    RAMS07 : origin = 0x00C000, length = 0x008000

    and in the SECTIONS section I have

    .ebss : > RAMS07, PAGE = 1


    On the arm I do the following to give the C28 permission to access the shared ram:

    // Give control of shared memory blocks to C28 processor

    RAMMReqSharedMemAccess(S0_ACCESS, SX_C28MASTER);

    RAMMReqSharedMemAccess(S1_ACCESS, SX_C28MASTER);

    RAMMReqSharedMemAccess(S2_ACCESS, SX_C28MASTER);

    RAMMReqSharedMemAccess(S3_ACCESS, SX_C28MASTER);

    RAMMReqSharedMemAccess(S4_ACCESS, SX_C28MASTER);

    RAMMReqSharedMemAccess(S5_ACCESS, SX_C28MASTER);

    RAMMReqSharedMemAccess(S6_ACCESS, SX_C28MASTER);

    RAMMReqSharedMemAccess(S7_ACCESS, SX_C28MASTER);


    On the C28 I'm not sure how far it is getting relative to the above code being executed on the arm. Maybe the C28 is booting before this gets executed or is there more I need to do on the ARM for the C28 to access the shared ram?
  • Yes, that looks to be correct setup. Have you switched ebss to LxRAMs to confirm that behavior is fixed? I'd recommend setting those sections in the local RAMs unless you have some exception on why you can't.

    There is also a "RAM Management" example in controlSUITE.

    Best regards
    Chris
  • Yes, switching to the following fixed the issue of global variable initialization.

    .ebss : >> RAML2 | RAML3 | RAMM1, PAGE = 1

    The shared RAM was getting used for .ebss because it needed to hold a very large global variable (flash code for another processor). I'm guessing that part of the project doesn't work anymore with the above change. I haven't tried because I'm working on a different part of the project.

    It seems like I should still be to store that data in the shared ram without setting the .ebss to use the shared ram? Is that true? Or is there a better way for storing that very large information without using the shared ram for .ebss?
  • Alright, good.
    You could use the pragma DATA_SECTION() (See that example I mentioned), to place the array in shared memory and keep ebss assigned to local. Can try that.
    I'm assuming you probably have it correct, but also check that your RAMReqSharedMemAccess() is called before the IPC call to boot the C28. This makes sure the shared mem is assigned to C28 before it begins branching and running the application.

    Best regards
    Chris