Here are the knowledge I knew.
1. General Booting Sequence
- Read pins BOOT0 and BOOT1 to determine boot mode
- Fetch MSP from address 0x0000 0000
- 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,
If we execute SCB ->VTOR = SRAM_BASE | VECT_TAB_OFFSET;
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?
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.
- Read the BOOT0 and BOOT1. both of them are 1.
- Fetch the MSP (manually)
- Fetch the Reset Handler (manually)
- define the Vector table is in SRAM region
- 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?