4.2 AT Devices - On-Chip Debugging (OCD)
An on-chip debug module is a system allowing a developer to monitor and control the execution on a device from an external development platform, usually through a device known as a debugger or debug adapter.
With an OCD system, the application can be executed whilst maintaining exact electrical and timing characteristics in the target system, and while being able to stop execution conditionally or manually and inspect program flow and memory.
Run Mode
When in Run mode, the execution of code is completely independent of the MPLAB ICE 4. The MPLAB ICE 4 will continuously monitor the target device to see if a break condition has occurred. When this happens, the OCD system will interrogate the device through its debug interface, allowing the user to view the internal state of the device.
Stopped Mode
When a breakpoint is reached, the program execution is halted, but some I/O may continue to run as if no breakpoint had occurred. For example, assume that a USART transmit has just been initiated when a breakpoint is reached. In this case, the USART continues to run at full speed, completing the transmission, even though the core is in Stopped mode.
Hardware Breakpoints
The target OCD module contains several Program Counter comparators implemented in the hardware. When the Program Counter matches the value stored in one of the comparator registers, the OCD enters Stopped mode. Since hardware breakpoints require dedicated hardware on the OCD module, the number of breakpoints available depends upon the size of the OCD module implemented on the target. Usually, one such hardware comparator is ‘reserved’ by the debugger for internal use.
Software Breakpoints
A software breakpoint is a BREAK
instruction placed in
the program memory on the target device. When this instruction is loaded, program
execution will break, and the OCD enters Stopped mode. To continue execution a
“start” command has to be given from OCD. Not all Microchip devices have OCD modules
supporting the BREAK
instruction.