Close

Programming PIC32 with arduino

A project log for MCU how-tos, reviews, rants

As title says, my random essays about microcontrollers, all in one package

jaromir.sukubajaromir.sukuba 06/16/2018 at 10:532 Comments

This isn't probably the most exciting post in here, but since I'm author of firmware for #Badge for Hackaday Conference 2018 in Belgrade , I'm often asked how to update firmware in the badge, so I decided to write it down to single place to have reference point.

Omitting the most obvious ways (buying PicKit3 or PicKit4 and using MPLABX IDE or IPE tool for this task), there are other ways how to achieve the goal - from the two I have on my mind, both revolving around great piece of software, called pic32prog. You can buy PicKit2 "clone" (PicKit2 was open-source design made and released by Microchip, so those clones are more like derivative works) and use it with pic32prog, or alternatively you can build bitbanged loader using arduino. I used cheap atmega328 nano board from usual vendors, costing me something like 2USD.

Hook 3,3kOhm pull-up to D2 and D3 pins, then connect

D4 - 1kOhm resistor - MCLR

D3 - 1kOhm resistor - B0

D2 - 1kOhm resistor - B1

GND - GND

as you can see on picture

Clone git or download zip from github, extract and if you don't want to compile it, look for precompiled binary for your OS.

Now turn the arduino into PIC32 programmer by running

pic32prog -d:ascii:SERIAL -b3

where SERIAL is your serial port. For windows it's COMx, for linux it's /dev/ttyUSBx. This should load firmware into the arduino.

From this point on, this setup should be able to flash new firmware into badge, or any supported PIC32. Run pic32prog -d:ascii:/SERIAL file.hex

pic32prog -d:ascii:SERIAL file.hex

pic32prog should find the programmer and if wired properly, also the target. Don't forget to have fresh batteries installed in badge.

The rest should look like this

Notice the full FLASH loading is really slow - that's what you pay for trivial programmer from parts you have in your drawer - but acceptable for occasional firmware update.

Discussions

Marcel van Kervinck wrote 10/19/2018 at 18:31 point

This is cool, I will try this before the superconf...

  Are you sure? yes | no

Mike Szczys wrote 06/16/2018 at 16:16 point

That is a really awesome solution. I just assumed anyone without a PIC programmer available was out of luck with their badge firmware. Thanks for putting this together @jaromir.sukuba !

  Are you sure? yes | no