cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 Nucleo memory mapping

karthik2
Associate II
Posted on May 04, 2015 at 22:59

Hi, I'm trying to understand the memory mapping used on the STM32 Nucleo series of boards. Specifically, I'm trying to understand how I can use SRAM vs Flash for program execution. 

  • In short, i am trying to get my program to use either all Flash ( for program execution as well as any memory i need during execution ) or all SRAM. 
  • By default, the program seems to load into Flash ( since its still there when i do a power cycle ). Is it possible to start a program from SRAM? Its ok if its volatile, i can program it when i start up. 
  • The reference manual says that there is a 64K region of memory that can be used as Main Flash Memory/ System Memory or SRAM depending on BOOT configuration. So if i alter the appropriate BOOT pins, can i get the program to execute out of SRAM instead of Flash? 
Any help with clearing this up would be appreciated. I just dont want to brick my board! 

Thanks! 

#sram #stm32 #flash
3 REPLIES 3
Posted on May 05, 2015 at 01:30

There are several STM32 variants, you need to be specific

The BOOTx pins shadow a specific memory at ZERO, as well as there normal addresses, ie 0x08000000 for FLASH, and 0x20000000 for SRAM

If you mess up your code you can still boot into the ROM.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
karthik2
Associate II
Posted on May 05, 2015 at 02:03

Hi Clive1,

        I'm planning to use several STM32 nucleos boards for this work, but for now, I am specifically working with the STM32F302R8 board.  

       

cheers! 

RomainR.
ST Employee
Posted on May 05, 2015 at 15:15

To place the code in SRAM, it is not just necessary to change the state of the BOOT pin.

I suggest you do the following:

Well, consider that you work with the Keil environment.

Step 1. Test your application in Flash execution before anything else.

Then erase the Flash memory (STLink Utilities)

Step 2. From the sizes of your firmware (see .map file generated at the link), hold the different sections of the Code, RO Data, RW Data, and ZI Data

Step 3. Study the datasheet of your STM32, SRAM start address 0x20000000 up 0x2000FFFF (ie: 64Kb SRAM for STM32F302R8), the sum of the linker sections of your program 

should be less than the total size of SRAM for your device.

Step 4. In Keil options, into Target tab, change the Start address and size to IROM1 and IRAM1:

Example: Suppose your application gives: Code = 8072, 252 = R0-Data, RW Data, ZI = 88 and = 1344-Data

In code + RO = 8072 + 252 = 8324 bytes = 0x2084 (we keep 0x20FF)

RW in memory = 88 + 1344 = 1432 bytes = 0x598

IROM1and IRAM1 sections are changed in the target options Keil:

IROM1 Start = 0x20000000 Size = 0x20FF code for RO + datas

IRAM1 Start = 0x200020100 Size = 0xFFFF for RW datas

Step5.

Also in the Keil Linker Options tab ensure that Use Memory Layout from Target Dialog is

checked

.

Step6. In

STLinkV2 options, uncheck Flash Download: Programm and Verify. And thhen

Remove Flash Algorithm.

Step8. Save your project and Clean and rebuild it.

Step7.

Put the Pin Boot0 = High = 3V and run Keil in Debug mode.

Your code is now fully executed from SRAM.

You can check with the STLink utilities that SRAM is written.

If you disconnect STLink, target is no powered. 

You loose code in SRAM.

If your application uses interrupt you need to relocate interrup vector in SRAM too. 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.