简体   繁体   English

STM32:从自定义引导加载程序跳转到应用程序时出现硬故障

[英]STM32: hard fault when jumping to application from custom bootloader

I'm working on a STM32F401 MCU with custom bootloader and application.我正在开发带有自定义引导加载程序和应用程序的 STM32F401 MCU。 Compiler is GCC 5.2.1, not optimizations are running.编译器是 GCC 5.2.1,没有优化正在运行。

I'm getting a hardfault after the first interrupt after the following jump sequence: bootloader -> application -> bootloader -> application.在以下跳转序列后的第一个中断后,我遇到了硬故障:引导加载程序->应用程序->引导加载程序->应用程序。 After the first jump to the application from the bootloader, the system is working properly.从引导加载程序第一次跳转到应用程序后,系统工作正常。 However, after jumping to the application after jumping back to the bootloader (I'm not resetting the board on purpose), the hardfault happens after the first interrupt that may be anything from SysTick to EXTI.但是,在跳回引导加载程序后跳转到应用程序后(我不是故意重置板),硬故障发生在第一个中断之后,可能是从 SysTick 到 EXTI 的任何东西。

What could be the reason for this?这可能是什么原因? Anything that I'm not updating?有什么我不更新的吗? Thanks.谢谢。

stubs of the code:代码的存根:

jumping procedure (for both programs; application is at 0x08008000 and bootloader is at 0x08000000):跳转过程(对于两个程序;应用程序位于 0x08008000,引导加载程序位于 0x08000000):

typedef  void (*pFunction)(void);
uint32_t appStack;
pFunction appEntry;

//Jump to address
/* Get the application stack pointer */
appStack = (uint32_t) * ((__IO uint32_t*)address);
/* Get the application entry point */
appEntry = (pFunction) * (__IO uint32_t*) (address + 4);

/* Reconfigure vector table offset */
SCB->VTOR = address;

__set_MSP(appStack);

appEntry();

application cleanup before jumping:跳转前的应用程序清理:

osThreadSuspendAll();
__disable_irq();
SysTick->CTRL =0;
SysTick->LOAD=0;
SysTick->VAL=0;

__set_PRIMASK(1);

HAL_UART_DeInit(&huart2);
HAL_I2C_DeInit(&hi2c1);
HAL_RCC_DeInit();
HAL_DeInit();

禁用引导加载程序中使用的所有外围设备,然后跳转到应用程序解决了该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM