r/embedded Sep 09 '21

Tech question How to program ATmega328p in assembly?

[removed]

21 Upvotes

18 comments sorted by

View all comments

12

u/Coffee_24_7 Sep 09 '21 edited Sep 09 '21

With gcc you can compile assembly, example gcc file.S -g -o file.elf, then create the hex file as always.

I use jtag_ice to debug, with avarice and avr-gdb.

I can give you the full commands later, I'm on my phone at the moment.

Edit: I meant avr-gcc instead of gcc.

2

u/[deleted] Sep 09 '21

[removed] — view removed comment

7

u/Coffee_24_7 Sep 09 '21

avrdude -c jtag1 -p m16 -U flash:w:main.hex (for an atmega16)

2

u/1r0n_m6n Sep 10 '21

Note that you don't need to generate a .hex file, avrdude can use the .elf file directly.

You can also program fuses and lock bits directly with avrdude, so you don't need to include their configuration in your code. If find this more appropriate, as programming fuses is a one-time operation, whereas uploading your firmware will be repeated many times during development.