This is an old revision of the document!


Pickle Microchip PIC ICSP

Pi Zero programming dsPIC33EV

Pickle has been written to allow programming of PICMicro devices in FreeBSD, NetBSD, Linux, Cygwin (Windows) and MACOS/X or any UNIX/POSIX based system, which includes the Raspberry Pi and embedded devices running OpenWRT.

All systems support high voltage programming (HVP) of PICMicros with the Velleman K8048 or K8076 kits, however, other high voltage programming kits and circuits may be supported by adjustment of the I/O rules.

Support is also available to program low voltage programming (LVP) compatible PICMicros directly from a Raspberry Pi version 1 or 2, OpenWRT enabled router or a USB UART adapter. Look for devices marked LVP(PGM) or LVP(KEY) in the supported PIC devices list.

Please refer to the Microchip documentation for your device as to whether it supports high voltage (HVP) or low voltage (LVP) programming or both.

Currently supported PICMicro devices range from the PIC10 to the PIC32 but generally only devices in DIP format have been tested. This program may or may not support your device in another package type and your feedback is welcome should you gain success with the application.

In order to use the program in Windows Cygwin you must first install and setup Cygwin including the necessary development tools for building the application. See this page for details.

Darron M Broad < darron at kewl dot org >

~~UP~~

News

PIC32MM

Support has been added in the code repository for 8-bit PICMicros which have a new programming algorithm. Two families of PIC16F and one family of PIC18F have so far been released by Microchip and are supported.

The repository also has support for programming the new PIC32MM 32-bit PICs but due to errors in the data-sheet, high speed programming with the programming executive is not available at this time.

~~UP~~

Licence

Before you download and use the application you should read the LICENCE 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 run this program unless you are willing to accept the consequences of it failing for any reason.

~~UP~~

Credits and thanks

Pickle was originally written by Darron M Broad in 2005 as `k8048' to support the PIC16F627. `k8048' was updated in 2007 adding various other devices and more active development has occured since 2012 adding many more. The project was renamed from `k8048' to pickle in January 2015 as the Velleman K8048 kit became less relevant and superseded by the Raspberry Pi as the primary development platform.

Thanks go to Ian Stoyle who supplied a patch which added support for the 16F84 device which does not have a device id within its configuration. This patch was the origin of the feature to override the device probe and instead supply the device name of the target.

Kristoffer Myskja reported that he had great success with the Velleman K8048 on a laptop without serial I/O by using a cardbus serial interface. This is probably the best option for a laptop without a UART.

Johan Ahlander notified me that the application worked fine in NetBSD.

Working with keen linux user and PIC coder Paul Van Gelder I added support for the Velleman K8076 kit and 16F84A PICMicro. Thanks Paul!

Many thanks to Chaitanya Rogers who donated money toward development and to acquire new PICmicros. All the PICMicros acquired with that donation are now supported, thank you.

Thank you Josef Larsson for reporting that the 16F690 is compatible with this application using ICSP. This device may also be used in the Velleman K8048 14P socket with pins 8 to 13 unconnected.

Thanks go to David Braithwaite as I now have a PIC18LF27J53 to investigate. This was sent free of charge with a RKP28sb PICMicro kit. This PICMicro isn't compatible with the Velleman K8048 but is usable in a direct connection to a Raspberry Pi with 3V3 low voltage programming.

Thank you Gerhard Bertelsmann for adding erase support for the PIC18F26K80 and for development and testing of OpenWRT GPIO support with the Linux GPIO bit- bang driver kernel module. The PIC18F26K80 is one of a number of devices which are available to program using the LVP(KEY) mode of operation.

I recently bought a PIC16F84 on Ebay for testing purposes. The seller generously sent an extra as a spare part, thank you for that Dawn.

Dustin Hoffman has reported that he has been using the PIC16F1503 device successfully on the Raspberry Pi in LVP mode. This is an inexpensive method of adding intelligent I/O to this computer. Thank you for this information and good luck with your projects.

Thanks go to Manoj Mokashi for submitting a patch to add a clocked output mode on TxD for UARTS which cannot send a continuous break condition. This solution requires a T flip flop connected to TxD.

Simon Casey added support for various high pin count PIC24 devices, see the supported list for more information. Thank you very much for your hard work and good luck with your various projects!

Special thanks go to Steve Marchant who made a contribution which has been used to acquire an Orange Pi computer. Future development with the Orange Pi should occur whenever it arrives in 2017 and good luck Steve.

Jim Gregory has reported great success with this program using gpio-bb on an Orange Pi, thanks for your feedback and good luck with your many experiments.

Lastly, thank you to Microchip for creating these versatile micro-controllers and also for their sample program which has supplied a third of the available and tested devices.

~~UP~~

FTDI

Supported interfaces

A number of back-end methods are built-in to program PICMicros.

  1. The POSIX RS-232 serial protocol for the Velleman kits or USB UART adapter.
  2. The Raspberry Pi GPIO interface for the Velleman kits, direct to breadboard or the ChipKITPi.
  3. Linux MCP23017 I2C direct to breadboard.
  4. GPIO bit-bang driver for Linux direct to breadboard.
  5. The Banana Pi A20 GPIO interface direct to breadboard.
  6. FTDI bit-bang driver for Linux.
POSIX RS-232

This is available on every platform with a UART but due to the bit-bang nature of operation, a standard motherboard UART is recommended for high speed.

Testing with a standard UART has been done on FreeBSD and Linux, and for USB, a Prolific PL-2303 serial adapter has been tested on Linux by both myself an Fred Marquis. The PL-2303 has also been tested on MACOS/X by Tobias Braun who reported success (Thank you Tobias).

Although the Prolific PL-2303 device works, it is very slow in operation due to USB control messages for this device taking a minimum of 3ms.

USB devices, such as the cp2102 serial interface in Linux can be used in the low voltage programming mode, see here for an example method of connection.

Raspberry Pi GPIO

RPi GPIO requires voltage level shifters when connected to the Velleman K8048 kit. An example circuit for the Velleman K8048 is demonstrated here.

For the RPi GPIO direct connection to a PICMicro on a breadboard.

For the PIC32 on the chipKITPi attached to a RPi.

Linux MCP23017 I2C

Linux MCP23017 I2C is demonstrated on a RPi with a Slice of PI/O expansion board.

GPIO bit-bang driver for Linux

The GPIO bit-bang driver for Linux kernel module installation is documented here for the RPi and OpenWRT.

Banana Pi A20 GPIO

See BPi GPIO direct connection to a PICMicro on a breadboard.

FTDI bit-bang

This utilises the FTDI library in Linux to bit bang the pins on a FTDI break out board. This uses an accelerated I/O mode and has only been tested to work with 8-bit PICMicros such as the PIC16 and PIC18 in LVP mode of operation.

Interface status
Hardware interface Status Device name
Motherboard 8250/16550 UART Works well Generic
PCI LGS GM16C550 UART Works well (tested in Cygwin) Intek21 PCI IO 2S-550 Board
MCT U232 USB serial converter Not working Targus PA088
pl2303 USB serial converter Works slowly Best Connectivity (Dabs Value)
FTDI USB serial converter Not working ECS i-Buddie USB Dock
Raspberry Pi GPIO Velleman K8048 Works well 74HC03 (voltage level shifting)
Raspberry Pi GPIO Works well Breadboard at 3V3
Linux (R-PI) MCP23017 I2C Works slowly Slice of PI/O
Linux GPIO bit-bang driver Works well Breadboard at 3V3
cp2102 USB serial converter (LVP) Works slowly BAITE betemcu.cn
Generic CH341 USB serial converter Works slowly QinHeng Electronics HL-340 USB-Serial adapter
Banana Pi A20 GPIO Works well Breadboard at 3V3
FTDI bit-bang (LVP) Works well FTDI USB

~~UP~~

Supported PICMicro devices

Tested PICMicro devices

PICMicros

The devices in the following table have been tested are known to work in specific modes of operation.

The modes are as follows:

  • HVP. High voltage programming at 9 or 13V.
  • LVP(PGM). Low voltage programming with VPP and PGM at VDD.
  • LVP(KEY). Low voltage programming with VPP at VDD and entry using a 32-bit key.

Test code indicates whether ICSP I/O test code has been written for this device.

New algorithm noted in the last column refers to the new PIC16F/18F programming algorithm incompatible with the older ICSP programming method.

Test code Device name Added by Tested by HVP LVP(PGM) LVP(KEY) Velleman K8048 Comments
Y PIC16F84A Darron Broad Paul Van Gelder 13 N N
Y PIC16F627 Darron Broad 13 5 N
Y PIC16F88 Tobin Richard 13 5 N
Y PIC16F648A Darron Broad 13 5 N
Y PIC16F819 Darron Broad 13 5 N
Y PIC16F676 Darron Broad 13 N N
Y PIC12F675 Darron Broad 13 N N
Y PIC16F877A Darron Broad 13 5 N ICSP only.
Y PIC18F1320 Darron Broad 13 5 N PGM 10K to GND on 28P.
Y PIC18F2550 Darron Broad 12.5 5 N
Y PIC18F252 Darron Broad 13 5 N
Y PIC16F716 Darron Broad 13 N N
Y PIC16F505 Darron Broad 13 N N
Y PIC10F200 Darron Broad 13 N N ICSP only.
Y PIC10F202 Darron Broad 13 N N ICSP only.
Y PIC18F4550 Darron Broad 12.5 5 N ICSP only.
Y PIC18F2320 Darron Broad 13 5 N
Y PIC12F683 Darron Broad 13 N N
Y PIC16F688 Darron Broad 13 N N
Y PIC16F628A Darron Broad 13 5 N
Y PIC16F726 Darron Broad 9 N N
Y PIC12F508 Darron Broad 13 N N
Y PIC12F615 Darron Broad 13 N N
Y PIC16F872 Darron Broad 13 5 N
Y PIC16F57 Darron Broad 13 N N ICSP only.
Y PIC16F54 Darron Broad 13 N N
Y PIC16F506 Darron Broad 13 N N
Y PIC10F220 Darron Broad 13 N N ICSP only..
Y PIC16F887 Darron Broad 12 5 N ICSP only.
Y PIC12F519 Darron Broad 13 N N
Y PIC16F73 Darron Broad 13 N N
Y PIC10F320 Darron Broad 9 5 N VPP 9V. ICSP only.
Y PIC16F886 Darron Broad 12 5 N
Y PIC16F1507 Darron Broad 9 N 5 VPP 9V. Use 14P socket.
Y PIC18F25K22 Darron Broad 9 N 5 VPP 9V.
Y PIC18F4620 Darron Broad 12.5 5 N ICSP only.
Y PIC16F876A Darron Broad 13 5 N
Y PIC12F617 Darron Broad 13 N N
Y PIC18F4520 Darron Broad 12.5 5 N ICSP only.
Y PIC16F917 Darron Broad 12 N N ICSP only.
Y PIC16F84 Ian Stoyle 13 N N
Y PIC18F1330 Darron Broad 12.5 N N
Y PIC18F2431 Darron Broad 13 5 N Incompatible (VDD on pin 7).
Y PIC18F26K80 Darron Broad &
Gerhard Bertelsmann
Gerhard Bertelsmann 9 N 5 Incompatible (VPP fault).
Y PIC16F1825 Darron Broad 9 N 5 VPP 9V.
Y PIC16F1936 Darron Broad 9 N 5 VPP 9V.
Y PIC16F1847 Darron Broad 9 N 5 VPP 9V.
Y PIC18F25K50 Darron Broad 9 N 5 VPP 9V.
Y PIC18F14K50 Darron Broad 9 5 N Incompatible (PGC/PGD 3V3 limit).
Y PIC18LF27J53 Darron Broad N N 3V3 Incompatible (architecture).
Y PIC16F690 Darron Broad Josef Larsson 13 N N Use 14P socket.
Y PIC12F510 Darron Broad 13 N N
Y PIC16F59 Darron Broad 13 N N ICSP only.
Y PIC16F767 Darron Broad 13 N N
Y PIC16F1788 Darron Broad 9 N 5 VPP 9V.
Y PIC16F570 Darron Broad 13 N N
Y PIC16F721 Darron Broad 9 N N Use 14P socket.
Y PIC16F527 Darron Broad 13 N N Use 14P socket.
Y PIC12F752 Darron Broad 13 N N
Y PIC12LF1552 Darron Broad 9 N 3V3 Incompatible (VDD 3V3).
Y PIC16F1518 Darron Broad 9 N 5 VPP 9V.
Y PIC16F1455 Darron Broad 9 N 5 Incompatible (PGC/PGD 3V3 limit).
Y PIC18LF2539 Darron Broad 13 5 N
Y PIC16F526 Darron Broad 13 N N
Y PIC16F753 Darron Broad 13 N N
Y PIC16F785 Darron Broad 12 N N Use 14P socket.
Y PIC16F707 Darron Broad 9 N N ICSP only.
Y PIC18F14K22 Darron Broad 9 5 N VPP 9V. Use 14P socket.
Y PIC18F26K20 Darron Broad 9 3V3 N Incompatible (VDD 3V3).
Y PIC16F1459 Darron Broad 9 N 5 Incompatible (PGC/PGD 3V3 limit).
Y PIC24F04KA201 Darron Broad 9 N 3V3 Incompatible (architecture).
Y dsPIC33FJ06GS101A Darron Broad N N 3V3 Incompatible (architecture).
Y PIC24FJ16MC101 Darron Broad N N 3V3 Incompatible (architecture).
Y dsPIC30F1010 Darron Broad N N 5 Incompatible (architecture).
Y PIC24F16KL402 Darron Broad 9 N 3V3 Incompatible (architecture).
Y dsPIC33FJ16GS502 Darron Broad N N 3V3 Incompatible (architecture).
Y dsPIC33FJ32MC102 Darron Broad N N 3V3 Incompatible (architecture).
Y dsPIC33EP128GP502 Darron Broad N N 3V3 Incompatible (architecture).
Y PIC24HJ128GP502 Darron Broad N N 3V3 Incompatible (architecture).
Y PIC24FJ64GB002 Darron Broad N N 3V3 Incompatible (architecture).
Y PIC24FJ64GA002 Darron Broad N N 3V3 Incompatible (architecture).
Y PIC24FV32KA302 Darron Broad 9 N 5 VPP 9V. ICSP only.
Y dsPIC30F4013 Darron Broad 13 N N ICSP only.
Y dsPIC33FJ128GP802 Darron Broad N N 3V3 Incompatible (architecture).
Y PIC16F1708 Darron Broad 9 N 5 VPP 9V. Use 14P socket.
Y PIC12F1612 Darron Broad 9 N 5 VPP 9V.
Y PIC16F636 Darron Broad 13 N N
Y PIC16LF1716 Darron Broad 9 N 3V3 Incompatible (VDD 3V3).
Y PIC12LF1572 Darron Broad 9 N 3V3 Incompatible (VDD 3V3).
Y PIC24FJ128GB202 Darron Broad N N 3V3 Incompatible (architecture).
Y PIC16LF1559 Darron Broad 9 N 3V3 Incompatible (VDD 3V3).
Y PIC24FJ128GA202 Darron Broad N N 3V3 Incompatible (architecture).
Y PIC32MX150F128B Darron Broad N N 3V3 Incompatible (architecture).
Y PIC32MX250F128B Darron Broad N N 3V3 Incompatible (architecture).
Y PIC32MX795F512H Darron Broad N N 3V3 Incompatible (architecture).
Y PIC32MX170F256B Darron Broad N N 3V3 Incompatible (architecture).
Y PIC24FV08KM101 Darron Broad 9 N 5 VPP 9V. ICSP only.
Y PIC32MX270F256B Darron Broad N N 3V3 Incompatible (architecture).
Y PIC16LF18313 Darron Broad 9 N 3V3 Incompatible (VDD 3V3).
Y PIC16F1578 Darron Broad 9 N 5 VPP 9V. Use 14P socket.
Y PIC16F1776 Darron Broad 9 N 5 VPP 9V.
Y PIC16F1764 Darron Broad 9 N 5 VPP 9V.
Y PIC18F45K80 Darron Broad 9 N 5 Incompatible (VPP fault).
Y PIC16LF1566 Darron Broad 9 N 3V3 Incompatible (VDD 3V3).
Y dsPIC33EV256GM002 Darron Broad N N 5 VPP 5V. ICSP only.
Y dsPIC33EV256GM102 Darron Broad N N 5 VPP 5V. ICSP only.
Y PIC16F18346 Darron Broad 9 N 5 VPP 9V. not tested.
Y PIC16F15355 Darron Broad 9 N 5 VPP 9V. not tested. New algorithm.
Y PIC18F26K40 Darron Broad 9 N 5 VPP 9V. not tested. New algorithm.
Y PIC16F18875 Darron Broad 9 N 5 VPP 9V. not tested. New algorithm.
N PIC16F873A Chris Williams 13 5 N
N PIC16F1503 Darron Broad Dustin Hoffman 9 N 5 VPP 9V.
N PIC32MX564F128H Darron Broad Gerhard Bertelsmann N N 3V3 Incompatible (architecture).
N PIC18F13K50 Darron Broad Gerhard Bertelsmann 9 5 N Incompatible (PGC/PGD 3V3 limit).
N PIC16LF1454 Darron Broad Gerhard Bertelsmann 9 N 3V3 Incompatible (VDD 3V3).
N PIC18F4685 Darron Broad 12.5 5 N ICSP only.
N PIC24FJ256GB106 Simon Casey N N 3V3 Incompatible (architecture).
N PIC24FJ128GC010 Simon Casey N N 3V3 Incompatible (architecture).
N PIC24FJ1024GB610 Simon Casey N N 3V3 Incompatible (architecture).
N PIC24FJ128GA410 Simon Casey N N 3V3 Incompatible (architecture).
N PIC32MM0032GPL028 Darron Broad N N 3V3 Incompatible (architecture). PE not supported.
Test code Device name Added by Tested by HVP LVP(PGM) LVP(KEY) Velleman K8048 Comments

~~UP~~

Installation

Download the latest archive file pickle-4.0e.tar.gz then decompress and extract the application source code from the archive. Once you perform `sudo make install', the application will be ready for use.

This has been tested on FreeBSD 5 and 6 yet should work on all FreeBSD variants and other BSD derived systems. It has also been test to work in Linux 2.6 but only compiled for 2.4.

Here are some sample sessions obtaining the application and then installing it.

FreeBSD
cd /usr/ports/devel/gmake
make
make install
rehash
cd /root
fetch "http://wiki.kewl.org/downloads/pickle-4.0e.tar.gz"
tar zxf pickle-4.0e.tar.gz
cd pickle
gmake
gmake install
Generic
wget "http://wiki.kewl.org/downloads/pickle-4.0e.tar.gz"
tar zxf pickle-4.0e.tar.gz
cd pickle
gnumake
sudo gnumake install
Cygwin
wget "http://wiki.kewl.org/downloads/pickle-4.0e.tar.gz"
tar zxf pickle-4.0e.tar.gz
cd pickle
make
make install
cd ~
vi .pickle
DEVICE=/dev/ttyS2
SLEEP=0
BITRULES=0x001F
BUSY=0
:wq!
Debian or Debian derived
sudo -s
apt-get install build-essential mercurial libftdi-dev
rehash
hg clone http://hg.kewl.org/pub/pickle
cd pickle
make
make install

~~UP~~

Configuration

A dot file in your home directory (.pickle) is used to configure the application.

The options are as follows.

# I/O device: tty, ttyUSB, RPI, I2C (MCP23017) or GPIO BIT-BANG
#
#DEVICE=/dev/ttyu0
#DEVICE=/dev/ttyS0
#DEVICE=/dev/ttyUSB0
DEVICE=RPI
#DEVICE=RPI2
#DEVICE=/dev/i2c-1
#DEVICE=/dev/gpio-bb

# I/O 1/2-bit delay/sleep time
#
# For ttyS 1 is fine
# For ttyUSB try 600
#
# When SLEEP is set to zero no delay is taken
# When SLEEP is less than 10, then SLEEP x I/O bit time is taken for R-PI and tty
# When SLEEP is less than 100 a busy loop is utilised
# When SLEEP is>=100 then system usleep is used.
#
# For GPIO BIT-BANG SLEEP configures the low and high clock durations in the driver
#
# ttyu/ttyS
#SLEEP=1
# ttyUSB
#SLEEP=600
# RASPBERRY PI VELLEMAN K8048
#SLEEP=10
# RASPBERRY PI GPIO
SLEEP=1
# MCP23017 I2C
#SLEEP=0
# GPIO BIT-BANG
#SLEEP=1

# I/O bit rules.
#       These rules determine the polarity of the control lines and whether
#       data input requires data output pulled high.
# 0x0001 PGD_OUT_FLIP
# 0x0002 PGC_OUT_FLIP
# 0x0004 VPP_OUT_FLIP
# 0x0008 PGD_IN_FLIP
# 0x0010 PGD_IN_PULLUP
# 0x0020 PGM_OUT_FLIP
# 0x0040 VPP_OUT_CLOCK
#       These rules are for GPIOs on program exit.
# 0x0100 PGD_RELEASE
# 0x0200 PGC_RELEASE
# 0x0400 PGM_RELEASE
# 0x0800 VPP_RELEASE
# 0x1000 VPP_RUN
#       This rule enables shift with irq lock for GPIO BIT-BANG.
# 0x2000 BB_LOCK
#       This rule re-enables the ALT0 function when an R-PI GPIO is released.
# 0x4000 ALT_RELEASE
#
# TTY VELLEMAN K8048 = PGD_IN_PULLUP + PGD_OUT_FLIP + PGC_OUT_FLIP + VPP_OUT_FLIP + PGD_IN_FLIP
# TTY VELLEMAN K8076 = PGD_IN_PULLUP
# RPI VELLEMAN K8048 = PGD_IN_PULLUP
#
# TTY VELLEMAN K8048
#BITRULES=0x001F
# TTY VELLEMAN K8076
#BITRULES=0x0010
# RASPBERRY PI VELLEMAN K8048
#BITRULES=0x0010
# RASPBERRY PI GPIO
BITRULES=0x1000
# MCP23017 I2C
#BITRULES=0x1010
# GPIO BIT-BANG
#BITRULES=0x1000
# CHIPKIT PI PIC32 ICSP
#BITRULES=0x4F00
# HUMBLE CAN PROTOTYPE
#BITRULES=0x5700

# I/O busy cursor (0=DISABLED)
#
BUSY=0

# RASPBERRY PI VELLEMAN K8048 (README.raspi)
#
# TX/!MCLR/VPP     - DSUB9(3)
#VPP=14
# PGM              - NOT SUPPORTED ON VELLEMAN K8048
#PGM=22
# RTS/PGC CLOCK    - DSUB9(7)
#PGC=15
# DTR/PGD DATA_OUT - DSUB9(4)
#PGDO=23
# CTS/PGD DATA_IN  - DSUB9(8)
#PGDI=24

# RASPBERRY PI VELLEMAN K8048 (http://wiki.kewl.org/dokuwiki/boards:rpi:k8048)
#
# TX/!MCLR/VPP     - DSUB9(3)
#VPP=14
# PGM              - NOT SUPPORTED ON VELLEMAN K8048
#PGM=22
# RTS/PGC CLOCK    - DSUB9(7)
#PGC=18
# DTR/PGD DATA_OUT - DSUB9(4)
#PGDO=24
# CTS/PGD DATA_IN  - DSUB9(8)
#PGDI=25

# RASPBERRY PI GPIO (separate PGD DATA I/O)
#                  = SLICE OF PI/O =
# !MCLR/VPP        - PI/O G04
#VPP=4
# PGM              - PI/O G22
#PGM=22
# PGC CLOCK        - PI/O G25
#PGC=25
# PGD DATA_OUT     - PI/O G24
#PGDO=24
# PGD DATA_IN      - PI/O G23
#PGDI=23

# R-PI OR GPIO BIT-BANG (single PGD DATA I/O)
#                  = SLICE OF PI/O =
# !MCLR/VPP        - PI/O G04
#VPP=4
# PGM              - PI/O G22
#PGM=22
# PGC CLOCK        - PI/O G25
#PGC=25
# PGD DATA_I/O     - PI/O G24
#PGD=24

# R-PI OR GPIO BIT-BANG (single PGD DATA I/O)
#                  = CHIPKIT PI =
# !MCLR/VPP        - RPi-Connect 18
VPP=9
# PGM              - RPi-Connect 12
PGM=22
# PGC CLOCK        - RPi-Connect 16
PGC=10
# PGD DATA_I/O     - RPi-Connect 20
PGD=11

# R-PI OR GPIO BIT-BANG (single PGD DATA I/O)
#                  = CHIPKIT PI PIC32 ICSP =
# !MCLR/VPP        - /RESET
#VPP=4
# PGM              - N/A
#PGM=65535
# PGC CLOCK        - PGC1 RX2
#PGC=14
# PGD DATA_I/O     - PGD1 TX2
#PGD=15

# R-PI OR GPIO BIT-BANG (single PGD DATA I/O)
#                  = HUMBLE CAN PROTOTYPE =
# !MCLR/VPP        - /RESET
#VPP=18
# PGM              - N/A
#PGM=65535
# PGD TXD          - PGD RX2
#PGD=14
# PGC RXD          - PGC TX2
#PGC=15

# MCP23017 I2C ADDRESS (README.i2c)
#
MCP=0x20

# ICSP I/O 1/2-bit sleep time for `kio'.
SLEEP=30

