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.

How to assign a function to specific memory location in flash?

Other Parts Discussed in Thread: MSP430F2274

Hi all,

 

I am using msp430f2274 in my application, my application requires to store the specific functions in specific memory locations. i tried for that but not able to do it, so any body tell me the way to do this operation please...

Welcome for any type of help..

Thanks

siva

  • Hi siva,

    with the IAR compiler, functions can be placed into a named segment using the @ operator or the #pragma location directive:

    /* IAR C Code */
    void g(void) @ "MYSEGMENT"
    {
    ...
    }

     

    or use:
    #pragma location="MYSEGMENT"
    void h(void)
    {

    }

     

    With the CCS compiler, the following scheme with the #pragma CODE_SECTION() directive must be used:

    /* CCS C Code */
    #pragma CODE_SECTION(g, "MYSEGMENT")
    void g(void)
    {
    ...
    }

     

    Your sections needs to be defined in the .xcl-file (for IAR) or in the .cmd-file (in case of CCS).

    Rgds
    aBUGSworstnightmare

    P.S. MYSEGMENT is just an example! Name it whatever you want!

  • HI aBUGSworstnightmare..

    Thanks for reply..can you tell me that what is "MYSEGMENT" and how can i define this in .CMD-file.

    i need to assign specific locations for upto 5 functions can you tell me what is the procedure to define in .cmd file..

     

    Regards

    siva

  • "MYSEGMENT" is the segment in which you want your code to be placed. Either you define your own or use one of the existing ones.
    This may as well be the segment for initialized data (so the startup code will copy your function from flash to ram automatically).

    But don't ask me how this segment is called on your compiler. You should be able to get it from the map file or such.

  • Hi siva,

    'MYSEGMENT' is just a template for a segment name! You can name it whatever you want!

    I've enclosed an example .cmd file were 9 custom segments were defined (ADCSAMPLE, CHANNEL0 to CHANNEL7). ADCSAMPLE is in RAM and CHANNELx is in FLASH memory!

    8468.CCS-cmd-example.zip

    If you want to place code into i.e. segment CHANNEL0 your #pragma looks like:

    /* CCS C Code */
    #pragma CODE_SECTION(g, ".channel0")
    void g(void)
    {
    ...
    }

    You can also place (constant) data into those named segments, i.e. into CHANNEL1:

    #pragma DATA_SECTION (move1, ".channel1")

    const unsigned int move1[3] =

     {

    1500,

    160,

    210,

     };

     

     

    Rgds
    aBUGSworstnightmare

     

    P.S. By the way, here's an example how to do it with IAR: http://e2e.ti.com/support/microcontrollers/msp43016-bit_ultra-low_power_mcus/f/166/p/19042/73751.aspx#73751

     

**Attention** This is a public forum