0

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.

asked May 3, 2019 at 16:04
1
  • just add a nop Commented May 3, 2019 at 16:15

1 Answer 1

2

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
answered May 3, 2019 at 16:09
2
  • 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 :) Commented May 3, 2019 at 16:12

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.