A Simple Programming Example

Programming Tutorial

1

Gather the necessary hardware

You will need the following hardware tools to follow the example exercise:

PC-Segger-Explorer16.jpg

2

Gather and install the software

  1. Install the USB driver for your OS (Windows/Linux/OS X) by downloading and installing the SEGGER Utility/Documentation/Driver package.
  2. 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.
  3. Install the MPLAB® X plugin for J-Link.
  4. 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.

3

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.
segger.png

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.

4

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.
OpenProject.png
  • Configure the project for the PIC32 you are using. The project default is PIC32MX360F512L.
JINKConfiguration.png
  • 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.
JTAGcomm.png

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.

Blink32-src.png

5

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.

JLINKbuild1.png
JLINKbuild2.png

6

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.

Troubleshooting

Error Codes


  • 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 Messages


  • 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:

  1. Unplug the J-Link from the USB host.
  2. Wait for 30 seconds to ensure it has been fully unloaded by the OS (this step is critical!).
  3. Plug it back into the USB host.

20th Annual
Microchip MASTERs Conference 2016
Register now - Deadline: July 29

JW Marriott Desert Ridge Resort-Phoenix, AZ

© 2016 Microchip Technology, Inc.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.