Question
Hard Fault jumping to System Memory
Posted on September 22, 2017 at 19:42
Hi,
I am testing some code in a STM32F446 to jump to the system memory from my firmware. I am using this code:
void JumpToBootloader(void){
void(*SysMemBootJump)(void); volatile uint32_t addr = 0x1FFF76DE; /** * Step: disable RCC, set it to default (after reset) settings * Internal clock, no PLL, etc. */ HAL_RCC_DeInit(); /** * Step: disable systick timer and reset it to default values */ SysTick->CTRL = 0; SysTick->LOAD = 0; SysTick->VAL = 0; __disable_irq(); /** * Step: Remap system memory address 0x0000 0000 in addres space */ __HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH(); /** * Step: Set jump memory location for system memory * Use address with 4 bytes offset which specifies jump location * where program starts. */ SysMemBootJump = (void(*)(void)) (*((uint32_t *)(addr + 4))); /** Step: Set main stack pointer **/ __set_MSP(*(uint32_t*)addr);/**
* Step: actually call our function to jump to set location * This will start system memory execution */ SysMemBootJump();}The fact is that when the MCU boots it goes to a Hard Fault from SysMemBootJump() instruction.
I am wondering whether I should configure the memory using the MPU to jump there.
The address used by the bootloader is from the AN.
Anyone could give me a clue about what is wrong with my code?
Thanks in advanced,
Omar
#hard-fault #system-memory #bootloader