Table of Contents
Nanu Nanu Microchip PIC32MX ICSP
This is a Microchip PIC32 ICSP (in circuit serial programmer) for AVR micro-controllers. Nanu nanu allows an AVR to program the flash on a PIC32.
It has been developed specifically for Arduino Nano 3.0 clones with CH340G UARTs and Arduino Pro Mini clones but will work with any AVR based Arduino clone such as the RKAT28sb.
What nanu nanu isn't though, is an Arduino project; it's written directly for ATMEL AVR and depends on avr-gcc and avrdude but not the Arduino Processing IDE nor does it utilise the Wiring API.
Licence
Nanu nanu is licensed under same terms as Pickle Microchip PIC ICSP which is the source of the software used to create this project. The Pickle LICENCE is found here. This licence details the rights and liabilities of using the application and it should be especially understood that I, the author, will not accept any responsibility for any side effects of running it. Do not download and use this firmware unless you are willing to accept the consequences of it failing for any reason.
Credits and thanks
This software was written by Darron M Broad in December 2014 and is an adaptation of Pickle Microchip PIC ICSP.
This project was inspired by a retrobsd forum post by Robert Rozee where it was used to demonstrate programming a PIC32 using ICSP with pic32prog.
Install
First ensure avr-gcc and avrdude are installed. If you have the Arduino IDE installed then you have them already, if not, install with something like the following.
apt-get install gcc-avr avr-libc avrdude
Next we build Nanu nanu, for this process three make files exist:
- 3V3-8M.mk
- 5V-16M.mk
- 3V3-16M.mk
The first is for the Pro Mini at 3V3 with an 8 MHz XTAL, the second for the Nano 3.0 and anything else running at 5V and the last one is experimental, running a 5V board at 3V3.
The experimental configuration is not supported by ATMEL and your particular CPU may or may not work reliably. Try it and see.
In this example we install onto a Arduino Pro Mini (3V3, 8 MHz).
hg clone http://hg.kewl.org/pub/nanunanu cd nanunanu make make -f 3V3-8M.mk 57600
The value 57600 given is the speed of the installed boot loader and this line uploads the hex file to the chip. For the Pro Mini and the Nano, the boot loader, by default, uses 57600 baud but Optiboot, for example, uses 115200.
NB. If you have a Pro Mini at 5V with a 16M XTAL, you would use 5V-16M.mk.
Set up
The PIC32 target is a 3V3 only device but can have 5V tolerant ICSP, but many do not. You must familiarise yourself with the target PIC before proceeding, for example, the following schematics do not go into fine detail about wiring.
For 3V3 arduino devices we use a source mode of operation and for 5V devices we use a sink mode when programming the PIC.
Source or sink mode is selected in the make file. Only change this setting if you know what you are doing and likewise, do not run a 3V3 device at 5V.
Install Pickle Microchip PIC ICSP. We will use the `pload' tool for uploading projects to the target PIC32MX.
The Pickle configuration needs editing, add or change the entry `BAUDRATE'; set it to 57600 for 3V3 devices with an 8 MHz XTAL or to 115200, for 5V devices with a 16 MHz XTAL.
This speed is not the speed of the boot loader, but now refers to the speed of the programmer. For devices with 8 MHz XTALs only 57600 is reliable and supported.
Nanu Nanu is also compatible with PIC32Prog. This is an alternative to using `pload'.
Regarding the source mode schematic, a BAT42 diode has been tested and works fine. A 1N4148 may also work here.
Program
Prepare the target PIC and the Arduino for programming. The arduino LED should be blinking quickly to indicate that it is ready.
Now program a PIC32MX device. Here is an example programming a PIC32MX150F128B with the Micromite BASIC firmware.
This is for an 8 Mhz 3V3 pro mini at 57600 baud, a 16 Mhz 5V pro mini at 115200 baud will be faster.
pload program /dev/ttyCP2104 MX150\ 28-pin.hex stk500v2_recv:rw_get MESSAGE_START failed stk500v2_cmd: command timed out, resending ... Total: 134144 Time: 1:24.38s
If pload reports an error when connecting then this is because of the boot loader immediately after a DTR reset. You can disconnect DTR (Pro Mini) or just ignore it (Nano) as the loader does.
When programming the LED will blink at around 1 Hz.
Verify
pload verify /dev/ttyCP2104 MX150\ 28-pin.hex stk500v2_recv:rw_get MESSAGE_START failed stk500v2_cmd: command timed out, resending ... Total: 134144 Fail: 0 Time: 1:25.38s
When verifying the LED will blink slowly.