Cortex M4 的引导加载程序 - 跳转到加载的应用程序 [英] Bootloader for Cortex M4 - Jump to loaded Application

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

问题描述

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

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 的闪存起始地址)
  • 我的应用程序在 0x420000
  • 0x800000 是闪存结束地址

这是 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"
    );
}

但是当我尝试跳转到我的应用程序时,应用程序没有启动.跳转到程序的代码出自 Atmel for SAM8X (Cortex M3) 的示例.调试器有时会说 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 的引导加载程序,其中的解决方案是添加一个但这对我不起作用,即使我使用了他们的代码.然后调试器不再响应.

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.处理器在 Thumb 模式下运行.

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 的引导加载程序 - 跳转到加载的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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