7 years, 7 months ago.

How to store code to flash instead of ram. Nucleo stm32f091rc

Compile fails because my 32k ram is full, while flash almost empty. How can i move non critical code sections to flash?

using mbed online compiler

1 Answer

7 years, 7 months ago.

Hello Dough,
The mbed family of microcontrollers use a modified Harvard Architecture. Program's code is stored in the Flash memory rather then in the RAM (see https://developer.mbed.org/handbook/Memory-Model). RAM is the working data space for storing all variables whilst the program is running. In C++, this is static variables, the heap, and the stack. So in case the RAM is full then you have to optimize the variables. For example, allocate memory for your variables dynamically from the heap and then delete (free RAM for other variables) once you do not need them anymore, if possible:

    MyType* myVar1 = new MyType;
    
   // your code using variable "myVar1"
    
    delete myVar1;  // if "myVar1" is not needed anymore
    // your code that does not use "myVar1"
    
    MyType* myVar2 = new MyType[100];
    
    // your code using variable "myVar2"
    
    delete [] myVar2;  // if "myVar2" is not needed anymore
    // your code that does not use "myVar2"
    


NOTE: Please pay attention also to the possible Collisions that could occur as indicated in the link provided above.

Thanks. How can I see linker output? I want to see which variables are using up the most.

posted by DOUG BELL 28 Aug 2016

Hello Dough,
Info about the online compiler is available at this link https://developer.mbed.org/handbook/mbed-Compiler. Memory usage info is displayed in the "Program Details - Build" tab. However, that doesn't include the runtime allocated variables (i.e. the heap and stack). You can also turn on verbose option by checking the "Verbose" check box in the "Compile Output" tab. If you need more features then you most likely have to use mbed CLI or export your program to another off-line toolchain.

posted by Zoltan Hudak 28 Aug 2016