0

I want to write a bootloader for my stm32l4 mcu which (after pressing a button) jumps to another part of flash and run the app on that part. for application part I write a simple blinky and generate its BIN file and copy this bin file to address 0x0800 8000 of flash memory.

Now I do not know how can I jump to this address and run this blinky app.

would anyone help me?

best!

  • I'd mark this as a duplicate of https://stackoverflow.com/questions/14393715/how-to-jump-between-programs-in-stellaris/14406706 except that is for Stellaris - the answer however applies to any Cortex-M3 or M4. – Clifford Aug 29 '21 at 16:54
  • Why exactly can't you use a function? Are you flashing the code in multiple steps or something? Running code from data flash? – Lundin Aug 30 '21 at 10:23

2 Answers2

0

At least two alternatives spring to mind:

  1. Use a function pointer:

        /* ... */
        void (*app)(void) = (void (*)(void))0x08008000;
        app();
    
  2. Declare an external function and resolve it with your linker script:

        /* ... */
        void app(void);
        app();
    

    How to define the address in the linker script depends on your linker.

the busybee
  • 10,755
  • 3
  • 13
  • 30
  • Would you explain more? – Amin-nano-sys Aug 29 '21 at 12:37
  • What exactly do you want to know? – the busybee Aug 29 '21 at 15:28
  • 1
    There are other issues to consider, such as disabling interrupts and possible re-initialisation of some hardware devices. Also that code will still be using the bootloader rather than the application stack and vector table. `0x08008000` is the start of the application vector table, not the application entry point. The vector table start has the stack-pointer and reset-vector address in that order. You need to load these to SP and PC to effect a valid application switch. – Clifford Aug 29 '21 at 16:57
0

I guess you could also rewrite the Interrupt Vector Table. I dont know exactly how the stm32l4 works, but have a look at the start up code. At some point it loads the program counter with a predefined value. You could rewrite this value and reset the MCU.