CubeCell AB-01 read free memory

Hi,
in order to detect a memory lead, i would like to read the remaining free memory from inside my program. I tried

https://github.com/McNeight/MemoryFree

But it compiles, but won’t link.
Arduino: 1.8.15 (Windows Store 1.8.49.0) (Windows 10), Board: “CubeCell-Board(HTCC-AB01), REGION_EU868, CLASS_A, CUSTOM, OTAA, ON, UNCONFIRMED, OFF, OFF, DEACTIVE, None”

WARNING: library LoRaWanMinimal claims to run on ASR650x-Arduino architecture(s) and may be incompatible with your current board which runs on CubeCell architecture(s).

libraries\MemoryFree-master\MemoryFree.cpp.o: In function `freeListSize()’:

C:\Users\jakob\Documents\Arduino\libraries\MemoryFree-master/MemoryFree.cpp:37: undefined reference to `__flp’

libraries\MemoryFree-master\MemoryFree.cpp.o: In function `freeMemory’:

C:\Users\jakob\Documents\Arduino\libraries\MemoryFree-master/MemoryFree.cpp:52: undefined reference to `__brkval’

C:\Users\jakob\Documents\Arduino\libraries\MemoryFree-master/MemoryFree.cpp:52: undefined reference to `__heap_start’

collect2.exe: error: ld returned 1 exit status

exit status 1

Error compiling for board CubeCell-Board(HTCC-AB01).

Is there an alternativ to do what I want von AB-01. Does it have its own system call?

Best Regards
Jakob

Hi Jakob,
I also wanted to know more about the memory consumption of my script and gathered these methods from several sources online.

// this function will return the number of bytes of the biggest chunk of heap memory currently free in RAM
int biggestAvailableMemoryChunk() {
  int msize = 4096; // CubeCell Module Plus with ASR6502 has 4096 Bytes Heap
  byte *buf;

  while (((buf = (byte *) malloc(--msize)) == NULL) && msize >= 0)
    ;

  free(buf);

  return msize;
}

uint8_t * heapptr;
char * stackptr;

void setup_check_mem() {
  char topofStack;
  stackptr =  &topofStack;           // save value of stack pointer

  uint8_t *tempheap = (uint8_t *)malloc(4);          // use temporarily
  heapptr = tempheap;                     // save value of heap pointer
  free(tempheap);      // free up the memory again
}

void check_mem() {
  char topofStack;
  char* topOfstackptr =  &topofStack;           // save value of stack pointer

  Serial.printf("Heap Start:  %p, Biggest chunk: %d\n", heapptr, biggestAvailableMemoryChunk());
  Serial.printf("Stack Start: %p, Stack: %p, Size: %d\n", stackptr, topOfstackptr, (int)stackptr - (int)topOfstackptr);
  Serial.println();
}

Just call setup_check_mem() at the beginning of your script (i.e. at the top of setup()). Afterwards use check_mem() to print info about the current memory consumption to the Serial port. I didn’t figure out how to get the total amount of free heap memory without brute force allocating everything possible… But the biggest chunk is a good indication. Keep in mind that the Heap gets fragmentet quickly if your biggest chunk does not change anymore.

Best Regards
Tom