avrdude and the chipKIT Platform

The bootloader on the chipKIT is based on the same bootloader that I developed for the mega2560. It uses stk500v2 protocol.

Avrdude can be used from the command line with the chipKIT boards or any other board that has the bootloader installed The command would be something like this >avrude -c stk500v2 -p pic32 -P /dev/tty.usbmodem1234 -b 115200 -U flash:w:filename.hex Or, under Windows(If you’ve copied avrdude.exe and avrdude.conf into the MPLABX bin folder): “C:\Program Files\Microchip\MPLABX\mplab_ide\bin\avrdude.exe” -C”C:\Program Files\Microchip\MPLABX\mplab_ide\bin\avrdude.conf” -v -p32MX795F512L -cstk500v2 -P COM40 -b 115200 -U flash:w:pic32_template_1.production.hex

Getting an hex file for chipKIT

When using mpide, default is to remove all the intermediate files between the mpide source of your project (.mpe file) and code uploaded on the chipKIT. But all the files generated by mpide (including the hex file) can be kept by changing mpide preference file. From Linux:
  1. close any running mpide
  2. edit ~/.mpide/preferences.txt
  3. look for preproc.save_build_files attribute
  4. Set it to true: preproc.save_build_files=true
  5. save the preference file
Now, all temporary files from build command will be kept. To locate the right directory with your build, from mpide, press the “shift” key while starting the build/verify command. You will have details about the build process (commands, outputs, path …) in mpide output console. Example:
/opt/mpide-0023-linux32-20111221/hardware/pic32/compiler/pic32-tools/bin/pic32-g++  -O2  -c  -mno-smart-io  -w  -fno-exceptions  -ffunction-sections  -fdata-sections  -G1024  -g  -mdebugger  -Wcast-align  -mprocessor=32MX320F128H  -DF_CPU=80000000L  -DARDUINO=23  -D_BOARD_UNO_  -Danything_you_want  -Danything=1   -I/home/fred/Arduino/Serial2   -I/opt/mpide-0023-linux32-20111221/hardware/pic32/cores/pic32   -I/opt/mpide-0023-linux32-20111221/hardware/pic32/variants/Uno32    /tmp/build6773645236763377018.tmp/Serial2.cpp  -o  /tmp/build6773645236763377018.tmp/Serial2.cpp.o

...

/opt/mpide-0023-linux32-20111221/hardware/pic32/compiler/pic32-tools/bin/pic32-ar  rcs  /tmp/build6773645236763377018.tmp/core.a  /tmp/build6773645236763377018.tmp/main.cpp.o
/opt/mpide-0023-linux32-20111221/hardware/pic32/compiler/pic32-tools/bin/pic32-g++  -Os  -Wl,--gc-sections  -mdebugger  -mprocessor=32MX320F128H  -o  /tmp/build6773645236763377018.tmp/Serial2.cpp.elf  /tmp/build6773645236763377018.tmp/Serial2.cpp.o    /tmp/build6773645236763377018.tmp/core.a  -L/tmp/build6773645236763377018.tmp  -lm  -T  /opt/mpide-0023-linux32-20111221/hardware/pic32/cores/pic32/chipKIT-UNO32-application-32MX320F128L.ld
/opt/mpide-0023-linux32-20111221/hardware/pic32/compiler/pic32-tools/bin/pic32-objcopy  -O  ihex  -j  .eeprom  --set-section-flags=.eeprom=alloc,load  --no-change-warnings  --change-section-lma  .eeprom=0  /tmp/build6773645236763377018.tmp/Serial2.cpp.elf  /tmp/build6773645236763377018.tmp/Serial2.cpp.eep
/opt/mpide-0023-linux32-20111221/hardware/pic32/compiler/pic32-tools/bin/pic32-bin2hex  -a  /tmp/build6773645236763377018.tmp/Serial2.cpp.elf
Binary sketch size: 10748 bytes (of a 126976 byte maximum)
  • temporary directory is /tmp/build6773645236763377018.tmp/
  • Hex file will be named /tmp/build6773645236763377018.tmp/Serial2.cpp.hex
WARNING: the temporary directory will be removed when mpide will be closed. You have to backup the hex file before closing mpide. To go back to initial configuration (files removed after each build), just set the preproc.save_build_files attribute to false
preproc.save_build_files=false

Using AVRDUDE from Linux console

copy avrdude.conf file from mpide to ~/.avrduderc, example:
cp /opt/mpide-0023-linux32-20111221/hardware/tools/avrdude.conf ~/.avrdude.rc
Use ever avrdude from mpide or from your own Linux distro… Here are details about avrdude from Ubuntu Precise Penguin:
dpkg-query -l avrdude
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                             Version                          Description
+++-================================-================================-================================================================================
ii  avrdude                          5.11.1-1                         software for programming Atmel AVR microcontrollers
Check if the avrdude configuration file from mpide is used, and which PIC32 devices are available:
fred@kat:~/MPLABXProjects/Blink$ avrdude -p ?

Valid parts are:
  pic32-440 = 32MX440F512H    [/home/fred/.avrduderc:16438]
  pic32-460 = 32MX460F512L    [/home/fred/.avrduderc:16251]
  pic32-360 = 32MX320F128H    [/home/fred/.avrduderc:16054]
  pic32-360 = 32MX320F064H    [/home/fred/.avrduderc:15863]
  pic32-360 = 32MX360F512L    [/home/fred/.avrduderc:15672]
  pic32 = 32MX795F512L    [/home/fred/.avrduderc:15483]

...
We can see that pic32-360 has to be used for Uno32 (32MX320F128H) Example, with:
  • avrdude from Ubuntu distro (Precise Penguin – avrdude 5.11.1)
  • Uno32 located on /dev/ttyUSB0
  • hex file build by using mpide
fred@kat:~/MPLABXProjects$ avrdude -P /dev/ttyUSB0 -p pic32-360  -b 115200 -c stk500v2 -v -v -U flash:w:Haribo.cpp.hex

avrdude: Version 5.11.1, compiled on Oct 30 2011 at 10:37:28
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "/etc/avrdude.conf"
         User configuration file is "/home/fred/.avrduderc"

         Using Port                    : /dev/ttyUSB0
         Using Programmer              : stk500v2
         Overriding Baud Rate          : 115200
avrdude: ser_recv(): programmer is not responding
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: ser_recv(): programmer is not responding
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: ser_recv(): programmer is not responding
avrdude: stk500v2_ReceiveMessage(): timeout
Oops… Upload error ? I have to press the Uno32 reset button, then code is uploaded:
         AVR Part                      : 32MX320F128H
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PA0
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    10     8    0 no       4096    8      0  9000  9000 0x00 0x00
           flash         65    10   256    0 yes    131072  256    512  4500  4500 0x00 0x00
           lfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           lock           0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : STK500V2
         Description     : Atmel STK500 Version 2.x firmware
         Programmer Model: AVRISP
         Hardware Version: 15
         Firmware Version Master : 2.10
         Vtarget         : 0.0 V
         SCK period      : 0.1 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x504943
avrdude: safemode: lfuse reads as 0
avrdude: safemode: hfuse reads as 0
avrdude: safemode: efuse reads as 0
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: current erase-rewrite cycle count is -1145324613 (if being tracked)
avrdude: erasing chip
avrdude: reading input file "Haribo.cpp.hex"
avrdude: input file Haribo.cpp.hex auto detected as Intel Hex
avrdude: writing flash (32664 bytes):

Writing | ################################################## | 100% 9.15s

avrdude: 32664 bytes of flash written
avrdude: verifying flash memory against Haribo.cpp.hex:
avrdude: load data flash data from input file Haribo.cpp.hex:
avrdude: input file Haribo.cpp.hex auto detected as Intel Hex
avrdude: input file Haribo.cpp.hex contains 32664 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 3.29s

avrdude: verifying ...
avrdude: 32664 bytes of flash verified

avrdude: safemode: lfuse reads as 0
avrdude: safemode: hfuse reads as 0
avrdude: safemode: efuse reads as 0
avrdude: safemode: Fuses OK

avrdude done.  Thank you.

Using AVRDUDE from within MPLAB X

