#include <atmel_start.h>

#define SECOND_APP_START_ADDRESS 0x2000

void jump_to_secondary()
{
        uint32_t app_start_address;
        app_start_address = *(uint32_t *)(SECOND_APP_START_ADDRESS + 4);

        /* Rebase the Stack Pointer */
        __set_MSP(*(uint32_t *)SECOND_APP_START_ADDRESS);

        /* Rebase the vector table base address */
        SCB->VTOR = ((uint32_t)SECOND_APP_START_ADDRESS & SCB_VTOR_TBLOFF_Msk);

        /* Jump to application Reset Handler in the application */
        asm("bx %0" ::"r"(app_start_address));
}
