Skip to content

Instantly share code, notes, and snippets.

@mulderp
Last active September 8, 2020 16:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mulderp/36ca39a9911d54de66ec to your computer and use it in GitHub Desktop.
Save mulderp/36ca39a9911d54de66ec to your computer and use it in GitHub Desktop.
# add headers
$ echo ‘#include “Arduino.h”’ > blink.cpp
# add sketch
$ cat blink.ino >> blink.cpp
# add int main()
$ cat /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/main.cpp >> blink.cpp
# build binary
$ avr-g++ -x c++ -MMD -c -mmcu=atmega328p -Wall -DF_CPU=16000000L -DARDUINO=160 -DARDUINO_ARCH_AVR -D__PROG_TYPES_COMPAT__ -I/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/ -I/Applications/Arduino.app/Contents/Java//hardware/arduino/avr/variants/standard -Wall -Os blink.cpp
# add arduino core libraries
$ avr-ar rcs libcore.a hooks.o wiring.o wiring_digital.o
# create elf
$ avr-gcc -mmcu=atmega328p -Wl,–gc-sections -Os -o blink.elf blink.o libcore.a -lc -lm
# create hex
$ avr-objcopy -O ihex -R .eeprom blink.elf blink.hex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment