STM32F4 custom bootloader jump ends up in hard fault
MCU: STM32F429IIT
I've written my first custom bootloader for the STM32. It takes a .hex-file from an SD-card, flashes it and jumps to that application.
The hex-parser and writing the flash works perfectly, I've double-checked that.
I've written a small example project (500ms timer toggles LED in interrupt). With the .hex file of that project, the bootloader works totally fine. (Flashes the application, jumps to the start-address and executes the application).
Now I want to do the same thing with my actual project, but it ends up in a hard fault everytime. The Fault Analyzer says "Attempt to switch to invalid state" after I execute the jump command.
Register content during fault exception:
Jump-Command:
void bootloader_jumpToAddress(uint32_t address)
{
void (*SysMemBootJump)(void);
_bootloader_DeInitTasks(); //custom function to disable SDIO, GPIO, Timers,...
__disable_irq();
SYSCFG->MEMRMP = 0x01;
SysMemBootJump = (void (*)(void)) (*((uint32_t *)(address + 4)));
__set_MSP(*(uint32_t *)address);
SysMemBootJump();
}STM32F429IITX_FLASH.ld (example project)
MEMORY
{
CCMRAM (xrw) : ORIGIN = 0x10000000, LENGTH = 64K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 192K
FLASH_BOOT (rx) : ORIGIN = 0x8000000,
LENGTH = 64K
FLASH (rx) : ORIGIN = ORIGIN(FLASH_BOOT) + LENGTH(FLASH_BOOT),
LENGTH = 2048K - LENGTH(FLASH_BOOT) - 256K
}STM32F429IITX_FLASH.ld (actual project)
MEMORY
{
CCMRAM (xrw) : ORIGIN = 0x10000000,
LENGTH = 64K
RAM (xrw) : ORIGIN = 0x20000000,
LENGTH = 192K
FLASH_BOOT (rx) : ORIGIN = 0x8000000,
LENGTH = 64K
FLASH (rx) : ORIGIN = ORIGIN(FLASH_BOOT) + LENGTH(FLASH_BOOT),
LENGTH = 2048K - LENGTH(FLASH_BOOT) - 256K
EMULATED_EEPROM (rw) : ORIGIN = 0x8200000 - 2 * 128K,
LENGTH = 2 * 128K
XRAM (xrw) : ORIGIN = 0xD00BF400, LENGTH = (8M - 0xBF400) /* allocate 1M for LTDC framebuffer */
}system_stm32f4xx.c (actual and example project):
/* Note: Following vector table addresses must be defined in line with linker
configuration. */
/*!< Uncomment the following line if you need to relocate the vector table
anywhere in Flash or Sram, else the vector table is kept at the automatic
remap of boot address selected */
#define USER_VECT_TAB_ADDRESS
#if defined(USER_VECT_TAB_ADDRESS)
/*!< Uncomment the following line if you need to relocate your vector Table
in Sram else user remap will be done in Flash. */
/* #define VECT_TAB_SRAM */
#if defined(VECT_TAB_SRAM)
#define VECT_TAB_BASE_ADDRESS SRAM_BASE /*!< Vector Table base address field.
This value must be a multiple of 0x200. */
#define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field.
This value must be a multiple of 0x200. */
#else
#define VECT_TAB_BASE_ADDRESS FLASH_BASE /*!< Vector Table base address field.
This value must be a multiple of 0x200. */
#define VECT_TAB_OFFSET 0x00010000U /*!< Vector Table base offset field.
This value must be a multiple of 0x200. */
#endif /* VECT_TAB_SRAM */
#endif /* USER_VECT_TAB_ADDRESS */
/******************************************************************************/main.c (actual and example project):
/* USER CODE BEGIN 1 */
__enable_irq();
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
...
...
...I'm not sure where to start my debugging session. The actual project is kinda big and has a lot of potential harms: FreeRTOS, TouchGFX, EMULATED-EEPROM (using flash as eeprom), XRAM (external RAM on FMC), audio applications, ARM-CMSIS, FATFS, USB-DEVICE, RTC,...)
Thanks in advance!
