cancel
Showing results for 
Search instead for 
Did you mean: 

Internal RAM: Potential Issues when using a large percentage of RAM

KMew
Senior III

Hello,

I am using the STM32F756ZGT6 for an upcoming project. I am using a 480x272 resolution display (RGB565) with a single layer. I also have additional features that will be on this board that use more RAM (2 tasks, multiple variables, etc.) that add up in the RAM. In total, I have 310 kBytes of RAM usage, according to the Memory Regions tab. The MCU has 320 kBytes of internal RAM and I have tested it with the display and my code works as intended.

My question is, long term, will I experience problems when the RAM usage is that high? My RAM usage percentage is about 96%, which is quite high. I cannot think of any issues (aside from limitations on software additions later), but I wanted to ask in case I'm not thinking of something.

This discussion is locked. Please start a new topic to ask your question.
1 ACCEPTED SOLUTION

Accepted Solutions
Peter BENSCH
ST Employee

You should not compare an STM32 with a CPU that has to process a highly complex operating system with a constantly changing RAM load due to constantly changing programs.

The RAM load results mainly from the allocation of variables, arrays, stacks, etc. specified by your programme. Only the stack is an unknown, which you can control by taking appropriate measures and defining it large enough; everything else is fixed and non-expanding, so to speak. When the stack "overflows", it overlaps RAM defined for variables and arrays, which usually leads to an immediate crash of the system.

If you have defined the stack large enough, your programme can run for decades with this RAM load.

Does this answer your question?

Did you enable the optimizer of your compiler and switch it to "optimization for size"?

Regards

/Peter

In order 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.

View solution in original post

3 REPLIES 3
Peter BENSCH
ST Employee

You should not compare an STM32 with a CPU that has to process a highly complex operating system with a constantly changing RAM load due to constantly changing programs.

The RAM load results mainly from the allocation of variables, arrays, stacks, etc. specified by your programme. Only the stack is an unknown, which you can control by taking appropriate measures and defining it large enough; everything else is fixed and non-expanding, so to speak. When the stack "overflows", it overlaps RAM defined for variables and arrays, which usually leads to an immediate crash of the system.

If you have defined the stack large enough, your programme can run for decades with this RAM load.

Does this answer your question?

Did you enable the optimizer of your compiler and switch it to "optimization for size"?

Regards

/Peter

In order 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.

Hello Peter,

Thank you for the answer! Yes, this answers my question.

So as long as my stack size is well defined, this "high load" will not be a problem?

Also, I do not have the compiler optimizer switched to "optimization for size." Where do I do this?

Correct.

Since you have not mentioned which tools you are working with, no recommendation can be given so far. If you have developed the graphical interface with TouchGFX and use STM32CubeIDE as compiler, it is quite easy:

  • Start STM32CubeIDE
  • open the project created by TouchGFX in the folder STM32CubeIDE: in STM32CubeIDE with File > Import > General, Existing Projects into Workspace, entering the path to your project and finish with Finish if only one project is listed
  • STM32CubeIDE > Project Explorer (left window) right click on the project and select Properties.
  • C/C++ Build > Settings > MCU GCC Compiler > Optimization --> set Optimization level (still on None?) to "Optimize for size"
  • Apply and Close
  • Project >Build Project (or the hammer icon at the top left)
  • Run > Run

Does it work and reduce the required RAM?

In order 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.