I am trying to compile and upload code to an Arduino Uno from the command-line, however I seem to be experiencing an odd issue.

When I compile this code:

#include <avr/interrupt.h>
#include <stdbool.h>

ISR(TIMER0_OVF_vect) {

int main() {
  while (true);

With these commands:

$ avr-gcc -mmcu=atmega328p -DF_CPU=16000000 -std=c17 -O3 -Wall -Wextra -c boot_loop.c -o boot_loop.o
$ avr-gcc boot_loop.o boot_loop.elf
$ avr-objcopy -j .text -j .data -O ihex boot_loop.elf boot_loop.hex
$ avrdude -p atmega328p -c arduino -P /dev/ttyUSB0 -U flash:w:boot_loop.hex

My Arduino ends up in a boot loop, flashing the LED 3 times every second or so (similarly to when you press the reset button or the device powers up).

I've tried it without an empty ISR and also with different interrupt vectors (e.g. TIMER0_COMPA_vect) but to no avail. Completely removing the ISR definition stops the boot loop.

  • just add a nop
    – sa_leinad
    Commented May 3, 2019 at 16:15

1 Answer 1


Your problem is not with your code. It's with how you're linking your elf file.

You haven't specified the chip to link for.

$ avr-gcc -mmcu=atmega328p boot_loop.o -o boot_loop.elf
  • That's the ticket! Can't believe I missed that, thanks! Commented May 3, 2019 at 16:11
  • 1
    You know why I spotted it so readily? Because I did the exact same thing once :)
    – Majenko
    Commented May 3, 2019 at 16:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.