# Debug level (0=NONE, 1=ERROR, 10=INFO)
DEBUG=1
FreeBSD using a Velleman K8048 with a serial UART
DEVICE=/dev/ttyu0
SLEEP=0
BITRULES=0x001F
BUSY=0
RPi version 1 using a Velleman K8048 with a 74HC03
DEVICE=RPI
SLEEP=10
BITRULES=0x0010
VPP=14
PGC=18
PGDO=24
PGDI=2
Cygwin for Windows using a Velleman K8048 with an Intek21 PCI IO 2S-550 Board
DEVICE=/dev/ttyS2
SLEEP=0
BITRULES=0x001F
BUSY=0
RPi version 1 GPIO Low Voltage Programming (LVP) with PGM
DEVICE=RPI
SLEEP=1
BITRULES=0x0000
VPP=4
PGM=22
PGC=25
PGDO=24
PGDI=23
RPi version 2 GPIO Low Voltage Programming (LVP) without PGM
DEVICE=RPI2
SLEEP=1
BITRULES=0x4F00
VPP=9
PGM=65535
PGC=10
PGD=11
Linux MCP23017 I2C LVP
DEVICE=I2C
SLEEP=1
BITRULES=0x0010
MCP=0x20
Linux FTDI bit-bang LVP
# TX  0
# RX  1
# RTS 2
# CTS 3
# DTR 4
# DSR 5
# DCD 6
# RI  7
DEVICE=FTDI
BITRULES=0x1000
SLEEP=1
VPP=0
PGC=1
PGD=3
PGM=-1  # DISABLED

~~UP~~

Advanced configuration

Pi Zero programming PIC32MX

On dsPIC/PIC24 and PIC32 devices, Microchip provide a `programming executive'.

This software is loaded into the chip to speed up ICSP.

Pickle supports ICSP with the programming executive (PE) on the PIC32 but not the dsPIC/PIC24 devices. Currently there are no plans to add PE support for the dsPIC/PIC24.

By default, PIC32 PE mode is not enabled and a few steps must be completed to activate this mode of operation.

If you have a .pickle file then rename it with a temporary name.

mv ~/.pickle ~/.pickle-config

Make a directory named .pickle in your home dir.

mkdir ~/.pickle

Move any old config into the new directory, renaming it to `config'.

mv ~/.pickle-config ~/.pickle/config

Download and unzip the programming executive from Microchip, Eg. for the PIC32MX150F128B.

cd ~/.pickle
wget -q http://ww1.microchip.com/downloads/en/DeviceDoc/RIPE_11_000301.zip
unzip RIPE_11_000301.zip

A file named RIPE_11_000301.hex will now exist in the .pickle directory. When we use p32, and it finds this file, it will automatically load it into the chip.

The following PE files are all that's required for the PIC32MX range of micros.

md5sum filename
2662befb94584d40b905a9040a9ed2f4 RIPE_06_000201.hex
4cb8f6492b1234a45c92979a36d91587 RIPE_11_000301.hex
aea1a950b72471e54b82852b93105d6a RIPE_15_000502.hex

To test that the PE has been registered correctly, we can issue the id command, and if the PE is found the filename is shown. If the filename is not shown then something is wrong.

p32 id
[1D000000] [PROGRAM]  00008000 WORDS
[1F80F220] [DEVICEID] 14D06053 PIC32MX150F128B
[1FC00000] [BOOT]     00000300 WORDS
[1FC00BF0] [DEVCFG3]  CFFFFFFF
[1FC00BF4] [DEVCFG2]  FFF9FFD9
[1FC00BF8] [DEVCFG1]  FC67CF59
[1FC00BFC] [DEVCFG0]  7FFFFFFB
           [PE]       RIPE_11_000301.hex

The speed up when using the PIC32 PE to read and write to flash file is considerable. For example, programming 128KB without PE takes about 60 seconds on the RPi, with the PE it takes about 7.5 seconds. Verifying the same data takes 2 minutes without the PE and 5.5 seconds with it.

~~UP~~

Running the application

There are multiple ways to run the pickle and its mode of operation is selected by using one of its symlinked command variations.

pickle: Show usage of other modes of operation
$ pickle
USAGE: pickle
Usage information.

FILES:
 /home/darron/.pickle
                Configuration.

FRONTENDS:
 FILE
                File input (INHX32 format).
 STDIN
                Standard input (INHX32 format).
 TTY
                POSIX serial I/O.

BACKENDS:
 BIT-BANG
                Linux GPIO bit-bang version 1.3.
 FTDI BIT-BANG
                Linux FTDI bit-bang.
 MCP23017
                Linux MCP23017 I2C.
 RPI
                Raspberry Pi GPIO.
 TTY
                POSIX serial I/O.

ENVIRONMENT:
 PICKLE
                Configuration file.

