STM32: hard fault when jumping to application from custom bootloader

家住魔仙堡 提交于 2019-12-05 06:42:10

问题


I'm working on a STM32F401 MCU with custom bootloader and application. Compiler is GCC 5.2.1, not optimizations are running.

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.

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):

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();

来源:https://stackoverflow.com/questions/38453553/stm32-hard-fault-when-jumping-to-application-from-custom-bootloader

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!