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.

Adding boot code address to reset vector in SLAA600

Other Parts Discussed in Thread: MSP430G2553, MSP430G2432

I'm using the code from SLAA600 as a basis for adding some self test code to the BSL in the MSP430G2553. I understand (mostly) what the associated .xcl file (lnk_msp430G2553_UART_1KB_Boot.xcl) is doing except that I don't see where a value is being assigned to FLASH_RESET_VECTOR, either in the .xcl file or in the associated code. How would I force the address of my code into this vector? Thanks.

Lee

  • FLASH_RESET_VECTOR is the "real" reset vector of the MSP430, so it's located in 0xFFFE. It's defined in the Boot linker file (i.e. lnk_msp430G2432_I2C_1KB_Boot.xcl) as follows:
    -D_FLASH_RESET_VECTOR=FFFE

    And the reset vector of the bootloader (which is where the MSP430 will start execution) is:
    -Z(CODE)RESET=_FLASH_RESET_VECTOR-_FLASH_END

    It's important not to confuse this reset vector with the Application reset vector. The Application linker file (i.e. lnk_msp430G2432_I2C_1KB_App.xcl) defines the reset vector to be located at:
    -Z(CODE)RESET=_App_Reset_Vector-_App_End

    App_Reset_Vector is placed just above the Bootloader. So, if the bootloader goes from 0xFC00 to 0xFFFF, then the Application reset vector will be placed in 0xFBFE-0xFBFF

    BTW, FLASH_RESET_VECTOR is also defined in the Application linker file, but just for information purposes since the linker file doesn't use the definition for anything.


    Note that the MSP430 will ALWAYS grab the reset vector from 0xFFFE, so it will always execute the bootloader first. The bootloader then decides if it needs to jump to Application (by jumping to the Application reset vector) or if it needs to stay in bootloader mode.


    Regards,
    Luis R
  • Hi Luis,

    I understand how the vectors are set up in the .xcl file. I'm trying to find out how to have the reset vector jump to my code, rather than to the application space. I'm planning on using the built-in serial BSL in the G2553, but I want to add some extra features (check there's a complete application loaded, CRC check, etc). So I need to add the address of my code to the reset vector. It will check the validity of the application space, then jump to either the application or back to the BSL.

    Regards,
    Lee
  • Lee,

    So, you are going to use the default ROM BSL, but you are going to use a "bootloader" like SLAA600 just to validate the application?

    When using C, the reset vector is usually in a library which will handle the basic initialization (stack, variables, etc.) before jumping to main(). You can check the source code for this library at: C:\Program Files (x86)\IAR Systems\Embedded Workbench MSP430 6.20\430\src\lib\430.

    Now, you can override this initialization and write your own, and the bootloader for SLAA600 does exactly that. Check startup.s43 and you'll see that this file defines the reset_vector which will jump to main_boot() (which is the main() function for the bootloader).

    You can use the same approach and modify startup.s43 to jump to any code you want in C, or you can implement your code in the same file.

    Does this clarify your question?

    Regards,
    Luis R
  • Luis,

    It sounds like I just need to put the code I need into main, and that will get called on a reset, once everything else is set up. After I validate the application I either jump to the application start or I jump back to the BSL. Is that correct?

    Lee
  • Hi Luis,

    The BSL start vector is located at 0x0C00. I've checked this location in 2 of my current projects using a debugger and it does in fact point to the start of the BSL. However, in the restart code I'm writing to check the status of the application load, I see all zeroes in the same section of memory. Does something have to be done in order to see the BSL memory area? What I have currently is only a few lines of code. If the BSL is ROM based I should see it regardless.

    Lee
  • Hi Lee,

    I'm not sure what you are trying to do, but as far as I know, you should be able to read that area.
    What do you get with the following code?

    volatile uint16_t *temp;
    volatile uint16_t temp2;

    int main( void )
    {
    // Stop watchdog timer to prevent time out reset
    WDTCTL = WDTPW + WDTHOLD;

    temp = (uint16_t *) 0x0C00;
    temp2 = *temp;
    P1OUT &= ~BIT0;
    P1DIR |= BIT0;

    if (temp2 == 0x0C06)
    {
    P1OUT |= BIT0;
    }

    while(1)
    ;
    }

    BTW, you are using G2xx3 and not G2xx2 right? G2xx2 doesn't have BSL.

    And the only other case where I have seen memory being zero is when the IAR debugger is set to "simulator" (default configuration) instead of "FET Debugger".

    Regards,
    Luis R
  • Hi Luis,

    I did forget to set the debugger setting to FET Debugger. It was set to simulator. Thanks for the help.

    Regards,

    Lee

  • If you want your test code to be executed before initialization, you can (at least in IAR) use the pre-init function. It usually just returns 1, but if you write your own, you can do anything you want. (including to not return but jump to the bootloader instead)

    int _system_pre_init( void )
    {
    do your test code here
    return 1
    }

    Keep in mind that all your global variables are NOT initialized yet. Or contain the contend before the reset.
    You may want to keep the already initialized data, in this case simply return 0 and the startup code will skip data initialization.
    If you tell main() somehow (e.g. by changing a hardware register that is set to 0 at a PUC and not required at all by your application), you may recover from a reset this way without losing data.

    No need then to deal with the reset vector at all.
    However, if this test function itself wasn't properly loaded, your system may still crash. But you cannot avoid this unless you implement the check into the bootloader itself or use an update mechanism that has the test code fixed in application flash and never touches it, even while doing an update. This again requires a change of the bootloader (to not do a mass erase) and messing with the linker script for a moved vector table.
  • For several reasons I decided to use a stand-alone BSL, based on the BSL code from SLAA600. I put my validity check in main, after the initialization. So far this seems to meet all my requirements. We're only using the ERASE_APP command, so the BSL is untouched.

**Attention** This is a public forum