Cortex M3 的引导加载程序 [英] Bootloader for Cortex M3

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

问题描述

我正在使用来自 mbed 的 LPC 1768 板,(带有 cortex M3 cpu)并且我试图在这里实现一些东西,主要是从 SD 卡升级用户应用程序,我正在编写两个程序,首先是引导加载程序/纳米-内核和用户应用程序(helloworld 将用于开始):

I am using a LPC 1768 board from mbed, (with cortex M3 cpu) and I am trying to achieve something here, mainly upgrade the user application from the SD Card, I am writing two programs, first a bootloader/nano-kernel, and a user-app (helloworld will do for a start):

  • 0x00 地址处的引导加载程序/纳米内核运行,它会做一些检查并最终抓取 SD 卡上的二进制文件
  • Bootloader/nano-kernel 将在地址 0x9000 处复制这个二进制文件(稍后可能需要更改,但 bootloader/nano-kernel 不使用此空间,因此应该没问题)
  • 引导加载程序在 0x9000 + 4 处跳转到用户应用程序

SD 卡很容易解决,我的跳跃部分有问题.下面是跳转函数的代码.

The Sd card is quite easy to work-out, I am having issues with the jumping part. Here is the code of the jumping function.

void run(void) {

  void (*user_code_entry)(void);

  unsigned *p;   
  SCB->VTOR = (USER_FLASH_START & 0x1FFFFF80);

  // Load contents of second word of user flash - the reset handler address
  // in the applications vector table
  p = (unsigned *)(USER_FLASH_START +4); // USER_FLASH_START is 0x9000

  user_code_entry = (void (*)(void))p;

  // Jump to user application
  user_code_entry();

}

所以我已经编译(我使用的是 Keil uvision4)用户应用程序将起始地址更改为 0x9000.如果我对我的电路板进行编程(使用 flashmagictool),然后手动跳转(仍然使用 flashmagictool)到 0x9004 (0x9000 + 4),用户应用程序将运行,所以我相信编译工作正常,因此用户应用程序可以在 0x9000 运行.

So I have compiled (I am using Keil uvision4) the user application changing the start address to 0x9000. If I program my board (using flashmagictool), and then manually jump (still using flashmagictool) to 0x9004 (0x9000 + 4), the user application will run so I believe the compilation has worked ok so user-app can run at 0x9000.

但是如果我运行引导加载程序/纳米内核,这个不会跳转到用户应用程序,不幸的是,由于我无法调试,我不确定发生了什么......我也试过不使用SD 复制部分,所以我首先对引导加载程序进行编程,基本上只是跳转到 0x9004.然后我对位于 0x9000 的用户应用程序进行编程.如果我重新启动电路板,引导加载程序会运行但不会跳转到用户应用程序.我检查了内存,似乎两个程序(引导加载程序 + 用户应用程序)都正确且位于正确的位置.

But If I run the bootloader/nano-kernel, this one does not jump to the user-application and unfortunately as I cannot debug, I am not sure of what is going on... I also have tried not to use the SD copy part, so I program the bootloader first with basically just the jump to 0x9004. I then program the user application that will sit at 0x9000. If I reboot the board, bootloader runs but does not jump to user-app. I have checked memory, and it seems that both programs (bootloader + user-app) are correct and at the right place.

我确定我在这里遗漏了一些东西,有没有我应该查看的低级代码?我已经在线阅读了大量文档,从我找到的示例中,他们以与我相同的方式跳转到用户代码......非常感谢您的帮助.

I am sure I am missing something here, is there any low-level code I should be looking at ? I have read tones of docs online, and from the examples I have found, they are jumping to user code the same way as I do... Thanks a lot for any help.

推荐答案

Cortex M3 只能在 Thumb 模式下运行.因此你总是要跳转到地址+1,否则会产生一个错误.

Cortex M3 can only run in Thumb mode. Thus you always have to jump to address +1, otherwise it will generate a fault.

试试吧:

user_code_entry = (void (*)(void))(USER_FLASH_START +4 +1);

这篇关于Cortex M3 的引导加载程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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