Vector Cortex-M0+;:Can';t从引导加载程序跳到应用程序

Vector Cortex-M0+;:Can';t从引导加载程序跳到应用程序,vector,bootloader,cortex-m,Vector,Bootloader,Cortex M,我正在使用Cortex-M0+开发ATSAMC21(ATSAMC21J18A),制作我的CAN引导加载程序。我的IDE是ATMEL studio。 闪烁我的应用程序是可以的,但当我跳入时,它失败了。(我尝试了调试和不调试) 令人沮丧的是,它指向这两条线中的第一条: *FFFFFFFE ?? ?? ??? Memory out of bounds or read error* *00000000 a0.32 adds

我正在使用Cortex-M0+开发ATSAMC21(ATSAMC21J18A),制作我的CAN引导加载程序。我的IDE是ATMEL studio。 闪烁我的应用程序是可以的,但当我跳入时,它失败了。(我尝试了调试和不调试) 令人沮丧的是,它指向这两条线中的第一条:

*FFFFFFFE ?? ??                ???      Memory out of bounds or read error*

*00000000 a0.32                 adds    r2, #160*   

我的链接器中的引导加载程序空间:

MEMORY
{
  rom      (rx)  : ORIGIN = 0x00000000, LENGTH = 0x00008000 
  ram      (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00008000 
}
MEMORY
{
  rom      (rx)  : ORIGIN = 0x00010000, LENGTH = 0x00030000 
  ram      (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00008000 
}
链接器中的应用程序(或固件)空间:

MEMORY
{
  rom      (rx)  : ORIGIN = 0x00000000, LENGTH = 0x00008000 
  ram      (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00008000 
}
MEMORY
{
  rom      (rx)  : ORIGIN = 0x00010000, LENGTH = 0x00030000 
  ram      (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00008000 
}
在跳跃之前

我禁用了irq中断,定义了入口点和堆栈指针,并更改了VTOR。 以下是我要跳转的代码:

void JumpToApp(void) {

uint16_t i;
uint32_t startAddress, applicationStack;


/* Check if WDT is locked */

if (!(WDT->CTRLA.reg & WDT_CTRLA_ALWAYSON)) {

    /* Disable the Watchdog module */

    WDT->CTRLA.reg &= ~WDT_CTRLA_ENABLE;

}
    //stop general IT
    __disable_irq();

    // Disable SysTick
    SysTick->CTRL = 0;

    // Disable IRQs & clear pending IRQs
    for (i = 0; i < 8; i++) {
        NVIC->ICER[i] = 0xFFFFFFFF;
        NVIC->ICPR[i] = 0xFFFFFFFF;
    }

    // Pointer to the Application Section 
    void (*application_code_entry)(void);

    startAddress = FLASH_APP_VADRESS; //HERE 0x00010000, my start App

    applicationStack = (uint32_t) *(volatile unsigned int*) (startAddress);

    application_code_entry = (void (*)(void))(unsigned *)(*(unsigned *)(FLASH_APP_VADRESS + 4)); //HERE 0x00010004

    // Rebase the Stack Pointer 
    __DSB();
    __ISB();    
    __set_MSP(*(uint32_t *)applicationStack); //HERE 0x00010000, my start App

    // Rebase the vector table base address 
    SCB->VTOR = ((uint32_t)startAddress & SCB_VTOR_TBLOFF_Msk);
    __DSB();
    __ISB();


    // Jump to user Reset Handler in the application 
    application_code_entry();
}
我应该为我的新MSP使用(0x20003240+0x00010000)吗


您将取消引用
SP
堆栈指针两次:

你只需要做一次。第二次将
SP
设置为零的可能性很高,一旦使用堆栈就会导致故障。

我找到了答案

最后跳转,就像atmel说的,但在我需要取消初始化某些模块之前

所以:阿特梅尔部分:

*// Pointer to the Application Section 
void (*application_code_entry)(void);
// Rebase the Stack Pointer 
__set_MSP(*(uint32_t *)FLASH_APP_VADRESS);
// Rebase the vector table base address TODO: use RAM 
SCB->VTOR = ((uint32_t)FLASH_APP_VADRESS & SCB_VTOR_TBLOFF_Msk);
// Load the Reset Handler address of the application 
application_code_entry = (void (*)(void))(unsigned *)(*(unsigned *)
(FLASH_APP_VADRESS + 4));
// Jump to user Reset Handler in the application 
application_code_entry();*
我在执行此操作之前的部分:

*Flash_Deinit(); //flash uninit
config_TC_Deinit(); //time clock uninit, scheduler
can_deinit0(); // module CAN0
can_deinit1(); // module CAN1
Handle_Wdt_Disable();
__disable_irq();



// Disable SysTick
SysTick->CTRL = 0;
SysTick->LOAD = 0;
SysTick->VAL = 0;

// Disable IRQs & clear pending IRQs
for (i = 0; i < 8; i++) {
    NVIC->IP[i] = 0x00000000;
}
NVIC->ICER[0] = 0xFFFFFFFF;
NVIC->ICPR[0] = 0xFFFFFFFF;*
*Flash_Deinit()//闪烁失谐
config_TC_Deinit()//时钟未校准,调度程序
can_deinit0();//模块CAN0
can_deinit1();//模块CAN1
Handle_Wdt_Disable();
__禁用_irq();
//禁用SysTick
SysTick->CTRL=0;
SysTick->LOAD=0;
SysTick->VAL=0;
//禁用IRQ并清除挂起的IRQ
对于(i=0;i<8;i++){
NVIC->IP[i]=0x00000000;
}
NVIC->ICER[0]=0xFFFFFFFF;
NVIC->ICPR[0]=0xFFFFFFFF*
我希望它能帮助别人!!!:)