1

Note: This is a reference question (but feel free to write answers of your own!)


I want to use the AVR tools directly -- no arduino-builder or arduino-cli. I would also like compilation and uploading to be as fast as reasonably possible

glibg10b
  • 317
  • 1
  • 7

1 Answers1

2
  1. Create a new file called Makefile in your project directory. Populate it with the following contents:
TEMPDIR := $(shell mktemp -d)

all: avr-g++ -DF_CPU=<CLK> -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 -V -p&lt;PARTNO&gt; -carduino -P/dev/tty&lt;SERIAL_PORT&gt; -b&lt;BAUD&gt; -D -Uflash:w:${TEMPDIR}/a.hex

rm ${TEMPDIR}/a.elf ${TEMPDIR}/a.hex
rm -d ${TEMPDIR}

  1. In the Arduino IDE, press Ctrl+, and enable verbose output during compilation and uploading.
  2. Start uploading with Ctrl+U. Replace the groups of angled brackets in Makefile (e.g. <CLK>) with the values in the Arduino IDE's build output.
  3. Run make.

-lm links in the AVR math library. *.cpp refers to your c++ source files. -V prevents avrdude from reading back the flash contents and verifying it, which saves time, but you may want to disable it while diagnosing problems.

glibg10b
  • 317
  • 1
  • 7