Go Down

Topic: How to write code to load firmware without using Arduino dev tool? (Read 1 time) previous topic - next topic

rememberfun

Arduino board is connected with Host PC via UART port. The default bootloader is running on the board.

Without using Arduino dev tool, how to write a C program to load new firmware onto the Arduino board via UART?

What protocol will be used to download firmware?

Any ideas are welcome!

Thanks

sirbow2

by firmware you you mean like the bootloader or actual user code?

you use the arduino IDE.
http://dduino.blogspot.com all my Arduino/electronic projects!!!

{NEW} Getting Started, Learning, Reference + FAQ PDF!!:
[url]http://ar

magagna

Does this help?

http://arduino.cc/en/Hacking/BuildProcess

If you want to see the avr-gcc and avrdude commands that run to get code to a board, hold down shift while clicking "upload" and you'll see something like this:

Code: [Select]
.\arduino\hardware\tools\avr\bin\avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=22 -I.\arduino\hardware\arduino\cores\arduino C:\DOCUME~1\chris\LOCALS~1\Temp\build7727412688693041721.tmp\sketch_feb28a.cpp -oC:\DOCUME~1\chris\LOCALS~1\Temp\build7727412688693041721.tmp\sketch_feb28a.cpp.o

.\arduino\hardware\tools\avr\bin\avr-gcc -c -g -Os -w -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=22 -I.\arduino\hardware\arduino\cores\arduino .\arduino\hardware\arduino\cores\arduino\pins_arduino.c -oC:\DOCUME~1\chris\LOCALS~1\Temp\build7727412688693041721.tmp\pins_arduino.c.o
.
.
.
\arduino\hardware\tools\avr\bin\avr-ar rcs C:\DOCUME~1\chris\LOCALS~1\Temp\build7727412688693041721.tmp\core.a C:\DOCUME~1\chris\LOCALS~1\Temp\build7727412688693041721.tmp\pins_arduino.c.o
.
.
.
.\arduino\hardware\tools\avr\bin\avr-gcc -Os -Wl,--gc-sections -mmcu=atmega328p -o C:\DOCUME~1\chris\LOCALS~1\Temp\build7727412688693041721.tmp\sketch_feb28a.cpp.elf C:\DOCUME~1\chris\LOCALS~1\Temp\build7727412688693041721.tmp\sketch_feb28a.cpp.o C:\DOCUME~1\chris\LOCALS~1\Temp\build7727412688693041721.tmp\core.a -LC:\DOCUME~1\chris\LOCALS~1\Temp\build7727412688693041721.tmp -lm

.\arduino\hardware\tools\avr\bin\avr-objcopy -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 C:\DOCUME~1\chris\LOCALS~1\Temp\build7727412688693041721.tmp\sketch_feb28a.cpp.elf C:\DOCUME~1\chris\LOCALS~1\Temp\build7727412688693041721.tmp\sketch_feb28a.cpp.eep

.\arduino\hardware\tools\avr\bin\avr-objcopy -O ihex -R .eeprom C:\DOCUME~1\chris\LOCALS~1\Temp\build7727412688693041721.tmp\sketch_feb28a.cpp.elf C:\DOCUME~1\chris\LOCALS~1\Temp\build7727412688693041721.tmp\sketch_feb28a.cpp.hex

Binary sketch size: 450 bytes (of a 32256 byte maximum)
http://en.wiktionary.org/wiki/magagna <-- My last name.  Pretty apt.

Nick Gammon


Arduino board is connected with Host PC via UART port. The default bootloader is running on the board.
Without using Arduino dev tool, how to write a C program to load new firmware onto the Arduino board via UART?


Use AVRdude with the appropriate arguments, sending it the appropriate file which you compiled and linked with avr-g++.
http://www.gammon.com.au/electronics

rememberfun


by firmware you you mean like the bootloader or actual user code?

you use the arduino IDE.


Thanks sirbow2,
My purpose is to load actual user code or application firmware instead of bootloader via serial.

Arduino IDE can do it but what I want to do is to write my own program with C language to do it.

rememberfun


Does this help?

http://arduino.cc/en/Hacking/BuildProcess

If you want to see the avr-gcc and avrdude commands that run to get code to a board, hold down shift while clicking "upload" and you'll see something like this:

Code: [Select]
.\arduino\hardware\tools\avr\bin\avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=22 -I.\arduino\hardware\arduino\cores\arduino C:\DOCUME~1\chris\LOCALS~1\Temp\build7727412688693041721.tmp\sketch_feb28a.cpp -oC:\DOCUME~1\chris\LOCALS~1\Temp\build7727412688693041721.tmp\sketch_feb28a.cpp.o

.\arduino\hardware\tools\avr\bin\avr-gcc -c -g -Os -w -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=22 -I.\arduino\hardware\arduino\cores\arduino .\arduino\hardware\arduino\cores\arduino\pins_arduino.c -oC:\DOCUME~1\chris\LOCALS~1\Temp\build7727412688693041721.tmp\pins_arduino.c.o
.
.
.
\arduino\hardware\tools\avr\bin\avr-ar rcs C:\DOCUME~1\chris\LOCALS~1\Temp\build7727412688693041721.tmp\core.a C:\DOCUME~1\chris\LOCALS~1\Temp\build7727412688693041721.tmp\pins_arduino.c.o
.
.
.
.\arduino\hardware\tools\avr\bin\avr-gcc -Os -Wl,--gc-sections -mmcu=atmega328p -o C:\DOCUME~1\chris\LOCALS~1\Temp\build7727412688693041721.tmp\sketch_feb28a.cpp.elf C:\DOCUME~1\chris\LOCALS~1\Temp\build7727412688693041721.tmp\sketch_feb28a.cpp.o C:\DOCUME~1\chris\LOCALS~1\Temp\build7727412688693041721.tmp\core.a -LC:\DOCUME~1\chris\LOCALS~1\Temp\build7727412688693041721.tmp -lm

