Pages: [1]   Go Down
Author Topic: How to write code to load firmware without using Arduino dev tool?  (Read 1134 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Sr. Member
****
Karma: 1
Posts: 486
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

you use the arduino IDE.
Logged

http://dduino.blogspot.com all my Arduino/electronic projects!!!

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

Southern California
Offline Offline
God Member
*****
Karma: 5
Posts: 539
I like blinky lights
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
.\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)
Logged

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

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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++.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
.\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!
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: February 28, 2012, 08:11:17 pm by rememberfun » Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: February 28, 2012, 09:34:56 pm by rememberfun » Logged

Southern California
Offline Offline
God Member
*****
Karma: 5
Posts: 539
I like blinky lights
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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/
Logged

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

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Southern California
Offline Offline
God Member
*****
Karma: 5
Posts: 539
I like blinky lights
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

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

Pages: [1]   Go Up
Jump to: