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.

Custom Reset Vector

Other Parts Discussed in Thread: MSP430F2274

Hi all,

Using Code Composer V5 to develop for MSP430F22724. There must be a simple solution to this. We are doing an energy harvesting application where the #bootup cycles are critical. I would like to write my own bootloader. I've tried using:

Tried In C

#pragma vector = RESET_VECTOR

void mySuperBoot (void) {

         // do stuff

}

Or In ASM

.sect '.reset'

.word 0x8000   ;if 0x8000 is addr of mySuperBoot()

Not Working

- The C version won't deploy into debug mode, it says:

'load program error, data verification failed at addr 0x0000000. Please verify.'

- The ASM version won't compile, it says

../lnk_msp430f2274.cmd", line 89: error: placement fails for object ".reset",   size 0x4 (page 0).  Available ranges:
   RESET        size: 0x2          unused: 0x2          max hole: 0x2

Question

How/Can I set my own .reset vector? This must be an easy problem to solve...

Thanks,

 Justin Reina

 

*I have done an appropriate (hopefully) amount of reading through slau132d, slau131c and TI E2E but have not found a working solution.

 

  • Hi,

     

    From MSP430 Optimizing C/C++ Compiler v 3.1 (slau132c) you must read chapter 6.9 System Initialization. The solution is there.

    "The _c_int00( ) initialization routine also provides a mechanism for an application to perform the MSP430
    setup (set I/O registers, enable/disable timers, etc.) before the C/C++ environment is initialized.
    Before calling the routine that initializes C/C++ global data and calls any C++ constructors, the boot
    routine makes a call to the function _system_pre_init( ). A developer can implement a customized version
    of _system_pre_init( ) to perform any application-specific initialization before proceeding with C/C++
    environment setup. In addition, the default C/C++ data initialization can be bypassed if _system_pre_init( )
    returns a 0. By default, _system_pre_init( ) should return a non-zero value.
    In order to perform application-specific initializations, you can create a customized version of
    _system_pre_init( ) and add it to the application project. The customized version will replace the default
    definition included in the run-time library if it is linked in before the run-time library.
    The default stubbed version of _system_pre_init( ) is included with the run-time library. It is located in the
    file pre_init.c and is included in the run-time source library (rts.src). The archiver utility (ar430) can be
    used to extract pre_init.c from the source library."

     

    Best regards,

    AES

  • I don't know how I missed that, thanks!! I'll work through this and give it a shot.

     

    Thanks,

     Justin Reina

  • Hi again,

    I remember this old discussion. Please, verify it also.

     

    Best Regards,

    AES

  • Besides the (correct) answer from aes, some additional info:

    The ISR that is called by the reset vector is not a typical ISR. When it is called, teh stack isn't initialized (so there are no local variables possible). Global variables haven't been initialized too (this is the job of this function!)
    For this reason, you simply cannot do it in C language. You'd need a setup function that sets up the C environment for your reset function that is supposed to do the set up for your C application :)

    The linker will usually automatically link a prebuilt assembly function that does all the stuff, initializing variables and initializing the stack. And then it simply jumps to main. So except for some very rare cases, the beginning of main is what comes right after the C initialization.

    There are, however, some entry points that allow you inserting some stuff if really necessary. E.g. reconfiguring the WDT, or setting up some port pins that must be set as fast as possible. Usually, you can do all this at the beginning of main.

    So from a C point of view, main() is your reset vector.

    Why didn't it work in ASM? Simply because the init function was still automatically added by the linker. So the linker ended up with two word values to be placed in the 2 bytes reset vector. Which doesn't work of course. You'll get the same error if you define two different ISRs for any other interrupt vector (e.g. in two different C files).

**Attention** This is a public forum