Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C executable to hex

I am using CLion as IDE. After building the output is an executable file example. What I would like to achieve is make .hex file from it and upload it to my AVR via avrdude. I read and tried some possible solutions here

xxd -p example | tr -d '\n' > example.hex

and

avrdude -u -c usbasp-clone -p atmega8 -P /dev/bus/usb/001/006 -U flash:w:example.hex

but avrdude outputs

avrdude: input file example.hex auto detected as invalid format
avrdude: invalid input file format: -1
avrdude: read from file 'example.hex' failed

Any ideas here?

like image 461
etilge Avatar asked Apr 29 '26 12:04

etilge


1 Answers

The tool for extracting sections from an executable and converting them into another format is objcopy.

avr-objcopy -j .text -j .data -O ihex example example.hex

Or if your avrdude is built with ELF support then you can use the executable directly.

avrdude -c usbasp-clone -p atmega8 -U flash:w:example
like image 94
Ignacio Vazquez-Abrams Avatar answered May 01 '26 13:05

Ignacio Vazquez-Abrams



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!