a9183756-gh / Arduino-CMake-Toolchain

CMake toolchain for all Arduino compatible boards
MIT License
137 stars 40 forks source link

Add compiler definition to get board RAM size #55

Open eigendude opened 2 years ago

eigendude commented 2 years ago

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: