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.

Is it possible to define a variable (in C) at a particular address?

Other Parts Discussed in Thread: CONTROLSUITE

Hi,

I am using a TMS320F28x micro and Code Composer Studio V4. I'd like to be able to define a global variable (in C) at a particular address. I've used compilers in the past that will allow you to do Something like this:

int MyVar @0x1000; // MyVar is defined to exist in memory at address 0x1000

My end goal is to create a variable for accessing the CAN mailbox registers as an array. Something like this:

struct MBOX CanMboxReg[32] @0x6100;

Then I would be able to initialize the registers in a for loop instead of a long list of individual statements (to save a little flash and look a little cleaner). I'm sure that there are other registers that I could do the same thing with, but at the moment I'm working on CAN. 

 

Thanks,

Mike 

  • Mike,

    You can do this using a pragma DATA_SECTION to allocate the desired data in a separate named section and then in the linker command file you can specify the placement of the named section to a desired memory location.

    For example, in the C file:

    #pragma DATA_SECTION(myarray, "my_sect")
    int myarray[10];

    And in the linker command file:

    SECTIONS
    {
     my_sect > SARAM
     ...
    }

     The C28x Header Files and Peripheral Examples uses similar pragmas which you could take a look at as an example.

  • Hi Mike!

    Looking this post i see that it is similar to my purpose. I want to save in a new varible the data of the mailboxes that i'm receiving of module CAN.

    Could you help me with this? 

    Thank you so much

  • We who watch this forum lack expertise in working with peripherals like CAN.  Most TI devices have a suite of software available (such as controlSUITE for C28x) that includes examples for working with the peripherals.  That's more likely to work for you.

    Thanks and regards,

    -George