Microchip Technology PICkit 2 Interface Guide

PICkit 2 Interface Guide
PC Application v2.61
OS Firmware v2.32
Document #:
Title:
Date: March 23, 2009
PICkit 2 Interface Guide
Matches Firmware Version 2.32.00, and software V2.6100
This document presents information on the design of the PICkit
Description:
2 PC application and OS firmware, and the interfaces between the Device File, Application, and Firmware.
Microchip Technology, Inc. PICkit 2 Interface Guide
Page 1 of 36
1.0 INTRODUCTION ...........................................................................................................................................3
2.0 GUIDING DESIGN GOALS ..........................................................................................................................3
3.0 ARCHITECTURE OVERVIEW ...................................................................................................................3
4.0 BOOTLOADER...............................................................................................................................................3
5.0 PROGRAMMER FIRMWARE .....................................................................................................................4
5.1 FIRMWARE COMMANDS..................................................................................................................................4
5.2 S
CRIPTING ....................................................................................................................................................10
6.0 PC APPLICATION .......................................................................................................................................18
6.1 APPLICATION MENUS ...................................................................................................................................18
6.2 S
6.3 PC A
6.4 H
6.5 H
6.6 R
6.7 W
6.8 V
6.9 E
6.10 B
TATUS WINDOW .........................................................................................................................................20
PPLICATION STARTUP...........................................................................................................................20
EX FILE IMPORT .........................................................................................................................................21
EX FILE EXPORT.........................................................................................................................................21
EAD DEVICE...............................................................................................................................................21
RITE DEVICE .............................................................................................................................................22
ERIFY DEVICE ............................................................................................................................................23
RASE DEVICE..............................................................................................................................................23
LANK CHECK..............................................................................................................................................24
7.0 DEVICE FILE ...............................................................................................................................................30
7.1 FAMILY PARAMETERS ..................................................................................................................................31
7.2 P
7.3 S
ART PARAMETERS ......................................................................................................................................32
CRIPT DEFINITIONS.....................................................................................................................................36
Microchip Technology, Inc. PICkit 2 Interface Guide
Page 2 of 36
1.0 Introduction
This document covers design and theory of the PICkit 2 version 2 firmware and PC application software. Version 2 implements a script-based design to allow maximum flexibility for programming any type of device without requiring frequent, part-specific changes and updates. All part-specific information is kept in a device file, allowing new parts and families with new algorithms to be implemented without frequent changes to the software or firmware.
2.0 Guiding Design Goals
The guiding design goals of the version 2 firmware
1. Allow the firmware and software to be as generic as possible so adding new part & family support requires little to no changes.
2. Remain compatible with bootloader commands for the existing Pk2.
3. All device specific information should be kept in the device file.
4. The scripting and firmware should be flexible enough to allow other tasks besides programming to be accomplished, such as ICD.
3.0 Architecture Overview
The PICkit 2 is organized into 4 functional blocks.
1. Bootloader
2. Programmer Firmware
3. PC Application
4. Device File
The Bootloader is designed to be autonomous i.e. does not require programmer firmware for operation. The Programmer firmware, however, has its own USB stack, and does not rely on the bootloader for communication while running. This allows the USB stack used during normal execution to be updated over USB using the bootloader. The programmer firmware is largely a script execution engine, with basic commands for management of scripts and data. Data is program code, EE contents, and other information for which the programmer only acts as a conduit. The PC application is responsible for the user interface portion of the system. Its function is to respond to user requests by packaging data and scripts for execution by the firmware. The device file contains all scripts and descriptions of each part supported. It is divided into 3 main sections. The first is the family description section, which sets up some parameters common to all family members. The second is the part description section, with an entry for each part supported. This description references scripts contained in the third section, and defines membership in a family defined in section 1. The third section contains an indexed listing of all scripts used by the supported parts.
4.0 Bootloader
- TBD - .
Microchip Technology, Inc. PICkit 2 Interface Guide
Page 3 of 36
5.0 Programmer Firmware
The firmware consists largely of commands to store and retrieve data from 2 data buffers, and to store and execute scripts from an indexable script buffer. The names & uses of the buffers are:
Download Data Buffer
256 byte circular buffer. Stores data sent by the PC host for use by script commands. This is where code and data to be programmed by a script is stored. The write pointer is advanced by USB commands that write to the buffer, and the read pointer is advanced by scripts that use the data.
Upload Data Buffer
128 byte circular buffer. Data retrieved by a script is stored here to be read over USB by the PC host. Data and code read from a part by a script is stored here. The write pointer is advanced by scripts that place data into the buffer, and the read pointer is advanced by USB commands to retrieve the data.
Script Buffer
768 byte indexed buffer. This buffer stores up to 32 scripts of variable sizes up to 768 bytes total. The Script Index Table stores the beginning location and length of each script 1 through 32. Currently scripts are limited in length to 62 bytes as that is the longest script than can be sent via a DOWNLOAD_SCRIPT command in a 64-byte USB packet.
5.1 Firmware Commands
A command packet starts with the command byte and is followed by the command data bytes in order starting with data[1]. Response data bytes are returned via USB starting at data[1]. Any command not defined is treated as a “No Operation”.
Byte
ID
ENTER_BOOTLOADER
0x5A
0xA0
Microchip Technology, Inc. PICkit 2 Interface Guide
NO_OPERATION
FIRMWARE_VERSION
- Read firmware version
SETVDD
- Set Target VDD voltage VDDLim is error detection threshold voltage.
Command Name Data
Length
command: 0 Transfers operation to bootloader.0x42 response: 0 command: 0 Command processor skips and goes to next
response: 0 command: 00x76 response: 3 data[1] = Major version
command: 3 data[1] = CCPL
response: 0
Data Description
command byte.
data[2] = Minor version data[3] = Dot version
When received as the first byte in a USB packet, exits PK2GO mode.
data[2] = CCPH = [((Vdd * 32) + 10.5) << 6] data[3] = VDDLim = (Vfault / 5) * 255 typ. Vfault = 0.7*Vdd
data[3] is calibrated using the factors sent via SET_VOLTAGE_CALS (0xB0)
Page 4 of 36
0xA1
SETVPP
- Set Target VPP voltage VPPLim is error detection threshold voltage.
READ_STATUS
- Read status word. StatusHigh and StatusLow 7:4 are cleared after a read.
READ_VOLTAGES
- Read Vdd & Vpp voltages
command: 3 data[1] = CCPR2L = 0x40
data[2] = VPPADC = [Vpp * 18.61] data[3] = VPPLim = [Vfault * 18.61] typ. Vfault = 0.7*Vpp
data[2] & data[3] are calibrated using the
factors in response: 0 command: 00xA2 response: 2 data[1] = Status Low
<7> unused
<6> 1 = PICkit 2 button pressed
<5> 1 = VppError (Vpp < Vfault)
<4> 1 = VddError (Vdd < Vfault)
<3> 1 = Vpp On
<2> 1 = Vpp GND On
<1> 1 = Vdd On
<0> 1 = Vdd GND On
data[2] = Status High
<7> 1 = Download Buffer Overflow
<6> 1 = Script Buffer Overflow, invalid
Script length or index
<5> 1 = Run Script on Empty Script
<4> 1 = Script abort- download empty
<3> 1 = Script abort- upload full
<2> 1 = ICD transfer timeout/Bus Error
<1> 1 = UART Mode enabled
<0> 1 = PICkit 2 reset since last
Status Read.
NOTE: Turns BUSY_LED off. command: 00xA3 response: 4 data[1] = VDDADCLow
data[2] = VDDADCHigh
Vdd = (VDDADC / 65536) * 5 V
data[3] = VPPADCLow
data[4] = VPPADCHigh
Vpp = (VDDADC / 65536) * 13.7 V
SET_VOLTAGE_CALS (0xB0)
VDDADC and VPPADC value are calibrated
using the values in
SET_VOLTAGE_CALS (0xB0)
0xA4
0xA5
Microchip Technology, Inc. PICkit 2 Interface Guide
DOWNLOAD_SCRIPT
- Stores a script in the Script Buffer. Any existing script at The script# will be replaced.
RUN_SCRIPT*
- Runs a script from the Script
Buffer.
command: 2+N data[1] = Script # (0-31)
data[2] = Script Length N data[3] = Script byte 1 xxx
data[N+2] = Script byte N response: 0 command: 2 data[1] = Script # (0-31)
data[2] = Run 1 – 256 times
(0x00 = 256x, 0x01 = 1x, 0xFF = 255x) response: 0
Page 5 of 36
0xA6
hs of all loaded
0xA8
EXECUTE_SCRIPT*
- Executes the included script.
CLR_DOWNLOAD_BUFFER
- Empties the Download Buffer
DOWNLOAD_DATA
- Adds data to end of buffer
CLR_UPLOAD_BUFFER
- Empties the Upload Buffer
UPLOAD_DATA
- Read data from Upload Buffer
CLR_SCRIPT_BUFFER
- Empties the Script Buffer
UPLOAD_DATA_NOLEN
- Read data from Upload Buffer, no preceding length byte.
command: 1+N data[1] = Script Length N
data[2] = Script byte 1 xxx
data[N+1] = Script byte N response: 0 command: 00xA7 response: 0 command: 1+N data[1] = Data Length N
data[2] = Data byte 1
xxx
data[N+1] = Data byte N response: 0 command: 00xA9 response: 0 command: 00xAA response: 1+N data[1] = Data Length N
data[2] = Data byte 1
xxx
data[N+1] = Data byte N command: 00xAB response: 0 command: 00xAC response: N data[1] = Data byte 1
xxx
data[N] = Data byte N
0xAD
0xAE
END_OF_BUFFER
RESET
- Resets the PICkit 2
SCRIPT_BUFFER_CHKSM
- Read checksums of the script buffer
command: 0 Indicates end of commands in USB 64-byte
report buffer. response: 0 command: 0 Any other commands in the buffer after the
RESET will not be executed. response: 0 command: 00xAF response: 4 data[1] = LengthSumL
data[2] = LengthSumH
- 16-bit sum of the lengt
scripts data[3] = BufferSumL data[4] = BufferSumH
- 16-bit sum of all used bytes in script buffer
Microchip Technology, Inc. PICkit 2 Interface Guide
Page 6 of 36
0xB0
0xB1
0xB2
0xB3
0xB5
SET_VOLTAGE_CALS
- Sets the calibration factors for VDD setpoints and ADC conversions.
- Stored in internal EE and used on subsequent resets.
WR_INTERNAL_EE
- Writes data to internal EEPROM
RD_INTERNAL_EE
- Read data from internal EEPROM
ENTER_UART_MODE
- Puts the PICkit 2 into UART Mode.
- Scripts will not execute in UART Mode.
EXIT_UART_MODE
- Returns PICkit 2 to normal mode.
ENTER_LEARN_MODE
- Puts PICkit 2 into “Learn” mode, where commands, scripts, and data are stored in the external EEPROM.
command: 4 data[1] = adc_calfactorL
data[2] = adc_calfactorH CalibratedResult = (ADRES * adc_calfactor) >> 8 data[3] = vdd_offset (signed 2’s comp) data[4] = vdd_calfactor Calibrated CCP value = (((CCP >> 6) + vdd_offset) * vdd_calfactor) >>1
Default (uncalibrated) values: data[1] = 0x00, data[2] = 0x01, data[3] =
0x00, data[4] = 0x80, response: 0 command: 2 + N data[1] = Start Address
data[2] = Data Length N (Max N=32)
data[3] = Data byte 1
xxx
data[N+2] = Data byte N
First data byte written at Start Address.
Additional bytes are written at subsequent
addresses. response: 0 command: 1 data[1] = Start Address
data[2] = Data Length N (Max N=32)
First data byte read from Start Address.
Additional bytes are read at subsequent
addresses. response: N data[1] = Data byte 1
xxx
data[N] = Data byte N command: 2 data[1] = BaudValueL
data[2] = BaudValueH
BaudValue = 65536 – [((1/BAUD) – 3e-6) /
1.67e-7]
Where BAUD = 1200, 2400, etc to
maximum 57600. response: 0 command: 00xB4 response: 0
command: 4 data[1] = 0x50
data[2] = 0x4B
data[3] = 0x32
data[4] = 0 : 128K EEPROM
1 : 256K EEPROM
First 3 bytes are command “key” value to
prevent accidental mode entry. response: 0
Microchip Technology, Inc. PICkit 2 Interface Guide
Page 7 of 36
0xB7
samples to be taken after the trigger, minus 1.
EXIT_LEARN_MODE
- Returns PICkit 2 to normal mode.
ENABLE_PK2GO_MODE
- Returns PICkit 2 to normal mode.
command: 00xB6 response: 0
command: 2 data[1] = 0x50
data[2] = 0x4B data[3] = 0x32 data[4] = 0 : 128K EEPROM 1 : 256K EEPROM
0xB8
LOGIC_ANALYZER_GO
- Logic Analyzer function.
- NOTE: clears script buffer
First 3 bytes are command “key” value to prevent accidental mode entry. 4
th
what EEPROMs to use (2 x 24LC512 vs 2 x 24LC1025). PK2GO Mode is exited by the reception of a FIRMWARE_VERSION command in the
first byte of a USB packet. response: 0 command: 7 data[1] = 0 : Falling Edge Triggers
1 : Rising Edge Triggers
data[2] = TrigMask – ‘1’ bit for active Ch
data[3] = TrigStates – Edge bits 2
data[4] = EdgeMask – ‘1’ bit for edge Ch
data[5] = TrigCount ‘0’ = 256 counts
data[6] = PostTrigCountL
data[7] = PostTrigCountH
data[8] = SampleRateFactor
0 : 1 MHz
1 : 500 kHz
3 : 250 kHz
9 : 100 kHz
19 : 50 kHz
39 : 25 kHz
99 : 10 kHz
199 : 5 kHz
byte tells
nd
state
Microchip Technology, Inc. PICkit 2 Interface Guide
Mask/State bits:
Ch1 = bit 2
Ch2 = bit 3
Ch3 = bit 4
Unused Mask/State bits should be ‘0’
PostTrigCount is the number of extra
Min value is 1. Max is 65279 response: 2 data[1] = TrigLocL
data[2] = TrigLocH
bit 7 = 1 : trigger is in swapped sample
bit 6 = 1 : trigger is an abort
!! Add 1 to get the actual address !!
TrigLoc is an address 0x600 to 0x7FF. On
an abort, the address is invalid
Page 8 of 36
0xB9
LEARNING MODE META-COMMANDS
These commands are only valid in Learning Mode.
COPY_RAM_UPLOAD
- Copies 128 bytes of RAM to the Upload buffer starting at the given address.
0x80 READ_OSCCAL Command: 2 data[1] = OSCCAL Address Low
0x81 WRITE_OSCCAL Command: 2 data[1] = OSCCAL Address Low
0x82 START_CHECKSUM Command: 2 data[1] = Format
0x83 VERIFY_CHECKSUM Command: 2 data[1] = Checksum Low
command: 2 data[1] = StartAddressL
data[2] = StartAddressH
bits 15-12 of StartAddress are ignored.
response: 0
data[2] = OSCCAL Address High
Reads & stores the device OSCCAL value
data[2] = OSCCAL Address High
Writes the device OSCCAL value stored by READ_OSCCAL
data[2] = 0
Format = 0 for most devices = 1 for Baseline / Midrange flash = 2 for Baseline / Midrange EE
Begin calculating a checksum on the upload buffer.
data[2] = Checksum High
Compares calculated checksum against included checksum.
0x84 CHECK_DEVICE_ID Command: 2 data[1] = DeviceIDMaskL
data[2] = DeviceIDMaskH data[3] = DeviceIDValueL data[4] = DeviceIDValueH
Checks that the target Device ID matches the
argument value. 0x85 READ_BANDGAP Command: 0 Reads the bandgap of 12F629 family devices 0x86 WRITE_CFG_BANDGAP Command: 0 Writes the Config word of 12F629 family
devices with the read badgap value. 0x87 CHANGE_CHKSM_FRMT Command: 2 data[1] = Format
data[2] = 0
Format = 0 for most devices
= 1 for Baseline / Midrange flash
= 2 for Baseline / Midrange EE
* If a script attempts to use data from the download buffer and it is empty, the script will abort and generate a status error. If a script attempts to place data in the upload buffer and it is full, the script will abort and generate a status error.
Microchip Technology, Inc. PICkit 2 Interface Guide
Page 9 of 36
5.1.1 Command USB Responses
Each command that provides a response will generate a separate USB read packet with only the data from that command. Each packet is set up as a blocking USB read. Thus, multiple commands may be stacked into a single USB Write packet, but a seperate USB read must be completed to retrieve the result for each command that returns a response. The response packets will be read in the order in which the commands appear in the Write packet. Results from multiple commands in a single Write packet are not appended to a single Read packet. This allows data to immediately available from a command after it has executed, without waiting for the entire USB Write packet to be processed. Data can be read as it is available even if a script with a long execution time (such as bulk erase) appears later in the command list.
5.1.2 UART Mode
UART Mode allows the PICkit 2 to be used as a simple UART. ICSPCLK = TX (data transmitted from the PICkit 2) ICSPDAT = RX (data received from target UART)
Signal levels are inverted (ie Start Bit = GND) logic level signals between GND and VDD.
A bit in the high status byte returned by the READ_STATUS command allows determination if the PICkit 2 is in UART Mode or not.
Restrictions: VPP will be shut off when UART mode is entered.
Scripts will not be run in UART mode if script commands are received.
The PICkit 2 VDD pin needs to be connected to the target VDD so the ICSP signals are clamped to the proper voltage, regardless of whether PICkit 2 is powering the target or not.
In UART mode, any data written to the Download Data Buffer will be transmitted on the TX pin at the specified baud rate.
Any received data on the RX pin will be placed in the Upload Data Buffer. The PC host should poll the buffer for data using the UPLOAD_DATA command. The Length byte in the response packet allows determination if any data was received. Note that the Upload Data Buffer may be overrun if the host does not keep up with the received data rate. Overflow data will be lost.
Data Buffers should be cleared before putting the unit in UART Mode
The BUSY LED acts as an activity light (for both RX and TX).
Baud rates faster than 38400 may not work reliably.
5.1.3 Unit IDs
A PICkit 2 unit may be assigned a unique Unit ID string of up to 15 characters. This string is stored in 16 bytes of internal EEPROM on the PICkit 2 PIC18F2550. A value string is always preceded by the char byte ‘#’ to indicate a valid string. If this first byte is not ‘#’, the Unit ID is assumed to be blank. Starting with PICkit 2 Firmware v2.32.00, the Unit ID is returned in the PICkit 2USB Descriptor for Serial Number String. This allows the Unit ID to be read from the USB descriptors without sending any HID commands, so software may detect and list all attached PICkit 2 units without risking corrupting any current communications with a PICkit 2 unit if it were to send HID commands.
Microchip Technology, Inc. PICkit 2 Interface Guide
Page 10 of 36
5.2 Scripting
Execution of a script will abort on the following conditions:
- Script is attempting to use bytes from the Download Data Buffer and the buffer is empty.
- Script is attempting to store bytes in the Upload Data Buffer, and the buffer is full.
- ICD Timeout or BusError bit is set.
RUN_SCRIPT and EXECUTE_SCRIPT commands will be ignored when any of StatusHigh bits 7:1 are set (i.e. a script error exists) until the error is acknowledge and cleared by a READ_STATUS command.
Some script control bytes require arguments. Argument bytes follow the control byte directly, in the order given in the table. All undefined byte values will be interpreted as “no operation.”
ID Control Byte Arguments Description.
0xFF VDD_ON - Turns on VDD PFET pass transistor. 0xFE VDD_OFF - Turns off VDD PFET pass transistor. 0xFD VDD_GND_ON - Turns on VDD NFET ground. 0xFC VDD_GND_OFF - Turns off VDD NFET ground. 0xFB VPP_ON - Turns on VPP PNP pass transistor. 0xFA VPP_OFF - Turns off VPP PNP pass transistor. 0xF9 VPP_PWM_ON - Start up VPP PWM. Allow 100ms to
come up to voltage.
0xF8 VPP_PWM_OFF - Shut down VPP PWM. Q4 is off
(VPP_PUMP low). 0xF7 MCLR_GND_ON - Turns on VPP NPN ground. 0xF6 MCLR_GND_OFF - Turns off VPP NPN ground. 0xF5 BUSY_LED_ON - Turns on BUSY LED 0xF4 BUSY_LED_OFF - Turns off BUSY LED 0xF3 SET_ICSP_PINS arg[1] = pin states
<7 – 4> unused <3> PGD logic level <2> PGC logic level <1> 1= PGD input, 0= output <0> 1= PGC input, 0= output
0xF2 WRITE_BYTE_LITERAL arg[1] = Byte to be sent Clocks out the following byte on PGC,
0xF1 WRITE_BYTE_BUFFER - Clocks out the next byte from the
0xF0 READ_BYTE_BUFFER - Clocks in a byte of data and stores it in
Sets the logic level and direction of the
ICSP pins. The logic level is always set
first, before the direction takes effect.
PGD. Byte is shifted LSB first.
PGD and PGC must be set to outputs
before calling.
Downstream Data Buffer and advances
the read pointer. Byte is shifted LSB
first. **
PGD and PGC must be set to outputs
before calling.
the Upstream Data Buffer, advancing
the write pointer. Byte is shifted in LSB
first. **
PGC must be set to output. PGD is
automatically set an input, and restored
to previous state after read.
Microchip Technology, Inc. PICkit 2 Interface Guide
Page 11 of 36
Loading...
+ 25 hidden pages