1

Why do I have to burn the code twice to actually burn it on to the Arduino board? I have to execute this command twice - only then is the chip getting programmed.

I'm using this command to burn the program into the Arduino Uno board using a Rasp Pi 3, via SSH from Windows 10.

avr-gcc -mmcu=atmega328 filename.c | avr-objcopy -O ihex -j .text -j .data a.out a.hex | avrdude -C avrdude.conf -v -p atmega328p -c arduino -P /dev/ttyACM* -b 115200 -D -U flash:w:a.hex:i
Greenonline
  • 3,152
  • 7
  • 36
  • 48
user137442
  • 19
  • 1

1 Answers1

6

On a Unix shell, separating commands with the pipe character (|) means “run these commands in parallel, feeding the standard output of each one to the standard input of next one”.

In this context, it makes no sense to use pipes, as both avr-objcopy and avrdude read their data from files, not from stdin. Furthermore, running these in parallel means that avrdude will not have access to a.hex when it starts.

The solution is to run the commands sequentially instead of in parallel. Type and run one command at a time.

Alternatively, if you really want to have everything in a single line, separate the commands with a semicolon (;, meaning “run the next command when the previous one is done”) or, better yet, double ampersand (&& = “run the next command only if the previous one exits successfully”).

Edgar Bonet
  • 45,094
  • 4
  • 42
  • 81