William Chang

How to Boot from embedded SRAM in STM32F1?

Blog Post created by William Chang on May 13, 2018

Here are the knowledge I knew.

1. General Booting Sequence

  1. Read pins BOOT0 and BOOT1 to determine boot mode
  2. Fetch MSP from address 0x0000 0000
  3. Fectch PC from address 0x0000 00004 (reset handler)

2. Boot mode in STM32

It seems it is simple to boot from embedded SRAM, but really?

Let's take a look at manual. In my case RM0008.

en..It's not that simple.

If we want to boot from embedded SRAM, we also need to

  • relocate the vector table
  • imply special mechanism to be able to boot SRAM even CPU always fetched the reset vector on the ICode bus.

So, What does relocate the vector table means? Let's find out.

en...So we need to Set the Bit 29.

What I found in the system_stm32f1xx.c file,


we execute SCB ->VTOR = 0X2000 0000U; // It's also set the Bit 29!!!



What is the special mechanism?

Because the CPU always fetched the reset vector on the ICode bus. Since we are booting from SRAM, we need to fetch the MSP and Reset handler manually.

How to do that?

In keil,

we can write down the code and save as .ini file and put it into initialization file box.

then the CPU will run that code first.

It means we can't flash our application code into the chip normally. We heavily rely on debugger.


Final conclusion on Boot from embedded SRAM mechanism in STM32.

Booting Sequence

  1. Read the BOOT0 and BOOT1. both of them are 1.
  2. Fetch the MSP (manually)
  3. Fetch the Reset Handler (manually)
  4. define the Vector table is in SRAM region
  5. Relocate the vector table (define the VECT_TAB_SRAM in system_stm32f1xx.c)


It seems like booting from SRAM but actually it was running in SRAM under control of Debugger.

Question is still unresolve?

How to Boot from embedded SRAM in STM32F1?