PIC32 debug

“The target device is not ready for debugging. Please check your configuration bit settings and program the device before proceeding.”

The solution:

#pragma config ICESEL = ICS_PGx1
It could also be ICS_PGx2, depending on your device.
Using the ethernet feature? Be sure to find if it is standard or alternate.

For alternate use this configuration bits:

#pragma config FMIIEN = OFF // OFF for RMII
#pragma config FETHIO = OFF //On default | OFF alternate

This was tested on PIC32MX795