Gather the necessary hardware
You will need the following hardware tools to follow the example exercise:
- Target Device and Demo Board
- Debugger / Programmer
Gather and install the software
- Install the USB driver for your OS (Windows/Linux/OS X) by downloading and installing the SEGGER Utility/Documentation/Driver package.
- Install MPLAB® X IDE and the MPLAB® XC32 compiler. If you already have MPLAB® X IDE installed, please note that it must be v2.15 or newer to support the J-Link.
- Install the MPLAB® X plugin for J-Link.
- Follow the instructions in the "Hands-on Exercises Files" section of the Downloads link to download the exercise and move it to the appropriate location.
Connect the hardware
- The MPLAB® X IDE plugin does not support the option of powering the target through the J-LINK. For this example you must provide an external power supply.
- If you are using the 2-wire connection, simply connect the J-Link through the Microchip adapter to the Explorer16 with the RJ11 cable. The example project defaults to 2-wire, so if you are doing this for the first time, this would be the best place to start.
- If you are using the 4-wire connection, please see the figure below which illustrates the orientation of the ribbon cable. Unfortunately due to the orientation of the connectors, there is no configuration that avoids the convoluted arrangement of the ribbon cable.
The MPLAB® X plugin does not presently support the full range of functions available for the J-Link Debug Probe. For advanced options, such as supplying external power or erasing a device, you must invoke the J-Link Commander command line utility which was installed when you installed the SEGGER Utility/Documentation/Driver package. Capabilities and operation of the J-Link Commander are treated in a separate article.
Open and Configure the Project
- Open the project. Note that if you open the project before installing the plugin, the project development tool will silently default to the MPSIM simulator.
- Configure the project for the PIC32 you are using. The project default is PIC32MX360F512L.
- Configure the project for 2-wire or 4-wire communication depending upon which connection you are using. You can find more details here. The project default is 2-wire.
If you are using 4-wire communication, please note that you must enable the JTAG port. Also, the JTAG interface shares several of the pins connected to the LED's on PORTA. The example code below uses only those port pins that do not conflict with 4-wire JTAG. It also takes advantage of a macro provided through plib to enable the JTAG port.
Build and Program the Project
Click on the Make and Program Device icon. If all goes well, you should see the following dialog boxes. If not, check the Troubleshooting section below.
Confirm that LEDs are blinking.
- Four of the LEDs (7,6,3,2) on the Explorer16 will blink once the board has been programmed. Four of the LEDs (5,4,1,0) are connected to the same ports as the JTAG pins, so they will not blink.
- Error code -142, Operation failed means that the J-Link is connected, but the wrong JTAG communication has been selected.
- Error code -259, Unrecognized error means:
- no PIC32 is connected
- the connector is backwards
- external power is not applied to the target board
- Error message: MPLAB® X has detected that your SEGGER JLinkARM.dll version is too old… means that you are using a version of MPLAB® X IDE that is earlier than v2.15.
- Message Connecting to J-Link Probe… followed by apparent hang of the system.
- Message Could not connect to tool hardware: seggerjlink, com.microchip.mplab.modules.seggerjlink.SeggerJLinkToolHandler The debugger could not be started. Terminating debug session.
These and similar messages mean that USB interface to the J-Link has timed out or been otherwise interrupted. To re-establish connection follow these steps:
- Unplug the J-Link from the USB host.
- Wait for 30 seconds to ensure it has been fully unloaded by the OS (this step is critical!).
- Plug it back into the USB host.