Page 1 of 1

STM32L0 - how to check available RAM memory

Posted: Tue Aug 30, 2022 10:13 am
by Beuzekom
Hi,

I am working on a project using the STM32L082. And during the code execution I would like to monitor the available RAM memory.
Does anybody know if there is a standard function available to monitor the available memory (RAM)?

Thans a lot

Re: STM32L0 - how to check available RAM memory

Posted: Tue Aug 30, 2022 10:26 am
by GonzoG

Re: STM32L0 - how to check available RAM memory

Posted: Wed Aug 31, 2022 7:41 pm
by dannyf
Unique ID, if the chip supports it.

Re: STM32L0 - how to check available RAM memory

Posted: Fri Sep 02, 2022 7:12 pm
by Bakisha
I once found same thing in SdFat library, called "FreeStack.h"

From that, simple sketch should work (at least at STM32F1/4):

Code: Select all

//  from SDfat library
extern "C" char* sbrk(int incr);
// free RAM (actually, free stack
inline uint32_t FreeBytes() {
  char top = 't';
  return &top - reinterpret_cast<char*>(sbrk(0));
}
void setup() {
    Serial.begin(115200);
  delay(2000);
}
void loop() {
  Serial.println(FreeBytes());
  delay(1000);
}
Maybe not 100% accurate, but it was enough for my case.