EXAMPLES:
 p12 SELECT DEVICE OPERATION [ARG]
                12-bit word PIC10F/12F/16F operations.
 p14 [SELECT DEVICE] [LVP] OPERATION [ARG]
                14-bit word PIC10F/12F/16F operations.
 n14 [LVP] OPERATION [ARG]
                14-bit word PIC16F operations.
 p16 [SELECT DEVICE] [LVP|HVP] OPERATION [ARG]
                16-bit word PIC18F operations.
 n16 [LVP] OPERATION [ARG]
                16-bit word PIC18F operations.
 p24 [SELECT DEVICE] [LVP|HVP] OPERATION [ARG]
                24-bit word PIC24/dsPIC operations.
 p32 OPERATION [ARG]
                32-bit word PIC32 operations.
 pctrl RUN|STOP|RESTORE
                Control master clear.
 pload PROGRAM|VERIFY TTY|IP FILE [16]
                Program or verify file on TTY or network.
 ptest TEST [ARG]
                Hardware tests.

VERSION:
 4.0f
p12: Perform operations on 12-bit word architecture devices
$ p12
USAGE: p12 SELECT DEVICE OPERATION [ARG]
12-bit word PIC10F/12F/16F operations.

Error: Missing arg(s).

FILES:
 /home/darron/.pickle
                Configuration.

ENVIRONMENT:
 PICKLE
                Configuration file.

EXAMPLES:
 p12 select
                Dump supported devices.
 p12 select PIC1XFXXX blank
                Blank device (disable protection and bulk erase).
 p12 select PIC1XFXXX config
                Display device configuration.
 p12 select PIC1XFXXX data
                Display data flash content.
 p12 select PIC1XFXXX dump
                Dump device content (INHX32 format).
 p12 select PIC1XFXXX flash [n] [address]
                Display all or n words of program flash content from address.
 p12 select PIC1XFXXX id
                Display device identification.
 p12 select PIC1XFXXX osccal
                Display oscillator calibration.
 p12 select PIC1XFXXX osccal 0x0c1a
                Restore oscillator calibration as 0x0c1a.
 p12 select PIC1XFXXX program [file.hex] [noblank]
                Blank and program file.hex or stdin to flash (INHX32 format).
 p12 select PIC1XFXXX verify [file.hex]
                Verify file.hex or stdin in flash (INHX32 format).
 p12 select PIC1XFXXX view [file.hex]
                View file.hex or stdin (INHX32 format).
 p12 select PIC1XFXXX /dev/ttyUSB0 | 8048
                Listen on /dev/ttyUSB0 or network for remote programming.

VERSION:
 4.0
p14: Perform operations on 14-bit word architecture devices
$ p14
USAGE: p14 [SELECT DEVICE] [LVP] OPERATION [ARG]
14-bit word PIC10F/12F/16F operations.

Error: Missing arg(s).

FILES:
 /home/darron/.pickle
                Configuration.

ENVIRONMENT:
 PICKLE
                Configuration file.

EXAMPLES:
 p14 select
                Dump supported devices.
 p14 select 16F84 OPERATION [ARG]
                Select device PIC16F84.
 p14 lvp OPERATION [ARG]
                LVP 32-bit key entry.
 p14 blank
                Blank device (disable protection and bulk erase).
 p14 config
                Display device configuration.
 p14 config 0x3000
                Restore band-gap configuration as 0x3000.
 p14 data
                Display data EEPROM content.
 p14 dump
                Dump device content (INHX32 format).
 p14 erase eeprom | flash | id | row [n]
                Erase EEPROM, flash, id or flash at row for n rows.
 p14 flash [n] [address]
                Display all or n words of program flash content from address.
 p14 id
                Display device identification.
 p14 osccal
                Display oscillator calibration.
 p14 osccal 0x343c
                Restore oscillator calibration as 0x343c.
 p14 program [file.hex] [noblank]
                Blank and program file.hex or stdin to flash (INHX32 format).
 p14 verify [file.hex]
                Verify file.hex or stdin in flash (INHX32 format).
 p14 view [file.hex]
                View file.hex or stdin (INHX32 format).
 p14 /dev/ttyUSB0 | 8048
                Listen on /dev/ttyUSB0 or network for remote programming.

VERSION:
 4.0
n14: Perform operations on 14-bit word architecture devices (new programming algorithm)
$ n14
USAGE: n14 [LVP] OPERATION [ARG]
14-bit PIC16F operations.

Error: Missing arg(s).

FILES:
 /home/darron/.pickle/config
                Configuration file.

ENVIRONMENT:
 PICKLE
                Configuration file.

EXAMPLES:
 n14 select
                Dump supported devices.
 n14 lvp OPERATION [ARG]
                LVP 32-bit key entry.
 n14 blank
                Blank device (disable protection and bulk erase).
 n14 config
                Display device configuration.
 n14 data
                Display data EEPROM content.
 n14 dump
                Dump device content (INHX32 format).
 n14 flash [n] [address]
                Display all or n words of program flash content from address.
 n14 id
                Display device identification.
 n14 program [file.hex] [noblank]
                Blank and program file.hex or stdin to flash (INHX32 format).
 n14 verify [file.hex]
                Verify file.hex or stdin in flash (INHX32 format).
 n14 view [file.hex]
                View file.hex or stdin (INHX32 format).
 n14 /dev/ttyUSB0 | 8048
                Listen on /dev/ttyUSB0 or network for remote programming.

VERSION:
 4.0f
p16: Perform operations on 16-bit word architecture devices
$ p16
USAGE: p16 [SELECT DEVICE] [LVP|HVP] OPERATION [ARG]
16-bit word PIC18F operations.

Error: Missing arg(s).

FILES:
 /home/darron/.pickle
                Configuration.

ENVIRONMENT:
 PICKLE
                Configuration file.

