Cortex-M3 跳转到指定bin执行

时间:2022-12-14 02:03:35

跳转前指定sp和msp:

#if defined(__GNUC__)
__attribute__(( naked )) static void set_sp(unsigned long addr)
{
__asm volatile (
"mov sp, r0 \n"
"bx lr \n"
);
} __attribute__(( naked )) static void set_msp(void)
{
__asm volatile (
"mrs r0, control \n"
"bic r0, #2 \n"
"msr control, r0 \n"
"bx lr \n"
);
}
#else
__asm static void set_sp(unsigned long addr)
{
mov sp, r0
bx lr
} __asm static void set_msp(void)
{
mrs r0, control
bic r0, #
msr control, r0
bx lr
}
#endif

跳转到指定地址:

 typedef int (*jump_fun)( void );

 void jump( unsigned int addr )
{
volatile int *ptr = (int *)addr;
jump_fun jump; set_msp();
set_sp(ptr[]); jump = (jump_fun)(ptr[]); jump();
}