我有一块1170的板卡,现在想实现的功能是bootloader读取U盘中的文件,然后载入到SDRAM中,最后跳转到SDRAM的指定地址(应用的起始地址)去运行程序,现在问题如下:
bootloader能正常识别U盘并读取镜像文件,参考官方bootloader的例程,通过
static void get_user_application_entry(uint32_t *appEntry, uint32_t *appStack)
{
assert(appEntry);
assert(appStack);
*appEntry = APP_VECTOR_TABLE[kInitialPC];
*appStack = APP_VECTOR_TABLE[kInitialSP];
}
此函数能获取AppEntry和appStack,调试发现appEntry为0x8007c1e1(与应用map文件对应为Reset_Handler的地址),appStack为0x20040000 ,与应用map文件一致:
整个跳转的主体函数如下
static void jump_to_application(void)
{
uint32_t applicationAddress, stackPointer;
get_user_application_entry(&applicationAddress, &stackPointer);
__disable_irq();
// Create the function call to the user application.
// Static variables are needed since changed the stack pointer out from under the compiler
// we need to ensure the values we are using are not stored on the previous stack
static uint32_t s_stackPointer = 0;
s_stackPointer = stackPointer;
static void (*farewellBootloader)(void) = 0;
farewellBootloader = (void (*)(void))applicationAddress;
// Set the VTOR to the application vector table address.
SCB->VTOR = (uint32_t)BL_APP_VECTOR_TABLE_ADDRESS;//BL_APP_VECTOR_TABLE_ADDRESS -- 0x80040000
// Set stack pointers to the application stack pointer.
__set_MSP(s_stackPointer);
__set_PSP(s_stackPointer);
// Jump to the application.
farewellBootloader();
usb_echo("never goto here.\r\n");
}
我之前的问题是跳转不成功,现在已经搞定了
the bootloader uses ram.icf link file