2

I'm trying to flash pure c-code to arduino Mega2560 board from linux using avr-gcc & avrdude. Compilation is done , now trying to flash using avr-dude, getting error as "avrdude: stk500_recv(): programmer is not responding avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00"

I used below command to produce hex file

avr-gcc -mmcu=atmega2560 -DF_CPU=16000000UL led.c -o led.elf

In file included from led.c:3:0: /usr/lib/avr/include/util/delay.h:95:3: warning: #warning "Compiler optimizations disabled; functions from won't work as designed" [-Wcpp] # warning "Compiler optimizations disabled; functions from won't work as designed"

And then

avr-objcopy -j .text -O ihex led.elf led.hex

finally for flashing

avrdude -F -V -c arduino -p ATMEGA2560 -P /dev/ttyACM3 -b 115200 -U flash:w:led.hex

FYI: port is correct & RX pin is blinking i.e connection is perfect between computer & board

3
  • One note: -DF_CPU=1000000UL is 1MHz. I'm pretty sure Arduino Mega2560 runs on 16MHz. Anyway, you can try to use PlatformIO CLI (I'm using it on Linux machine and it works fine with several different Arduinos)
    – KIIV
    Commented May 21, 2017 at 7:41
  • @KIIV , even @ 16Mhz , same probelm. any idea how to do without PlatformIO CLI?
    – sankar
    Commented May 21, 2017 at 8:24
  • Try prefixing your avrdude command with stty -F /dev/ttyACM3 hupcl &&
    – Majenko
    Commented May 21, 2017 at 11:49

1 Answer 1

2

In file included from led.c:3:0: /usr/lib/avr/include/util/delay.h:95:3: warning: #warning "Compiler optimizations disabled; functions from won't work as designed"

You should start by fixing this. Simply add -Os to the compiler command line. This means “optimize for size”, and is the standard optimization option used with Arduinos.

avr-objcopy -j .text -O ihex led.elf led.hex

If your copy of avrdude was compiled with libelf (like the one supplied with Ubuntu is), you don't need this: you can hand your elf file directly to avrdude.

avrdude -F -V -c arduino -p ATMEGA2560 -P /dev/ttyACM3 -b 115200 -U flash:w:led.hex

-F tells avrdude to not verify the device signature. -V tells it to not verify the upload. I wouldn't use any of these options unless I had a very good reason to do so. -c arduino is wrong: it selects the upload protocol used by optiboot (used, e.g., in the Uno). The Mega 2560 uses a different bootloader based on the “wiring” protocol. I would also add the -D option (disable auto erase) because I saw the Arduino IDE using it, and because without this option I get the error:

avrdude: erasing chip
avrdude: stk500v2_command(): command failed

In the end, the upload command ends up being something like:

avrdude -p atmega2560 -c wiring -P /dev/ttyACM3 -b 115200 -D -U led.elf
2
  • thanks ! it is working. your explanation is clear. I'm new to avr, can you please direct me where to learn all those? @Edgar Bonet
    – sankar
    Commented May 22, 2017 at 15:58
  • 1
    @sankar: I don't have a good reference handy for that. I learned it the hard way, by looking at how the Arduino IDE and Sudar Muthu's Makefile do it, and by reading the man page of avrdude. Commented May 22, 2017 at 16:02

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.