To use avrdude to upload a hex file you just built in MPLAB X, there are a couple steps you need to follow:
  1. (optional) From the MPIDE install folder, copy (as an example) C:\Program Files\mpide-0023-windows-20120122-test\hardware\tools\avr\bin\avrdude.exe to someplace you want to put avrdude and its configuration file, like C:\Program Files\Microchip\MPLABX\mplab_ide\bin\avrdude.exe
  2. (optional) From the MPIDE install folder, copy (as an example) C:\Program Files\mpide-0023-windows-20120122-test\hardware\tools\avr\etc\avrdude.conf to someplace you want to put avrdude and its configuration file, like C:\Program Files\Microchip\MPLABX\mplab_ide\bin\avrdude.conf
  3. From within MPLABX, open the properties for your current project. Select the Building/Loading screen, then enter the following for “Execute this line after build” (and check the box as well):
    • “C:\Program Files\Microchip\MPLABX\mplab_ide\bin\avrdude.exe” -C”C:\Program Files\Microchip\MPLABX\mplab_ide\bin\avrdude.conf” -v -p32MX795F512L -cstk500v2 -P COM40 -b 115200 -U flash:w:${ImagePath}
    • (Note that you will need to substitute the proper COM port number of your board, as well as the actual location of avrdude.exe and avrdude.conf into this command line. Also, if you’re not using an MX795 you’ll have to update that as well.)
  4. Make sure you have copied the proper linker script into your project. For example, if you’re using a chipKIT MAX32 board, just copy the chipKIT-MAX32-application-32MX795F512L.ld file from C:\Program Files\mpide-0023-windows-20120122-test\hardware\pic32\cores\pic32 into your MPLABX project folder, and then add that file to the Linker Files folder in the Project Properties.
If all of the paths are set up properly, you should get an automatic download every time you rebuild your project in MPLABX. Many times, I need to reset my chipKIT board in order to get the download to work, even though I don’t need to do this when using MPIDE. I’m not sure why this is – if anyone can suggest a workaround, that would really help.
VN:F [1.9.22_1171]
Rating: 10.0/10 (1 vote cast)
avrdude and the chipKIT Platform, 10.0 out of 10 based on 1 rating

