- Create a new file called
Makefilein your project directory. Populate it with the following contents:
TEMPDIR := $(shell mktemp -d)
all:
avr-g++ -DF_CPU=<CLK> -D__AVR_<PART>__ -DARDUINO=<ID> -DARDUINO_AVR_<DEVICE> -DARDUINO_ARCH_AVR -mmcu=<PARTNO> -fno-threadsafe-statics -O3 -flto -std=c++23 -isystem/usr/avr/include -lm -fuse-linker-plugin -Wl,--gc-sections *.cpp -o ${TEMPDIR}/a.elf
avr-objcopy -O ihex -R .eeprom ${TEMPDIR}/a.elf ${TEMPDIR}/a.hex
avrdude -F -V -p<PARTNO> -carduino -P/dev/tty<SERIAL_PORT> -b<BAUD> -D -Uflash:w:${TEMPDIR}/a.hex
rm ${TEMPDIR}/a.elf ${TEMPDIR}/a.hex
rm -d ${TEMPDIR}
- In the Arduino IDE, press Ctrl+, and enable verbose output during compilation and uploading
- Start uploading with Ctrl+U. Fill in the values in Makefile with the values in the Arduino IDE's build output
- Run
make
-lm links in the AVR math library. *.cpp refers to your c++ source files. -F skips avrdude's signature check and -V prevents it from reading back the flash contents and verifying it -- both of these options save time by bypassing important safety features, but you may want to disable them while diagnosing problems.