EXAMPLES:
 p16 select
                Dump supported devices.
 p16 select 18LF2539 OPERATION [ARG]
                Select device PIC18LF2539.
 p16 lvp OPERATION [ARG]
                LVP 32-bit key entry.
 p16 hvp OPERATION [ARG]
                HVP 32-bit key entry.
 p16 blank
                Blank device (disable protection and bulk erase).
 p16 config
                Display device configuration.
 p16 data
                Display data EEPROM content.
 p16 dump
                Dump device content (INHX32 format).
 p16 erase eeprom | flash | id | row [n]
                Erase EEPROM, flash, id or flash at row for n rows.
 p16 flash [n] [address]
                Display all or n words of program flash content from address.
 p16 id
                Display device identification.
 p16 program [file.hex] [noblank]
                Blank and program file.hex or stdin to flash (INHX32 format).
 p16 verify [file.hex]
                Verify file.hex or stdin in flash (INHX32 format).
 p16 view [file.hex]
                View file.hex or stdin (INHX32 format).
 p16 /dev/ttyUSB0 | 8048
                Listen on /dev/ttyUSB0 or network for remote programming.

VERSION:
 4.0
n16: Perform operations on 16-bit word architecture devices (new programming algorithm)
$ n16
USAGE: n16 [LVP] OPERATION [ARG]
16-bit PIC18F operations.

Error: Missing arg(s).

FILES:
 /home/darron/.pickle/config
                Configuration file.

ENVIRONMENT:
 PICKLE
                Configuration file.

EXAMPLES:
 n16 select
                Dump supported devices.
 n16 lvp OPERATION [ARG]
                LVP 32-bit key entry.
 n16 blank
                Blank device (disable protection and bulk erase).
 n16 config
                Display device configuration.
 n16 data
                Display data EEPROM content.
 n16 dump
                Dump device content (INHX32 format).
 n16 flash [n] [address]
                Display all or n words of program flash content from address.
 n16 id
                Display device identification.
 n16 program [file.hex] [noblank]
                Blank and program file.hex or stdin to flash (INHX32 format).
 n16 verify [file.hex]
                Verify file.hex or stdin in flash (INHX32 format).
 n16 view [file.hex]
                View file.hex or stdin (INHX32 format).
 n16 /dev/ttyUSB0 | 8048
                Listen on /dev/ttyUSB0 or network for remote programming.

VERSION:
 4.0f
p24: Perform operations on 24-bit word architecture devices
$ p24
USAGE: p24 [SELECT DEVICE] [LVP|HVP] OPERATION [ARG]
24-bit word PIC24/dsPIC operations.

Error: Missing arg(s).

FILES:
 /home/darron/.pickle
                Configuration.

ENVIRONMENT:
 PICKLE
                Configuration file.

EXAMPLES:
 p24 select
                Dump supported devices.
 p24 select 33EP128GP502 OPERATION [ARG]
                Select device dsPIC33EP128GP502.
 p24 select 24FJ128GB202 OPERATION [ARG]
                Select device PIC24FJ128GB202.
 p24 lvp OPERATION [ARG]
                LVP 32-bit key entry.
 p24 hvp OPERATION [ARG]
                HVP 32-bit key entry.
 p24 blank
                Blank device (disable protection and bulk erase).
 p24 config
                Display device configuration.
 p24 data
                Display data EEPROM content.
 p24 dump
                Dump device content (INHX32 format).
 p24 exec [n] [address]
                Display all or n words of executive flash content from address.
 p24 flash [n] [address]
                Display all or n words of program flash content from address.
 p24 id
                Display device identification.
 p24 program [file.hex] [noblank]
                Blank and program file.hex or stdin to flash (INHX32 format).
 p24 verify [file.hex]
                Verify file.hex or stdin in flash (INHX32 format).
 p24 view [file.hex]
                View file.hex or stdin (INHX32 format).
 p24 /dev/ttyUSB0 | 8048
                Listen on /dev/ttyUSB0 or network for remote programming.

VERSION:
 4.0
p32: Perform operations on 32-bit word architecture devices
$ p32
USAGE: p32 OPERATION [ARG]
32-bit word PIC32 operations.

Error: Missing arg(s).

FILES:
 /home/darron/.pickle
                Configuration file.

ENVIRONMENT:
 PICKLE
                Configuration file.

EXAMPLES:
 p32 select
                Dump supported devices.
 p32 boot [n] [address]
                Display all or n words of boot flash content from address.
 p32 blank
                Blank device (erase).
 p32 config
                Display device configuration.
 p32 dump
                Dump device content (INHX32 format).
 p32 flash [n] [address]
                Display all or n words of program flash content from address.
 p32 id
                Display device identification.
 p32 program [file.hex] [noblank]
                Blank and program file.hex or stdin to flash (INHX32 format).
 p32 verify [file.hex]
                Verify file.hex or stdin in flash (INHX32 format).
 p32 view [file.hex]
                View file.hex or stdin (INHX32 format).
 p32 /dev/ttyUSB0 | 8048
                Listen on /dev/ttyUSB0 or network for remote programming.

VERSION:
 4.0
ptest: Perform various hardware and communication tests
$ ptest
USAGE: ptest TEST ARG
Hardware tests.

Error: Missing args.

FILES:
 /home/darron/.pickle
                Configuration.

ENVIRONMENT:
 PICKLE
                Configuration file.

EXAMPLES:
 ptest VPP|PGC|PGD|PGM 5
                VPP, PGC, PGD or PGM LOW->HIGH->LOW output test with 5 seconds mark time.
 ptest 0 10
                PGD input test with 10 iterations of 1 second per step.
 ptest 1 10
                D-SUB-9 test with 10 seconds per step.
 ptest 2 10
                ICSP test with 10 seconds per step.
 ptest 3 0
                D-SUB-9 RTS 7 (PGC) DTR 4 (PGD) test with no mark time.
 ptest 3 1
                D-SUB-9 RTS 7 (PGC) DTR 4 (PGD) test with SLEEP mark time.
 ptest 3 100
                D-SUB-9 RTS 7 (PGC) DTR 4 (PGD) test with 100 microseconds mark time.
 ptest 4 100
                16F627 debug test with 100 microseconds clock mark time.
 ptest 5 100
                ICSPIO test with 100 microseconds clock mark time.
 ptest 6 10
                RPi GPIO test with 10 seconds mark time.

VERSION:
 4.0f
pctrl: Control master clear on GPIO (R-PI or OpenWRT)
$ pctrl
USAGE: pctrl RUN|STOP|RESTORE
Control master clear.

Error: Missing arg.

FILES:
 /home/darron/.pickle
                Configuration.

ENVIRONMENT:
 PICKLE
                Configuration file.