6 thoughts on “avrdude and the chipKIT Platform”

    1. Hi Michel:

      Thanks for the link. I’ll let our Steerage Group know.

      VN:F [1.9.22_1171]
      Rating: 0.0/5 (0 votes cast)
      VN:F [1.9.22_1171]
      Rating: -1 (from 1 vote)
  1. Hi I’m Ruben de Mexico, i am using FUBARINO Board with MPLABX and tried fubarinoSD program my board, but I can not. I only get this message:

    CLEAN SUCCESSFUL (total time: 204ms)
    make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
    make[1]: Entering directory `C:/Users/Limon/MPLABXProjects/limon_1_32.X’
    make -f nbproject/Makefile-default.mk dist/default/production/limon_1_32.X.production.hex
    make[2]: Entering directory `C:/Users/Limon/MPLABXProjects/limon_1_32.X’
    “C:\Program Files (x86)\Microchip\xc32\v1.31\bin\xc32-gcc.exe” -g -x c -c -mprocessor=32MX795F512H -MMD -MF build/default/production/lemon.o.d -o build/default/production/lemon.o lemon.c
    “C:\Program Files (x86)\Microchip\xc32\v1.31\bin\xc32-gcc.exe” -mprocessor=32MX795F512H -o dist/default/production/limon_1_32.X.production.elf build/default/production/lemon.o -Wl,–defsym=__MPLAB_BUILD=1,–script=”chipKIT-application-32MX795F512.ld”,-Map=”dist/default/production/limon_1_32.X.production.map”
    “C:\Program Files (x86)\Microchip\xc32\v1.31\bin”\\xc32-bin2hex dist/default/production/limon_1_32.X.production.elf
    make[2]: Leaving directory `C:/Users/Limon/MPLABXProjects/limon_1_32.X’
    “————————————–”
    “User defined post-build step: [“C:\Program Files (x86)\Microchip\MPLABX\mplab_ide\bin\avrdude.exe” -C “C:\Program Files (x86)\Microchip\MPLABX\mplab_ide\bin\avrdude.conf” -v -p32MX795F512H -cstk500v2 -P COM20 -b 115200 -U flash:w:”dist\default\production\limon_1_32.X.production.hex”]”

    avrdude.exe: Version 5.10, compiled on Jan 19 2010 at 10:45:23
    Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
    Copyright (c) 2007-2009 Joerg Wunsch

    System wide configuration file is “C:\Program Files (x86)\Microchip\MPLABX\mplab_ide\bin\avrdude.conf”

    Using Port : COM20
    Using Programmer : stk500v2
    Overriding Baud Rate : 115200
    AVR Part : 32MX795F512H
    Chip Erase delay : 9000 us
    PAGEL : PD7
    BS2 : PA0
    RESET disposition : dedicated
    RETRY pulse : SCK
    serial program mode : yes
    parallel program mode : yes
    Timeout : 200
    StabDelay : 100
    CmdexeDelay : 25
    SyncLoops : 32
    ByteDelay : 0
    PollIndex : 3
    PollValue : 0x53
    Memory Detail :

    Block Poll Page Polled
    Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack
    ———– —- —– —– —- —— —— —- —— —– —– ———
    eeprom 65 10 4 0 no 2048 8 0 9000 9000 0xff 0xff
    flash 65 10 128 0 yes 524288 256 2048 4500 4500 0xff 0xff
    lock 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00
    lfuse 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00
    hfuse 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00
    efuse 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00
    signature 0 0 0 0 no 3 0 0 0 0 0x00 0x00
    calibration 0 0 0 0 no 1 0 0 0 0 0x00 0x00

    Programmer Type : STK500V2
    Description : Atmel STK500 Version 2.x firmware
    Programmer Model: STK500
    Hardware Version: 0
    Firmware Version Master : 0.00
    Topcard : Unknown
    Vtarget : 0.0 V
    SCK period : 0.1 us
    Varef : 0.0 V
    Oscillator : Off

    avrdude.exe: AVR device initialized and ready to accept instructions

    Reading | ################################################## | 100% 0.01s

    avrdude.exe: Device signature = 0x504943
    avrdude.exe: NOTE: FLASH memory has been specified, an erase cycle will be performed
    To disable this feature, specify the -D option.
    avrdude.exe: erasing chip
    avrdude.exe: reading input file “dist\default\production\limon_1_32.X.production.hex”
    avrdude.exe: input file dist\default\production\limon_1_32.X.production.hex auto detected as Intel Hex
    avrdude.exe: ERROR: address 0x1fc00490 out of range at line 86 of dist\default\production\limon_1_32.X.production.hex
    avrdude.exe: write to file ‘dist\default\production\limon_1_32.X.production.hex’ failed

    avrdude.exe done. Thank you.

    make[1]: Leaving directory `C:/Users/Limon/MPLABXProjects/limon_1_32.X’
    make[1]: *** [.build-conf] Error 1
    make: *** [.build-impl] Error 2

    BUILD FAILED (exit value 2, total time: 3s)

    please help, I know I’m doing wrong.

    Thank you very much, greetings from Mexico.

    VA:F [1.9.22_1171]
    Rating: 5.0/5 (1 vote cast)
    VA:F [1.9.22_1171]
    Rating: +1 (from 1 vote)
    1. Hey Rube, sorry to hear you are having difficulty. Could you do me a favor and post this issue to our forums? In this way our team will be able to answer and the issue along with solution made available to other users. Thanks so much:)

      VN:F [1.9.22_1171]
      Rating: 0.0/5 (0 votes cast)
      VN:F [1.9.22_1171]
      Rating: 0 (from 0 votes)
  2. excellent, I’ll do it, thanks

    VA:F [1.9.22_1171]
    Rating: 4.0/5 (1 vote cast)
    VA:F [1.9.22_1171]
    Rating: -1 (from 1 vote)
  3. His this problem solved aniwere i m having the same problem whit a fubarino sd

    avrdude.exe: ERROR: address 0x1fc00490 out of range at line

    VA:F [1.9.22_1171]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.22_1171]
    Rating: 0 (from 2 votes)

Comments are closed.