【发布时间】:2021-10-26 14:09:27
【问题描述】:
我正在使用基于 STM32F4 的定制板,带有 2MB 内部闪存。
- 我有一个小的自定义最小引导加载程序应用程序(它转到位于内部闪存中 0x08000000 的扇区 0) 我的用户应用程序存储在内部闪存中位于 0x08020000 的扇区 5 中。所以我的引导加载程序不会在 MCU 的内部闪存中刷新任何用户应用程序。它只跳转到用户应用程序。 自定义引导加载程序使用对此函数的调用跳转到应用程序:bootloader_jump_to_user_app:
uint32_t nAppAdr=0x08020000;
bool bootloader_jump_to_user_app(uint32_t nAppAdr)
{
bool ret = true;
void(*app_reset_handler)();
//shut down any tasks remaining
HAL_RCC_DeInit();// to turn off the PLL and set the clock to it's default state
HAL_DeInit();// to disable all the peripherals
SysTick->CTRL = 0;//to turn off the systick
SysTick->LOAD = 0;
SysTick->VAL = 0;
//disable interrupts
__set_PRIMASK(1);
__disable_irq();.
SCB->VTOR = nAppAdr;//change this
//configure the MSP by reading the value from the base address
uint32_t msp_value = *(__IO uint32_t*) nAppAdr;
__set_MSP(msp_value);
uint32_t resethandler_address = *(__IO uint32_t*) (nAppAdr + 4);
//app_reset_handler = (void*)resethandler_address;
app_reset_handler = (void (*)(void)) (*((uint32_t*)(resethandler_address)));
//jump to reset handler of the user app.
app_reset_handler();
return ret;
}
- 在我的用户应用程序中,在文件 system_stm32f4xx.c 中,我定义了 USER_VECT_TAB_ADDRESS,并将 VECT_TAB_OFFSET 设置为 0x08020000(在我的用户应用程序的内部闪存中的位置
#define USER_VECT_TAB_ADDRESS
#define VECT_TAB_OFFSET 0x00020000
这应该使我的用户应用程序可引导加载。
- 我在内部闪存的第 5 扇区(起始地址 0x08020000)中刻录了我的用户应用程序。我检查了这一步(比较此位置的前几个字节与 bin 文件的前几个字节)。
执行自定义引导加载程序时,函数 bootloader_jump_to_user_app 的最后一条语句,特别是对 app_reset_handler() 的调用,会导致以下类型的异常: “硬故障异常。 处理器已将可配置优先级异常升级到 HardFault。 指令预取 (CFSR.IBUSERR,BFAR) 发生总线故障。 异常发生在 PC=0x1478048, LR=0x8000f85 "
这应该很简单。有什么我想念的吗?为什么我得到例外? 任何帮助表示赞赏 谢谢
【问题讨论】:
标签: bootloader stm32f4