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.

MSPGCC compiling at address

Other Parts Discussed in Thread: MSP430G2553

I am working on a project that requires custom bootloader software and custom application software on a MSP430G2553.  I have completed the application software and tested it.  I am still working on the bootloader software.  I am using MSPGCC running under linux.  Is there a way when I compile to software to specify the addresses that the two pieces of code are programmed at?  For example the bootloader for be programmed in to the MSP starting at address 0xC000 and I wish to program the application code beginning at address 0xCA00. So how would I tell the compiler that my application code starts at address 0xCA00 instead of the default 0xC000?      

  • Modify the linker file. Not sure about MSPGCC, but on CCS this is the .cmd file, on IAR it is the .xcl file.
  • In MSPGCC, you can also directly assign a target address to a compiler object like a function or variable. I never used it myself, but I think the header files that define the module registers will tell the syntax.
    However, for multiple objects, if only their target region shall be limited, then indeed, the linker file is the place where to limit the definition of the text section (where the code goes) to the flash area of interest.
  • I was able to make a new linker file, by copying the original and editing it. I have placed it in the same folder as my source code. The problem now is trying to figure out how to compile and link with the new linker file. I am not that familiar with the command line and have not had much luck doing the research online. Below is the command I am using.

    msp430-gcc -O0 -Wall -g -mmcu=msp430g2553 -c main.c
    This appears to work to compile the code

    msp430-gcc -W1, --section-start -W1, -T linker_script.x -o main.elf main.o
    But when I try to run the linker all I get is a long list of undefined references.

    Any suggestions on what I am doing wrong?
  • I'm not familiar with the later versions of mspgcc 8whcih one do you use?).
    However, on later versions of CSS, the register addresses are no longer specified in the header file but resolved by references in the linker script (this allows using precompiled libraries on multiple target MSPs). If the MSPGCC you use does it the same way, then it could be that this information is not directly in the linker script but included. And in your altered script, this inclusion somehow fails.
    Just an idea.
  • I got the problem worked out.  It was just a matter of getting the syntax for the command correct.  

    msp430-gcc -Wall main.c -T msp430.x -o main.out && msp430-objcopy -O ihex main.out main.hex..

    It will compile now and use my custom linker script to put the program at whatever address I wish.  Now I only have one main hurdle and that is to create and maintain the integrity of a custom interrupt vector table. 

     

  • The way I did it was to put the interrupt table somewhere in memory (a fixed address, of course, maybe 0xF780. the original table holds the addresses of jump instructions which are indirect jumps on this second, moved table. Except for the reset vector, which points to the bootloader. This way, the real table is never deleted and always points to the bootloader. The custom table can be erased and rebuilt by the bootloader then without risking bricking the device.
    The bootloader will then take up the area from 0xf800 to 0xFF80, including the table with the indirect jumps. If the bootloader detects that it isn't required, it can pick the application start address from the custom table's reset vector and jump there, starting the application. Except for moving the vector table segment, there is no need to fix any address. The linker will put the correct addresses in the (moved) custom vector table.
  • This method seems more reasonable than some of the other schemes I have been trying to pursue. I will try and implement it. Thank you .
  • Some problems still remain. How to put the table in at a fixed point? How to get the compiler to compile a custom vector table .
  • The easiest way is to simply define a separate linker section of the proper position and size. And either tell the compiler to put the table in a segment that is linked into this section, or tell the linker to link the table object into this section or direct memory location (this is how it is done with the hardware registers). In the latter case, the target ares should be not part of any linker section, so the linker doesn't place anythign else there (direct placement commands can cause overlapping elements, and somethimes this is intended). But don't ansk me for the syntax - I'm not that experienced with linker command files.

**Attention** This is a public forum