5
\$\begingroup\$

I am trying to program a few Atmega328 (not Atmega328p) with an ICSP. These are TQFP.

What I am trying to do is to upload the program to a fresh chip without having to first load the bootloader. I use a command like this

avrdude -v -p m328 -c usbtiny -U flash:w:blink.cpp.hex:i

avrdude says it is uploaded successfully, but the program does not actually run.

However, when I first burn the bootloader, using the Arduino GUI, then use the command line and programmer to upload the program, the program does run. I am confused about why this is because my understanding was that the bootloader was not needed if the programming was done using the programmer.

Why is the bootloader needed?

Secondly, if the bootloader is needed, is there a way to make avrdude do everything to load the bootloader and the program in one line?

asked Oct 12, 2012 at 23:33
\$\endgroup\$
3
  • \$\begingroup\$ How did you create the blink.cpp.hex file? \$\endgroup\$ Commented Oct 13, 2012 at 9:04
  • \$\begingroup\$ I used the Arduino IDE. I got the path of the file from the Arduino IDE using the verbose output option in the settings. \$\endgroup\$ Commented Oct 13, 2012 at 10:14
  • \$\begingroup\$ I think you should check Dave Tweed's answer. electronics.stackexchange.com/a/43538/8627 \$\endgroup\$ Commented Oct 13, 2012 at 14:14

2 Answers 2

7
\$\begingroup\$

To answer the first question, the bootloader is needed because your program is built in such a way that it depends on the bootloader residing at the reset address of the processor, and then having the bootloader jump to your program. It's a function of how the linker script and the run-time code is set up for the Arduino environment.

I don't know the precise answer to your second question, but it certainly should be possible.

An alternative solution would be to use a different linker script so that your program actually resides at the reset address.

answered Oct 13, 2012 at 0:38
\$\endgroup\$
1
  • \$\begingroup\$ interesting. That makes sense. I'll look into the solution. Thanks for the answer. \$\endgroup\$ Commented Oct 14, 2012 at 2:09
4
\$\begingroup\$

I think Dave Tweed is right about the binary being compiled for use with the Arduino bootloader.

I use the following bash script to program ATtiny's and I often use single Arduino libraries. I cannot test your specific setup, but if you change the various variables it just might work.

#!/bin/bash
freq=9600000/8
baud=19200
src=main.cpp
avr=attiny13
dev=/dev/ttyUSB003
avr-gcc -g -DF_CPU=$freq -Wall -Os -mmcu=$avr -c -o tmp.o $src &&
avr-gcc -g -DF_CPU=$freq -Wall -Os -mmcu=$avr -o tmp.elf tmp.o &&
avr-objcopy -j .text -j .data -O ihex tmp.elf tmp.hex &&
avrdude -p $avr -cstk500v1 -P$dev -b$baud -v -U flash:w:tmp.hex
answered Oct 13, 2012 at 14:19
\$\endgroup\$

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.