A Bit of Debugging

If you want to use a development tool such as the MPLAB® REAL ICE In-circuit emulator or ICD as a debugger, two things need to happen. First, your compiler needs to be told to reserve the device resources used by the debug executive (code which will execute alongside your program and which will communicate with the debugger), and second, the debug executive needs to be enabled.

When you start a debug session in MPLAB X IDE, as described in "Starting and Stopping A Debug Session", it does both of these things. The IDE passes the appropriate options to the compiler so that it will reserve the required memory locations, and it will also program the appropriate configuration bit in the device to enable background debugging. Neither of these things happen for production builds.

Some devices allow you to program the background debug configuration bit in your program. If so, the config pragma setting might be called DEBUG or BKBUG. However, even if this setting is defined, you should not manually set or clear this bit in your code, even though you typically should specify the settings for all the other configuration bits. Having the IDE control this bit means that you do not need to manually change it as you perform different builds, and it can't be accidentally left in the wrong state.

The bits you might need to program if you are using a 16- or 32-bit PIC device are the JTAG enable bit (called JTAGEN), which turns on debugging facilities that use the JTAG standard, and the communication channel select bits (called either ICS or ICESEL) which specify the device channel (hence the device pins) used by an in-circuit debugger to exchange information between the debugger and the device.

See your device datasheet for more detailed information regarding the purpose of each configuration bit, and open the relevant device HTML file to determine the configuration bit names and allowable values that you can use in your program. These files are called pic_chipinfo.html, pic18_chipinfo.html, config_index.html, and PIC32ConfigSet.html, all in your compiler’s docs directory. Select your target device from those shown when you open the file in your favourite web browser.

© 2023 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
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.