GS003 In-Circuit Debugging Interface Options with dsPIC DSC Author: Hrushikesh (Rishi) Vasuki Microchip Technology INTRODUCTION This document describes useful options that facilitate in-circuit debugging of dsPIC30F embedded application programs. MULTIPLE DEBUGGING CHANNELS dsPIC30F Digital Signal Controllers use Microchip's low-cost development tool, MPLAB(R) ICD 2 In-Circuit Debugger for both programming and in-circuit debugging. MPLAB ICD 2 provides a 5-pin interface to the dsPIC30F device. These pins are: VDD, VSS, MCLR, PGC/EMUC and PGD/EMUD. The PGC/EMUC and PGD/EMUD pins are used to communicate clock and data signals, respectively, between the MPLAB ICD 2 unit and the dsPIC30F device during programming and debugging operations. To give you flexibility in board layout, dsPIC30F DSC devices provide multiple options for connecting the MPLAB ICD 2 to your target board for in-circuit debugging. dsPIC30F devices are available in packages ranging from 18 to 80 pins. Devices in small packages often have several peripheral functions multiplexed on each pin (see Figure 1). In certain cases, the default programming and debugging pin functions, PGC/ EMUC and PGD/EMUD, are multiplexed on pins that may be used by other peripherals like the I2CTM, SPITM, or UART modules. In such cases, the application is able to use these pins for programming, however they cannot be used for in-circuit debugging. In-circuit debugging should then be performed using alternate debugging channels, as listed in Table 1. You should note that the device programming and connect operations using MPLAB ICD 2 will continue to require the use of the PGC and PGD pins. (c) 2005 Microchip Technology Inc. TABLE 1: DEBUGGING CHANNELS Pin Name Pin Function EMUD EMUC Default Debug Data pin Default Debug Clock pin EMUD1 EMUC1 Alternate Debug Channel #1 Data pin Alternate Debug Channel #1 Clock pin EMUD2 EMUC2 Alternate Debug Channel #2 Data pin Alternate Debug Channel #2 Clock pin EMUD3 EMUC3 Alternate Debug Channel #3 Data pin Alternate Debug Channel #3 Clock pin FIGURE 1: TYPICAL ALTERNATE DEBUGGING CHANNEL To I2CTM Device ICD 2 Header dsPIC30F3012 Switch Debug 12 PGC 11 PGD PGC/EMUC/SDA* PGD/EMUD/SCL* Program 2 3 14 13 1 VDD VSS VPP EMUD3* EMUC3* VDD VSS MCLR * Pin Multiplexing on dsPIC30F3012 (PDIP Package): Pin Multiplexed Functions 2 EMUD3/AN0/VREF+/CN2/RB0 3 EMUC3/AN1/VREF-/CN3/RB1 11 PGD/EMUD/AN6/U1TX/SDO1/SCL/CN6/RB4 12 PGC/EMUC/AN5/U1RX/SDI1/SDA/CN7/RB5 DS93003A-page 1 GS003 DESIGN PROCEDURE 4. To make use of these alternate debugging channels, a few steps need to be taken: 1. Before you lay out your circuit board, decide whether you will need to use alternate debugging channels. For instance, assume that an application running on a dsPIC30F3012 requires the SDA and SCL pin functions to communicate via the I2C protocol with other components on the board. On the dsPIC30F3012 device, the SCL and SDA pins (11 and 12) are multiplexed with the default in-circuit debugging pins, EMUD and EMUC, respectively. So, this application requires an alternate in-circuit debugging channel. 2. Select the alternate debugging channel to use from EMUC1/EMUD1, EMUC2/EMUD2 or EMUC3/EMUD3. For the hypothetical application, assume that pins 2 and 3 on the dsPIC30F3012 are available for use during in-circuit debugging operations. Thus, you would use EMUC3 and EMUD3 as the alternate in-circuit debugging channel for this application. 3. 5. 6. 7. Before downloading code (programming) into the target device, you'll need to set the configuration bits dialog in MPLAB IDE to accurately reflect the selected in-circuit debugging channel. MPLAB IDE, by default, uses the PGC/ EMUC and PGD/EMUD pins for programming and debugging. For the hypothetical application you'll set the "COMM CHANNEL SELECT" option to "Use EMUC3 and EMUD3", as shown in Figure 2. The configuration bits dialog is invoked by selecting the Configure>Configuration Bits menu in MPLAB IDE. During a programming or connect operation (with MPLAB ICD 2 selected as a Debugger), the switch (or jumper) should be positioned so that the MPLAB ICD 2 unit communicates with the target dsPIC30F device via PGC and PGD (pins 12 and 11, respectively). When programming is complete, the switch (or jumper) should be positioned so that the MPLAB ICD 2 unit communicates with the target dsPIC30F device via EMUC3 and EMUD3 (pins 3 and 2, respectively). You are now ready to perform in-circuit debugging operations using such functions as Reset, Run, Single-step, Halt, Set Breakpoint, etc. While designing your board, provide a connection between the PGC and PGD pins on the MPLAB ICD 2 unit and the selected alternate debugging channel, EMUC3 and EMUD3, as shown by the switch in Figure 1. FIGURE 2: DS93003A-page 2 EXAMPLE MPLAB(R) IDE CONFIGURATION BITS DIALOG (c) 2005 Microchip Technology Inc. GS003 MPLAB ICD 2 ERROR HANDLING If any of the steps detailed in this document were not performed, MPLAB IDE may display an error message such as shown in Figure 3. FIGURE 3: This error message is displayed because MPLAB ICD 2 is not able to communicate with the Debug Executive running on the dsPIC(R) DSC. This communication failure occurs because the Debug Executive expects to communicate with MPLAB ICD 2 on a channel (for example EMUC3 and EMUD3) different from the board configuration (for example EMUC and EMUD). EXAMPLE DEBUGGING ERROR ON INCORRECT CONFIGURATION Programming Target... ...Validating configuration fields ...Erasing Part ...Programming Programming Executive ...Verifying Programming Executive ...Programming Program Memory (0x0 - 0x53F) Verifying... ...Program Memory ...Verify Succeeded ...Loading DebugExecutive ...Programming DebugExecutive ...Debug Executive Error message displays if the ...Programming Debug Vector ...Debug Vector dsPIC30F device is not properly configured for debugging. ...Programming Configuration Bits .. Config Memory Verifying configuration memory... Connecting to debug executive ICD0083: Target not in debug mode, unable to perform operation MPLAB ICD 2 Ready (c) 2005 Microchip Technology Inc. DS93003A-page 3 GS003 SUMMARY This document described how alternate debugging channels (EMUCx & EMUDx pins) can be used for incircuit debugging when the default debugging channel (EMUC & EMUD pins) is in use by the application and, hence, rendered unavailable for use by MPLAB ICD 2. Several dsPIC30F Development Boards, including dsPICDEMTM MC1 and dsPICDEM 2, include jumpers or switches that allow you to select alternate debugging channels. For circuit details, see the schematics included in the User's Guides for these Development Boards (dsPICDEMTM 1.1 Development Board User's Guide (DS70099) and dsPICDEMTM 2 Development Board User's Guide (DS51558)). DS93003A-page 4 (c) 2005 Microchip Technology Inc.