.\arduino\hardware\tools\avr\bin\avr-objcopy -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 C:\DOCUME~1\chris\LOCALS~1\Temp\build7727412688693041721.tmp\sketch_feb28a.cpp.elf C:\DOCUME~1\chris\LOCALS~1\Temp\build7727412688693041721.tmp\sketch_feb28a.cpp.eep

.\arduino\hardware\tools\avr\bin\avr-objcopy -O ihex -R .eeprom C:\DOCUME~1\chris\LOCALS~1\Temp\build7727412688693041721.tmp\sketch_feb28a.cpp.elf C:\DOCUME~1\chris\LOCALS~1\Temp\build7727412688693041721.tmp\sketch_feb28a.cpp.hex

Binary sketch size: 450 bytes (of a 32256 byte maximum)



Thanks magagna, it is very helpful!

rememberfun

#6
Feb 29, 2012, 02:07 am Last Edit: Feb 29, 2012, 02:11 am by rememberfun Reason: 1
Thanks Nick too.

My understanding,
1) avrdude is used to upload user code/application firmware to Arduino board.
2) stk500 protocol is used by default and current arduino bootloader support this protocol.
3) avrdude is open source and can be referenced to write my own program.
4) AvrUsb500 is another open source implementation of stk500 protocol.

I have another concern,
which one is more mature if comparing AvrUsb500 and avrdude? I'd like to choose a good start-point to learn it.

Thanks

Nick Gammon

I haven't used AvrUsb500 so I can't comment on that.

Remember this: the entire Optiboot bootloader takes under 512 bytes of program space. It can't be doing anything *too* complex.

You could devise your own boot loading protocol if you want to. Examples could be found in existing bootloaders, plus the datasheet for the processor suggests how to do it. You could write one that loaded code via SPI or I2C. You could build in other things. Basically you just need to somehow read in the hex file which is output from the compile process, and - in an agreed format - send that to the bootloader code, which burns it into program memory.

You haven't said *why* you want to do this, but anything is possible.
http://www.gammon.com.au/electronics

rememberfun

#8
Feb 29, 2012, 03:33 am Last Edit: Feb 29, 2012, 03:34 am by rememberfun Reason: 1

I haven't used AvrUsb500 so I can't comment on that.

Remember this: the entire Optiboot bootloader takes under 512 bytes of program space. It can't be doing anything *too* complex.

You could devise your own boot loading protocol if you want to. Examples could be found in existing bootloaders, plus the datasheet for the processor suggests how to do it. You could write one that loaded code via SPI or I2C. You could build in other things. Basically you just need to somehow read in the hex file which is output from the compile process, and - in an agreed format - send that to the bootloader code, which burns it into program memory.

You haven't said *why* you want to do this, but anything is possible.


Please let me give more background of my idea,

The purpose is to download an updated firmware by host PC in the future and upload to Arduino board via Serial port.
That can make arduino having live upgrade capability.

I don't know how much effort to write customized protocol. However, that means you have to change bootloader code and also write your own program in host PC to support this customized protocol.

I checked arduino-1.0\hardware\arduino\bootloaders\atmega\ATmegaBOOT_168.c. Is it using a customized protocol?

Could you give some hints?

Thanks

magagna

So you are looking to send someone the hex file (compiled Arduino program code) and they will upload it to their board from a computer, but you don't want the user to have to run the Arduino IDE?

A couple people have already done this. Basically they've written wrappers around AVRDude so it takes care of the upload and protocol, so you don't have to re-invent the wheel. Maybe these will help you out:

http://arduino.cc/playground/Code/ArduinoUpload

and

http://smileymicros.com/blog/2010/10/11/ardup-an-arduino-hex-file-uploader/
http://en.wiktionary.org/wiki/magagna <-- My last name.  Pretty apt.

rememberfun

Forgot it, I will look more detail into optboot code. It seems a good start point for me. Thanks Nick.

rememberfun


So you are looking to send someone the hex file (compiled Arduino program code) and they will upload it to their board from a computer, but you don't want the user to have to run the Arduino IDE?

A couple people have already done this. Basically they've written wrappers around AVRDude so it takes care of the upload and protocol, so you don't have to re-invent the wheel. Maybe these will help you out:

http://arduino.cc/playground/Code/ArduinoUpload

and

http://smileymicros.com/blog/2010/10/11/ardup-an-arduino-hex-file-uploader/


That makes my idea work on PC.
How to do it on iOS/Android? That will be my final aim. Thanks magagna!

magagna

Ive never heard of an IOS or Android version of AVRDude, but the source code is available so maybe you can use that as the basis for those platforms.

Good luck!
http://en.wiktionary.org/wiki/magagna <-- My last name.  Pretty apt.

Go Up