How can I disable/enable JTAG at runtime on the PIC32MZ?
Although the JTAG Port Enable bit (JTAGEN) is located in the Device Configuration Registers, modifying this bit via Run-Time Self-Programming (RTSP) is not recommended.
You can only successfully modify configuration registers on PIC32MZ devices while in RUN mode, not in DEBUG mode. However, this may generate an ECC fault and cause the device to boot from the alternate configuration words rather than the primary (this is a security measure).
A better approach to disable/enable the JTAGEN bit during runtime:
- Enable JTAG in the Device Configuration Register
- Enable or disable JTAG during runtime by writing the JTAGEN in the Configuration Contol register (CFGCON)
- 1 = Enable the JTAG port
- 0 = Disable the JTAG port
Unlike the flash-based Device Configuration Registers, CFGCON is a normal, SRAM-based Special Function Register (SFR).