Arduino-CMake-Toolchain icon indicating copy to clipboard operation
Arduino-CMake-Toolchain copied to clipboard

Add compiler definition to get board RAM size

Open eigendude opened this issue 2 years ago • 0 comments

Description

This PR adds the compiler definition ARDUINO_BOARD_RAM_SIZE, and sets it to the memory size of board being flashed. As a result, firmware code can refer to the expected total memory size when reporting memory usage percentages.

How has this been tested?

At the top of my memory utils header, I have:

#if !defined(ARDUINO_BOARD_RAM_SIZE)
#error "ARDUINO_BOARD_RAM_SIZE should have been defined by the build system"
#endif

When compiled with this patch, the build succeeds.

I also have the following function:

size_t GetTotalRAM()
{
  return ARDUINO_BOARD_RAM_SIZE;
}

I've tested on the following boards:

  • Arduino Uno - correctly returns 2048 bytes
  • Arduino Leonardo - correctly returns 2560 bytes

eigendude avatar Mar 04 '22 20:03 eigendude