[英]Bootloader for Cortex M3
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): 我正在使用mbed的LPC 1768板(带有cortex M3 cpu),我正在尝试在这里实现一些功能,主要是从SD卡升级用户应用程序,我正在编写两个程序,首先是一个bootloader / nano-kernel,以及一个用户应用程序(helloworld将开始):
The Sd card is quite easy to work-out, I am having issues with the jumping part. Sd卡很容易锻炼,我遇到了跳跃部分的问题。 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();
} }
So I have compiled (I am using Keil uvision4) the user application changing the start address to 0x9000. 所以我编译了(我使用Keil uvision4)用户应用程序将起始地址更改为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.
如果我编程我的电路板(使用flashmagictool),然后手动跳转(仍使用flashmagictool)到0x9004(0x9000 + 4),用户应用程序将运行,所以我相信编译工作正常,因此用户应用程序可以在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. 但是,如果我运行bootloader / nano-kernel,这个没有跳转到用户应用程序,不幸的是因为我无法调试,我不知道发生了什么...我也试过不使用SD副本部分,所以我首先编程引导加载程序,基本上只是跳转到0x9004。 I then program the user application that will sit at 0x9000.
然后我编写将位于0x9000的用户应用程序。 If I reboot the board, bootloader runs but does not jump to user-app.
如果我重启电路板,bootloader会运行,但不会跳转到用户应用程序。 I have checked memory, and it seems that both programs (bootloader + user-app) are correct and at the right place.
我检查了内存,似乎两个程序(bootloader + user-app)都是正确的并且位于正确的位置。
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 can only run in Thumb mode. Cortex M3只能在Thumb模式下运行。 Thus you always have to jump to
address +1
, otherwise it will generate a fault. 因此,您始终必须跳转到
address +1
,否则会产生故障。
Just try: 试一试:
user_code_entry = (void (*)(void))(USER_FLASH_START +4 +1);
Just read the AN10866 document on NXP Site. 请阅读恩智浦网站上的AN10866文档。 You have load the PC and Stack pointer and then jump to the reset interrupt:
您已加载PC和堆栈指针,然后跳转到重置中断:
__asm void boot_jump( uint32_t address ){
LDR SP, [R0] ;Load new stack pointer address
LDR PC, [R0, #4] ;Load new program counter address
}
void execute_user_code(void)
{
/* Change the Vector Table to the USER_FLASH_START
in case the user application uses interrupts */
SCB->VTOR = USER_FLASH_START & 0x1FFFFF80;
boot_jump(USER_FLASH_START);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.