Search code examples
stm32linker-scriptsmemory-mappinggnu-arm

STM32 Boot from specific NOR block


I've ported an STM32F4 project from Keil uVision5 to Eclipse (GNU MCU Plugin).

In my Keil uVision5 project, I used to use 7th block (0x080E0000) for my boot code (I verify that using STM32 ST-LINK Utility tool that my boot code is really at 7th block) which I used to configure very easily using Keil uVision5 interface as shown below:

enter image description here

If I'm not mistaken, in my Keil uVision project (whose memory configuration is shown above), the MCU boots from 0th block (0x08000000) and then jumps immediately to 7th block (0x080E0000) to execute my code. Tell me if I'm wrong.

My problem is with my Eclipse project. As you might already know, we configure the memory map using a linker script file named mem.ld. I tried to imitate the same behavior using mem.ld but I suppose that I've failed. Whenever I flash the executable generated by Eclipse, my code doesn't run. Moreover, I couldn't find a way to indicate an area for startup in mem.ld file. Below is my memory configuration in mem.ld file:

MEMORY
{
    RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
    CCMRAM (xrw) : ORIGIN = 0x10000000, LENGTH = 64K
    FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 16K
    FLASHB1 (rx) : ORIGIN = 0x080E0000, LENGTH = 640K
    EXTMEMB0 (rx) : ORIGIN = 0x00000000, LENGTH = 0
    EXTMEMB1 (rx) : ORIGIN = 0x00000000, LENGTH = 0
    EXTMEMB2 (rx) : ORIGIN = 0x00000000, LENGTH = 0
    EXTMEMB3 (rx) : ORIGIN = 0x00000000, LENGTH = 0
    MEMORY_ARRAY (xrw)  : ORIGIN = 0x20002000, LENGTH = 32
}

Could you please help me to imitate the same behavior with Keil uVision5 using mem.ld file? What mistake do I do in mem.ld configuration? What should be the correct configuration?

Thanks a lot in advance.


Solution

  • The address of the code which is executed after the reset is taken from the 4-7 bytes of your vector table (it is called the reset vector).

    In the gcc style linker script the ENTRY directive is important not your memory sections definitions.

    you can change the entry to the address value or a symbol. For example

    ENTRY(My_Startup_Function) or as it is in the standard linker scripts generated by the CubeMX ENTRY(Reset_Handler)

    in keil as I remember you have couple of options: command line

    --entry=location

    where location can be address or symbol

    here is more information about the root region and the entry point. I do not use keil anymore and personally prefer gcc.