dstroy0 / InputHandler

Arduino input handler
https://dstroy0.github.io/InputHandler/
GNU General Public License v3.0
1 stars 0 forks source link

get free heap for debugging #44

Closed dstroy0 closed 2 years ago

dstroy0 commented 2 years ago

implement some sort of function or macro to get free heap multiplatform for debugging and leak detection during iterative testing

dstroy0 commented 2 years ago
#if !defined(__FREERAM_H__)
#define __FREERAM_H__

#include <Arduino.h>

int freeRam () 
{
  extern int __heap_start, *__brkval;
  int v;
  return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}

#endif
  .data   : AT (ADDR (.text) + SIZEOF (.text))
  {
     PROVIDE (__data_start = .) ;
    /* --gc-sections will delete empty .data. This leads to wrong start
       addresses for subsequent sections because -Tdata= from the command
       line will have no effect, see PR13697.  Thus, keep .data  */
    KEEP (*(.data))
    *(.data*)
    *(.rodata)  /* We need to include .rodata here if gcc is used */
    *(.rodata*) /* with -fdata-sections.  */
    *(.gnu.linkonce.d*)
    . = ALIGN(2);
     _edata = . ;
     PROVIDE (__data_end = .) ;
  }  > data
  .bss   : AT (ADDR (.bss))
  {
     PROVIDE (__bss_start = .) ;
    *(.bss)
    *(.bss*)
    *(COMMON)
     PROVIDE (__bss_end = .) ;
  }  > data
   __data_load_start = LOADADDR(.data);
   __data_load_end = __data_load_start + SIZEOF(.data);
  /* Global data not cleared after reset.  */
  .noinit  :
  {
     PROVIDE (__noinit_start = .) ;
    *(.noinit*)
     PROVIDE (__noinit_end = .) ;
     _end = . ;
     PROVIDE (__heap_start = .) ;
  }  > data

__heap_start

I am fairly certain that the macros RAMSTART and RAMEND play a role somewhere in here.

I'm just trying to figure out how to make this portable.

dstroy0 commented 2 years ago

freeRam() is confirmed working on avr and ESP platforms.

dstroy0 commented 2 years ago

it's working on teensy 4.x

dstroy0 commented 2 years ago

due and sam should be working

dstroy0 commented 2 years ago

working on rp2040

dstroy0 commented 2 years ago

yes samd working, I think that's everyone, closing this now