Programming in C++I have opted to avoid the Arduino IDE as my programming tool and instead use a development workflow based on the GNU Make toolchain. Fortunately there is a very well maintained project called, creatively enough "Arduino Makefile" that uses the existing Arduino libraries to make the transition to non-Arduino µController programming much smoother.
But why?The Arduino IDE is an incredible tool for learning µController programming but it has its limitations. Building code using a standardised method such as Make allows for the use of build verification testing tools and automated unit tests as well as keeping all of the build settings in version control.
Homebuilt MakefileMy first attempt involved trying to use a makefile I had used some years previous to build complex AVR-GCC based projects (Can be found here). This failed. The Arduino environment and the general layout of my system has changed sufficiently since I worked on this project that is simply refused to work. I was readying myself for the task of fixing the makefile when I discovered...
Arduino-MakefileThe Arduino Makefile project provides a set of command line tools and a makefile template to make developing Arduino based software using the GNU Make workflow more convenient.
MakefileA Makefile provides instructions to GNU Make on how to compile a given package of source code as well as any post-processing required to make it functional. In order to use the makefile to compile an Arduino based project we need to set up some environment variables.
Cross CompilingAs the architecture for which I am compiling is different to the host processor I will need to use a cross-compiler, in the case of the AVR µController I can use the GNU Compiler Collection AVR branch (avr-gcc and avr-g++).
TestingI am going to start with a simple program to test the build environment, this program will simply blink an LED.
ResultSuccess! The build succeeded and I have now got a hex file ready for uploading to the µController that will consume 5.9% of the available program memory. (Note that this screenshot is from testing with an Arduino Uno, I switch to a custom board for the next screenshot hence the change of target!)
The amount of space used here is quite unreasonable for the functionality of the program, this is due to the Arduino environment pulling in a lot of libraries to abstract basic functions of the microcontroller to a higher level. This is one of the main reasons for moving away from the Arduino environment as these layers of abstraction not only bloat the size of the program but slow the response time of some basic functions.