简体   繁体   中英

STM32: hard fault when jumping to application from custom bootloader

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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