Introduction  to STM32 Memory Model and Linker Scripts 
Introduction to the STM32 Memory Model
The memory of STM32 microcontrollers has two main areas :
1. Flash Memory :
  • Read-Only
  • Begins at address 0x08000000
  • Size depends on specific STM32 microcontroller
  • ​Program code is stored here.
  • ​Contains a vector table at address 0x08000004
2. SRAM Memory :
  • Read and Write
  • Begins at 0x20000000
  • Size depends on specific STM32 microcontroller
  • ​Variables and Stack are stored here
The Linker Script
It is the script given to the linker in order to specify the memory layout and
to initialize the various memory sections used by the firmware.

The linker script is responsible for making sure various portions of the firmware are in their proper place and also for associating meaningful labels with specific regions of memory used by the startup code.
The 4 features of a linker script :

  • Memory Layout        :  Available memory types
  • Section Definitions  :  Placing specific parts at specific locations
  • Options                     :  Commands e.g. ENTRY POINT
  • Symbols                   :  Variables to inject into program at link time
Memory
In order to allocate program memory, the linker needs to know the types of memory, their
 addresses and sizes.

We use the MEMORY definition to provide this information
Sections
• Code and data are organized into sections.

• Symbols of the same memory region are placed in the same section
The 3 relevant sections :

  • .text   :  Placed in the FLASH memory types
  • .data  :  Placed in the SRAM memory types
  • .bss    :  Placed in the SRAM memory types
In the video below we shall take a look at the linker script generated by CubeIDE to see if it contains some of the features we have discussed:

Conclusion

This is all there is for this 13 minutes introduction to the stm32 memory model and linker script.   

If you are really interested in learning how to write your own linker script and develop embedded firmware using build systems such as "make" then take a look at our new course :  Embedded Build Systems with GNU Tools and Make

You can find out more here:

EmbeddedExpertIO - All Rights Reserved