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

jaromirsukubajaromir.sukuba 06/16/2018 at 10:536 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

7emenov.alex wrote 04/17/2020 at 16:41 point

с помощью этой приблуды можно прошить PIC32MX564F128H?

  Are you sure? yes | no

QuantumStar wrote 10/28/2019 at 21:24 point

I must be doing something wrong... I tried this, but get an error that the 'Arduino Bootloader not found'. I know this is an old post, but just saying, I'm not having any luck using an Uno for this.

  Are you sure? yes | no

penumbra wrote 03/08/2022 at 15:59 point

It could be that you have unsupported version of bootloader on yout arduino nano board.

You need to flash `old` bootloader on your nano you can find it in

```
arduino-1.8.XX/hardware/arduino/avr/bootloaders/atmega/ATmegaBOOT_168_atmega328.hex
```

I've used raspberry pi and avrdude but i guess you can use another nano or arduino uno.

After that, you are good to go with this procedure.

  Are you sure? yes | no

Andy Preston wrote 07/20/2019 at 16:15 point

Thanks so much for this. I'm an "AVR Dude" ;) but occasionally I want to build someone else's project that uses a PIC32. I didn't want to have to spend loads of money on a PICKIT that'd hardly ever get used. This is just what I need to flash firmware to a PIC once every now and again. 

  Are you sure? yes | no

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