EXAMPLES:
 pctrl RUN
                Raise master clear to take the device out of reset.
 pctrl STOP
                Lower master clear to put the device in reset.
 pctrl RESTORE
                Lower then raise master clear to reset the device.

VERSION:
 4.0
pload: Program or verify file on TTY or network
$ pload
USAGE: pload PROGRAM|VERIFY TTY|IP FILE [16|24|32]
Program or verify file on TTY or network.

Error: Missing arg.

FILES:
 /home/darron/.pickle/config
                Configuration file.

ENVIRONMENT:
 PICKLE
                Configuration file.

EXAMPLES:
 pload program /dev/ttyS0 file.hex
                Program file.hex (INHX32 format) on /dev/ttyS0.
 pload verify /dev/ttyS0 file.hex
                Verify file.hex (INHX32 format) on /dev/ttyS0.
 pload program 192.168.1.100 < led.hex
                Program stdin (INHX32 format) on 192.168.1.100 port 8048.
 pload program /dev/ttyAMA0 led.hex 24
                Program led.hex (INHX32 format) on /dev/ttyAMA0 using 24-bit boot loader addressing.

VERSION:
 4.0

~~UP~~

Using the Application

PIC16F54

To demonstrate its usage we may utilise some assembly code supplied in the Pickles support package.

An example assembly file for the PIC16F627 on the Velleman K8048 kit sends the text “hello, world” over the ICSP lines to the host PC within an infinite loop.

The ptest command has a function to decode the text as sent above and dump it to the console, below is an example of assembling the assembly code file, writing it to the PIC16F627 chip and dumping out the text sent by the chip.

Build debug assembly file
hg clone http://hg.kewl.org/pub/pickles
cd pickles/examples/pic16f627/
make
Program PIC16F627 with debug assembly hex file
p14 program debug.hex
Total: 272
Verify PIC16F627 against debug assembly hex file
p14 verify debug.hex
Total: 272 Fail: 0

It is important to remember that on the Velleman K8048 the switch must be set to PROG. mode when writing to the chip and set to the RUN mode to execute code.

PIC16F627 debug assembly test mode
ptest 4 100

TEST MODE 4 [16F627 debug.asm] CTRL-C TO STOP

io_test4: read byte: 02 .
io_test4: read byte: 48 H
io_test4: read byte: 65 e
io_test4: read byte: 6C l
io_test4: read byte: 6C l
io_test4: read byte: 6F o
io_test4: read byte: 2C ,
io_test4: read byte: 20
io_test4: read byte: 77 w
io_test4: read byte: 6F o
io_test4: read byte: 72 r
io_test4: read byte: 6C l
io_test4: read byte: 64 d
io_test4: read byte: 0A .
io_test4: read byte: 03 .
io_test4: read line: Hello, world
io_test4: read byte: 02 .
^C
TEST DONE

Below are other examples of using the other commands available in pickle.

Display device identity
p14 id
[0000] [PROGRAM]  0400 WORDS
[2000] [USERID0]  0001 .
[2001] [USERID1]  0002 .
[2002] [USERID2]  0003 .
[2003] [USERID3]  0004 .
[2004] [RESERVED] 3FFF
[2005] [RESERVED] 3FFF
[2006] [DEVICEID] 07A0 DEV:7A0 REV:00 PIC16F627
[2007] [CONFIG]   3F31
[2100] [DATA]     0080 BYTES
Display only device configuration
p14 config
[2007] [CONFIG]   3F31
Display data EEPROM
p14 data
[2100] 48 65 6C 6C 6F 2C 20 77 6F 72 6C 64 0A 00 FF FF Hello, world....
Display program flash
p14 flash
[0000] 2862 3FFF 3FFF 3FFF 0009 00A4 01A5 01A6 b.......
[0008] 0BA6 2808 0BA5 2808 0BA4 2808 3400 3EFF ........
[0010] 1D03 280F 3400 00A4 3001 200F 0BA4 2814 ........
[0018] 3400 00A4 300B 200F 300B 200F 0BA4 281A ........
[0020] 3400 00A5 300A 2019 0BA5 2822 3400 01A0 ....."..
[0028] 01A1 1F06 3400 0BA1 2829 0BA0 2829 3400 ....).).
[0030] 01A0 01A1 1B06 3400 0BA1 2832 0BA0 2832 .....2.2
[0038] 3400 00A2 1406 2027 1786 2030 1386 3008 ...'.0..
[0040] 00A3 2027 0103 0CA2 1803 3080 0086 2030 .'.....0
[0048] 0BA3 2841 1006 3400 1683 1303 009B 1283 .A......
[0050] 1303 3002 2039 1683 1303 141C 081A 0A9B ..9.....
[0058] 1283 1303 3800 1903 285F 2039 2853 3003 ...._9S.
[0060] 2039 3400 1283 1303 018B 3007 009F 0186 9.......
[0068] 1683 1303 158E 3080 0081 307E 0086 30FF .....~..
[0070] 0085 1283 1303 3000 204C 3001 2005 2873 ....L..s
Dump device content
p14 dump
:020000040000FA
:100000006228FF3FFF3FFF3F0900A400A501A601B2
:10001000A60B0828A50B0828A40B08280034FF3ECF
:10002000031D0F280034A40001300F20A40B142856
:100030000034A4000B300F200B300F20A40B1A2823
:100040000034A5000A301920A50B22280034A00195
:10005000A101061F0034A10B2928A00B2928003478
:10006000A001A101061B0034A10B3228A00B3228ED
:100070000034A2000614272086173020861308308B
:10008000A30027200301A20C031880308600302033
:10009000A30B412806100034831603139B00831220
:1000A000031302303920831603131C141A089B0A09
:1000B00083120313003803195F28392053280330B3
:1000C00039200034831203138B0107309F0086010F
:1000D000831603138E15803081007E308600FF303A
:1000E00085008312031300304C2001300520732853
:020000040000FA
:10420000480065006C006C006F002C0020007700F7
:104210006F0072006C0064000A000000FF00FF00E5
:020000040000FA
:024000000100BD
:024002000200BA
:024004000300B7
:024006000400B4
:02400E00313F40
:00000001FF

I hope you enjoy using this application, good luck.

~~UP~~

This website uses cookies for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information