用于Cortex M4的Bootloader-跳至已加载的应用程序 [英] Bootloader for Cortex M4 - Jump to loaded Application

查看:708
本文介绍了用于Cortex M4的Bootloader-跳至已加载的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Atmel SAM4E-EK板上使用Atmel SAM4E-16e.我已经为此配置编写了一个引导程序. 引导加载程序通过UART接收.bin文件,并将其写入Flash.这项工作没有问题,我进行了十六进制转储,这正是我所期望的:

I am using a Atmel SAM4E-16e on Atmel SAM4E-EK Board. I have written a bootloader for this configuration. The bootloader receives the .bin-File via UART and writes it into Flash. This works without problems, i made a hex-dump and it was exactly what i expected:

  • 引导加载程序位于0x400000(AT SAM4E的Flash起始地址)
  • 我在0x420000处的申请
  • 0x800000是Flash结束地址

这是C代码:

int main(void){
     // Init and downloading the .bin to Flash
     binary_exc((void*) 0x420000);
}



int binary_exec(void * vStart){
    int i;
    // -- Check parameters
    // Should be at least 32 words aligned
    if ((uint32_t)vStart & 0x7F)
    return 1;

    Disable_global_interrupt();
    // Disable IRQs
    for (i = 0; i < 8; i ++) NVIC->ICER[i] = 0xFFFFFFFF;
    // Clear pending IRQs
    for (i = 0; i < 8; i ++) NVIC->ICPR[i] = 0xFFFFFFFF;

    // -- Modify vector table location
    // Barriars
    __DSB();
    __ISB();
    // Change the vector table
    SCB->VTOR = ((uint32_t)vStart & SCB_VTOR_TBLOFF_Msk);
    // Barriars
    __DSB();
    __ISB();

    Enable_global_interrupt();

    // -- Load Stack & PC
    _binExec(vStart);
    return 0;
}

void _binExec (void * l_code_addr){
    __asm__ ("mov   r1, r0        \n"
    "ldr   r0, [r1, #4]  \n" //I also tryed #5 but that doesn't work, too
    "ldr   sp, [r1]      \n"
    "blx   r0"
    );
}

但是当我尝试跳转到我的应用程序时,该应用程序无法启动. 跳转到该程序的代码来自于SAM8X(Cortex M3)的Atmel示例.调试器说有时PC会跳到另一个地址(0x004003E2),但不会继续.

But when i try to jump to my application, the Application does not start. The code for jumping to the program is out of an example of Atmel for the SAM8X (Cortex M3). The debugger says sometimes that it the PC jumps to another Address (0x004003E2) instead, but does not go on.

我发现了旧主题用于Cortex M3的Bootloader ,解决方案是仅添加一个但这对我不起作用,即使我使用了他们的代码也是如此.然后调试器不再响应.

I found the old topic Bootloader for Cortex M3 where the solution was to just add one but this doesn't work for me, even if i used their code. Then the debugger does not responds any more.

我正在将Atmel Studio 7与GCC一起使用.处理器以拇指模式运行.

I am using Atmel Studio 7 with GCC. The processor runs in Thumb-Mode.

希望您能帮助我解决此问题,或者给我一些提示,以解决这里出现的问题.

I hope you can help me to solve this problem or give me some tipps what is going wrong here.

推荐答案

我现在已经解决了这个问题. 我仍然使用我在问题中发布的代码.问题在于,我在处理器的闪存上写入的.bin文件位于0x420000,其编译方式使其认为位于闪存起始地址(0x400000). 加载复位向量的地址后,它位于0x400xyz而不是0x420xyz,因此应用程序跳到了错误的地址.

I have solved the problem now. I still use the code I posted in my question. The problem was that the .bin-file i write on my processor's flash at 0x420000 was compiled in a way that it thought it is at flash start address (0x400000). When it has loaded the reset vector's address it was at 0x400xyz instead of 0x420xyz so the application jumped to the wrong address.

解决方案是将要通过引导加载程序上传的项目中的Flash起始地址更改为0x420000.

The solution was to Change the Flash start address to 0x420000 in the project I want to upload via bootloader.

这篇关于用于Cortex M4的Bootloader-跳至已加载的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