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.

Place small ASM code at specific flash location

Other Parts Discussed in Thread: MSP430F149

Hello everyone,


     On my MSP430F149 C project I am trying to place a small ASM code ("br #__c_int00") at a specific flash location (0x1600). How this can be acomplished in CCS 5.3?

    I did something similar using Imagecraft ICC430, where I had to create a .s file and just add an .org directive. Something like this:

    .area jmp_to_main_kernel_asm(abs)
    .org 0x1600
    br #__start

where "_start" was the init routine defined by Imagecraft compiler.

Is there a specific #pragma I could use to accomplish the same result in CCS?

Regards,

Calin

  • Calin,

    You must use the .sect directive, as well as correspond that with a section in your linker CMD file.

    I just happened to be working on a similar thing. Check the attached project, where several pieces of code and data are allocated throughout the memory, and one in particular (.const) is allocated to a fixed address.

    Hope this helps,

    Rafael

    D413_Demo.rar
  • Hello Rafel,

        I placed some constant data into a specific flash address with this approach:

    #pragma RETAIN(watermark)
    #pragma location=0x1604
    const unsigned char watermark[] = {'M','e','t','r','o','l','o','g'};

        It worked fine.

        Now I tried your idea:

        - Created a SECTION { .blentry    : {} > 0x1600 ... at lnk_msp430f149.cmd
        - Created a new .s file, with these lines:

    .sect .blentry
    br     #0123h

        It compiles ok, however no data is placed at the correct address (0x1600). Am I missing something here?

        Also, do you have idea how to refer to the linker function _c_int00? I tried br #_c_int00 (and some variations) but the linker keeps complaning about undefined "c_int00"

    Thank you for your tips!

    Calin

  • Calin,

    A few details:

    I am assuming you are putting a space before the "br #0123h" so it is properly considered as a mnemonic, right? 

    If you don't have any label that references the assembly piece of code you just wrote, chances are the linker will automatically remove it (it is not called from anywhere). In this case, you could try to define a symbol and call it from your C source code.

       .sect .blentry
       .global my_func
       .asmfunc
    my_func
       br     #0123h
       .endasmfunc


    Not all details are accurate, therefore you should take a look at section 6.5 of the MSP Compiler User's Guide (a link to it is here)

    I am unsure how the symbol _c_int00 would be called, but the section I referenced above mentions the & operand to access variables, therefore you could try the same with functions.

    Hope this helps,

    Rafael

     

  • Hello Rafael, I guess I found the solution. In the end it is simple:


    In Linker file lnk_msp430f149.cmd I added these two declarations:

    MEMORY
    {
        BLENTRY                 : origin = 0x1600, length = 0x0004
    }

    SECTIONS
    {
        .blentry    : {} > BLENTRY    
    }

    And into my asm file just wrote:

        .global _c_int00
        .retain .blentry
        .sect .blentry
        br     #_c_int00

    The code appeared correctly positioned at my desired flash location.

    Your tips were very helpful. Thank you.

    Calin

  • Calin,

    Ah, I forgot the .retain, which is mandatory for ELF...

    Glad everything is working.

    Cheers,

    Rafael