Debug and trace

Debug and trace system offers a flexible and powerful mechanism for non-intrusive debugging.

Figure 1. Overview
Overview

The main features of the debug and trace system are:
  • Two-pin serial wire debug (SWD) interface
  • Flash patch and breakpoint (FPB) unit supports:
    • Two literal comparators
    • Six instruction comparators
  • Data watchpoint and trace (DWT) unit
    • Four comparators
  • Instrumentation trace macrocell (ITM)
  • Embedded trace macrocell (ETM)
  • Trace port interface unit (TPIU)
    • 4-bit parallel trace of ITM and ETM trace data
    • Serial wire output (SWO) trace of ITM data

DAP - Debug access port

An external debugger can access the device via the DAP.

The debug access port (DAP) implements a standard ARM® CoreSight™ serial wire debug port (SW-DP), which again implements the serial wire debug protocol (SWD). SWD is a two-pin serial interface, see SWDCLK and SWDIO in #debugandtrace__fig.

In addition to the default access port in CPU (AHB-AP), the DAP includes a custom control access port (CTRL-AP). The CTRL-AP is described in more detail in CTRL-AP - Control access port.

Note:
  • The SWDIO line has an internal pull-up resistor.
  • The SWDCLK line has an internal pull-down resistor.

CTRL-AP - Control access port

The control access port (CTRL-AP) is a custom access port that enables control of the device when other access ports in the DAP are disabled by the access port protection.

Access port protection blocks the debugger from read and write access to all CPU registers and memory-mapped addresses. See the UICR register APPROTECT for more information on enabling access port protection.

Control access port has the following features:

  • Soft reset, see Reset for more information
  • Disabling of access port protection, which is the reason why CTRL-AP allows control of the device even when all other access ports in the DAP are disabled by the access port protection

Access port protection is disabled by issuing an ERASEALL command via CTRL-AP. This command will erase the flash, UICR, and RAM.

Registers

Table 1. Register overview
Register Offset Description
RESET 0x000

Soft reset triggered through CTRL-AP

 
ERASEALL 0x004

Erase all

 
ERASEALLSTATUS 0x008

Status register for the ERASEALL operation

 
APPROTECTSTATUS 0x00C

Status register for access port protection

 
IDR 0x0FC

CTRL-AP identification register, IDR

 

RESET

Address offset: 0x000

Soft reset triggered through CTRL-AP

Bit number 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ID                                                               A
Reset 0x00000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ID RW Field Value ID Value Description
A RW

RESET

   

Soft reset triggered through CTRL-AP. See Reset behavior in POWER chapter for more details.

     

NoReset

0

Reset is not active

     

Reset

1

Reset is active. Device is held in reset.

ERASEALL

Address offset: 0x004

Erase all

Bit number 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ID                                                               A
Reset 0x00000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ID RW Field Value ID Value Description
A W

ERASEALL

   

Erase all flash and RAM

     

NoOperation

0

No operation

     

Erase

1

Erase all flash and RAM

ERASEALLSTATUS

Address offset: 0x008

Status register for the ERASEALL operation

Bit number 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ID                                                               A
Reset 0x00000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ID RW Field Value ID Value Description
A R

ERASEALLSTATUS

   

Status register for the ERASEALL operation

     

Ready

0

ERASEALL is ready

     

Busy

1

ERASEALL is busy (on-going)

APPROTECTSTATUS

Address offset: 0x00C

Status register for access port protection

Bit number 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ID                                                               A
Reset 0x00000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ID RW Field Value ID Value Description
A R

APPROTECTSTATUS

   

Status register for access port protection

     

Enabled

0

Access port protection enabled

     

Disabled

1

Access port protection not enabled

IDR

Address offset: 0x0FC

CTRL-AP identification register, IDR

Bit number 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ID E E E E D D D D C C C C C C C B B B B           A A A A A A A A
Reset 0x02880000 0 0 0 0 0 0 1 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ID RW Field Value ID Value Description
A R

APID

   

AP identification

B R

CLASS

   

Access port (AP) class

     

NotDefined

0x0

No defined class

     

MEMAP

0x8

Memory access port

C R

JEP106ID

   

JEDEC JEP106 identity code

D R

JEP106CONT

   

JEDEC JEP106 continuation code

E R

REVISION

   

Revision

Electrical specification

Control access port

Symbol Description Min. Typ. Max. Units
Rpull

Internal SWDIO and SWDCLK pull up/down resistance

13
fSWDCLK

SWDCLK frequency

0.125 8 MHz

Debug interface mode

Before an external debugger can access either CPU's access port (AHB-AP) or the control access port (CTRL-AP), the debugger must first request the device to power up via CxxxPWRUPREQ in the SWJ-DP.

If the device is in System OFF when power is requested via CxxxPWRUPREQ, the system will wake up and the DIF flag in RESETREAS will be set. The device is in the debug interface mode as long as the debugger is requesting power via CxxxPWRUPREQ. Once the debugger stops requesting power via CxxxPWRUPREQ, the device is back in normal mode. Some peripherals behave differently in debug interface mode compared to normal mode. These differences are described in more detail in the chapters of the peripherals that are affected.

When a debug session is over, the external debugger must make sure to put the device back into normal mode since the overall power consumption is higher in debug interface mode than in normal mode.

For details on how to use the debug capabilities, read the debug documentation of your IDE.

Real-time debug

The nRF52840 supports real-time debugging.

Real-time debugging allows interrupts to execute to completion in real time when breakpoints are set in thread mode or lower priority interrupts. This enables developers to set breakpoints and single-step through the code without the risk of real-time event-driven threads running at higher priority failing. For example, this enables the device to continue to service the high-priority interrupts of an external controller or sensor without failure or loss of state synchronization while the developer steps through code in a low-priority thread.

Trace

The device supports ETM and ITM trace.

Trace data from the ETM and the ITM is sent to an external debugger via a 4-bit wide parallel trace port interface unit (TPIU), see TRACEDATA[0] through TRACEDATA[3] and TRACECLK in #debugandtrace__fig.

In addition to parallel trace, the TPIU supports serial trace via the serial wire output (SWO) trace protocol. Parallel and serial trace cannot be used at the same time. ETM trace is only supported in parallel trace mode, while ITM trace is supported in both parallel and serial trace modes.

For details on how to use the trace capabilities, read the debug documentation of your IDE.

TPIU's trace pins are multiplexed with GPIOs, and SWO and TRACEDATA[0] use the same GPIO, see Pin assignments for more information.

Trace speed is configured in the TRACECONFIG register. The speed of the trace pins depends on the DRIVE setting of the GPIOs that the trace pins are multiplexed with. Only S0S1 and H0H1 drives are suitable for debugging. S0S1 is the default DRIVE at reset. If parallel or serial trace port signals are not fast enough in the debugging conditions, all GPIOs in use for tracing should be set to high drive (H0H1). The user shall make sure that DRIVE setting for these GPIOs is not overwritten by software during the debugging session.

Electrical specification

Trace port

Symbol Description Min. Typ. Max. Units
Tcyc

Clock period, as defined by ARM (See Embedded Trace Macrocell Architecture Specification->Trace Port Physical Interface->Timing specifications on ARM Information Center)

62.5 500 ns

Documentation feedback | Developer Zone | Updated 2018-03-22