cancel
Showing results for 
Search instead for 
Did you mean: 

Booting STM32 from SRAM

Arlleex1
Associate II

Good day.

The reference manual RM0033 for the microcontroller (in the Boot configuration section) states that "When the device boots from SRAM, in the application initialization code, you have to

relocate the vector table in SRAM using the NVIC exception table and the offset register ".

Why?

After all, the RAM address will be mapped to the address 00000000 and the processor will regularly retrieve the addresses of the vectors.

Why should I explicitly write VTOR to RAM address?

5 REPLIES 5
Singh.Harjit
Senior II

They are trying to say that there must be a vector table in SRAM and it needs to be pointed to by the NVIC exception table and the offset register.

When you want to run code from SRAM, there are two ways to get code into the SRAM:

1) Copy it from FLASH to SRAM

2) Download and then write it to SRAM

For #1, since you are booting from FLASH, the FLASH has an exception table. This can be in its own region so that the linker knows where to place it. When you copy the "code" to SRAM, your copying routine may not pick up the separate region and so the area where the exception table would be, will be uninitialized memory. When you try to run from here, it won't work

For #2, if you built the image as if you are programming FLASH but are downloading it to SRAM, then, the exception vector will be there and you don't need to do anything. However, if you didn't build the image with the exception vector, then again, it won't run.

Arlleex1
Associate II

Thanks, I think I get it.

The documentation says that I must set the offset register, even if the correct vector table is already in RAM, and the inputs of the microcontroller boot selection are moved to the "load from RAM" position.

I will summarize.

If somehow the code has already been placed in RAM, and the vector table is placed at the beginning of the RAM, then you cannot write the offset register, but simply load the microcontroller from the RAM. For example, by resetting the MCU with the boot mode setting “boot from RAM�?.

I'm right?

Singh.Harjit
Senior II

Almost:

If somehow the code has already been placed in RAM, and the vector table is placed at the beginning of the RAM, then you cannot write the offset register, but simply load the microcontroller from the RAM. 

The portion "you cannot write the offset register" is not true. You can always write it. You just don't need to because when the processor was reset, the register was initialized to 0.

This doesn't apply to this situation but if you ever decide to relocate the exception vector table, make sure you get the alignment right. I was bringing up a system in a very high pressure situation and missed this and kept getting hard faults. The debug infrastructure was immature and it took some serious spelunking to figure it out. I guess, it made a big enough impression that I still remember it after six years.

Arlleex1
Associate II

I understood you.

My English is not as good as we would like, so perhaps the thought was conveyed not quite correctly =)

Thanks!

Singh.Harjit
Senior II

Sorry about that. All the best.