如何在 Stellaris 中的程序之间跳转 [英] How to jump between programs in Stellaris

查看:19
本文介绍了如何在 Stellaris 中的程序之间跳转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 Stellaris LM3S1607 芯片开发引导加载程序.我正在使用 Keil MicroVision4 C 编译器.这个想法是创建 2 个独立的固件,一个将更新另一个.在固件 1 中,我下载了固件 2 文件并将其写入地址 0x3200 的闪存.直到这里它正在工作.我还验证了数据是否正确写入闪存.现在我有两个应用程序.一个是我的 uip 引导加载程序,而 seoncd 一个是我的主要项目.我想知道如何从第一个程序跳转到位于 0x3200 的第二个程序.

I am working on a boot loader for Stellaris LM3S1607 chip. I am using Keil MicroVision4 C compiler. The idea is to create 2 independent firmware that one will update another. In firmware1 i downloaded firmware2 file and write it to flash in address 0x3200. untill here it is working. i also verifed that the data is being written to flash correct. Now i have in flash two applications. one is my uip boot loader and the seoncd one is my main project. i want to know how can i jump from the first program to the second program located in 0x3200.

如果有人可以帮我跳,那就太好了.谢谢

If someone can help me to jump it will be great. Thanks

推荐答案

这适用于任何 Cortex-M 部件...

This will work on any Cortex-M part...

创建一个汇编函数,如:

Create an assembler function like:

__asm void boot_jump( uint32_t address )
{
   LDR SP, [R0]       ;Load new stack pointer address
   LDR PC, [R0, #4]   ;Load new program counter address
}

内联汇编语法各不相同;这个例子是 Keil ARM-MDK/ARM RealView.

In-line assembler syntax varies; this example is Keil ARM-MDK / ARM RealView.

然后在引导加载程序结束时:

Then at the end of your bootloader:

// Switch off core clock before switching vector table
SysTick->CTRL = 0 ;

// Switch off any other enabled interrupts too
...

// Switch vector table
SCB->VTOR = APPLICATION_START_ADDR ;

//Jump to start address
boot_jump( APPLICATION_START_ADDR ) ;

请注意,在这种情况下,APPLICATION_START_ADDR 是链接应用程序代码的基地址或位置地址(在这种情况下为 0x3200),而不是链接映射中指示的入口点.应用程序向量表位于该地址,向量表的开头包含应用程序的初始堆栈指针地址和程序计数器(实际代码入口点).

Note that APPLICATION_START_ADDR in this case is the base or location address of your linked application code (0x3200 in this case), not the entry point indicated in the link map. The application vector table is located at this address, and the start of the vector table contains the application's initial stack pointer address and program counter (the actual code entry point).

boot_jump() 函数从应用程序的向量表中加载堆栈指针和程序计数器,模拟从闪存基址(引导加载程序的向量表)加载它们的复位时发生的情况.

The boot_jump() function loads a stack pointer and program counter from the application's vector table, simulating what happens on reset where they are loaded from the base of Flash memory (the bootloader's vector table).

请注意,您必须在应用程序代码的链接器设置中将起始地址设置为与引导加载程序将复制映像的起始地址相同.如果您使用的是 Keil 调试器,您将无法在没有引导加载程序存在的情况下在调试器中加载和运行应用程序(或者至少在没有正确手动设置 SP 和 PC 或使用调试器脚本的情况下),因为调试器会加载重置向量地址而不是应用程序向量地址.

Note that you must have set the start address in your application code's linker settings to the same as that which the bootloader will copy the image. If you are using the Keil debugger, you will not be able to load and run the application in the debugger without the bootloader present (or at least without manually setting the SP and PC correctly or using a debugger script), because the debugger loads the reset vector addresses rather than the application vector addresses.

在切换向量表之前禁用中断很重要,否则在应用程序初始化之前发生的任何中断都会向量到应用程序的处理程序,并且可能还没有准备好.

It is important that interrupts are disabled before switching the vector table, otherwise any interrupt that occurs before the application is initialised will vector to the application's handler, and that may not be ready.

请注意您在应用程序和引导代码中使用的任何外设,如果引导代码已经设置了外设寄存器,则有关复位条件的任何假设都可能不成立.

Be careful of any peripherals that you use in both the application and boot code, any assumptions about reset conditions may not hold if the peripheral registers have already been set by the boot code.

这篇关于如何在 Stellaris 中的程序之间跳转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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