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:- close any running mpide
- edit ~/.mpide/preferences.txt
- look for preproc.save_build_files attribute
- Set it to true: preproc.save_build_files=true
- save the preference file
/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
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.rcUse 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 microcontrollersCheck 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:- (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
- (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
- 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.)
- 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.


