Skip to main content
Omar Suárez
Senior
September 22, 2017
Question

Hard Fault jumping to System Memory

  • September 22, 2017
  • 8 replies
  • 1496 views
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
This topic has been closed for replies.

8 replies

Tesla DeLorean
Guru
September 22, 2017
Posted on September 22, 2017 at 20:08

>>Anyone could give me a clue about what is wrong with my code?

You are using a non-sense address.

What is at 0x1FFF76DE? The address of the function you want to call? A vector table?

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Omar Suárez
Senior
September 22, 2017
Posted on September 22, 2017 at 20:39

Hi Clive,

you were totally right, the address I was using was the one containing the bootloader ID. The system memory begins in the 0x1FFF0000 address.

Now it doesn't throw the Hard Fault error.

But I am not sure I am entering the systme memory because the Flahs Loader application can't connect using the USART3.

How can I sure I am accessing the system memory correctly?

Thanks for your help!

Omar

Tesla DeLorean
Guru
September 22, 2017
Posted on September 22, 2017 at 20:43

>>How can I sure I am accessing the system memory correctly?

With a half descent debugger you can step into it.

I've generally advised that you jump into it with near reset conditions, and that you map the ROM into the zero address space, as it would be if BOOT0 = High.

Does USART3 work if you strap BOOT0=High and reset?

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..