[转]Cortex-M3 跳转到指定bin执行 - uTank - 博客园

 跳转前指定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, #2    msr    control, r0    bx  lr}#endif

跳转到指定地址:

 

 1 typedef int (*jump_fun)( void ); 2  3 void jump( unsigned int addr ) 4 { 5     volatile int *ptr = (int *)addr; 6     jump_fun jump; 7  8     set_msp(); 9     set_sp(ptr[0]);10     11     jump = (jump_fun)(ptr[1]);12 13     jump();14 }

 


---------------------
作者:uTank
来源:CNBLOGS
原文:https://www.cnblogs.com/utank/p/8151189.html
版权声明:本文为作者原创文章,转载请附上博文链接!
内容解析By:CSDN,CNBLOG博客文章一键转载插件

posted @ 2021-09-23 17:21  decrement  阅读(89)  评论(0编辑  收藏  举报