Search code examples
cembeddedstm32microcontrollerboot

Memory Aliasing to a specific Flash Sector


I have an STM32 Mcu in which I flashed a BootLoader at the start of the Flash (0x0800_0000) and an Application at the 0x0801_0000 address (Sector 4).

If I am debugging my Application code and I reset the chip, the code switches to the Bootloader. I understand from this that the 0x0800_0000 address is aliased to the 0x0000_0000 of the Cpu and the mcu will always execute the code from the Bootloader first after reset.

My question is, is it possible for me to alias the 0x0000_0000 address to the Application start address (or generally speaking to a specific address in the Flash memory other than 0x0800_0000) so that it starts from there directly after reset ?


Solution

  • That depends on the STM32 model. In some STM32F7, H7 and other models you have special option bytes which specify the boot address

    Most STM32 MCUs does not have it and the processor starts from the beginning of FLASH (or RAM / system ROM - but it is not interesting for us now). The bootloader should check presence of the firmware and its integrity and then pass the control to the firmware by

    • setting the stack pointer
    • setting the vector table
    • disabling interrupts
    • putting all used by bootloader peripherals to the reset state

    and eventually calling the firmware reset handler.