Debug

Hardware auto-detect whether the debugger adapter is JTAG or SWD, but if debugger is SWD, the pin used by JTAG (but not used in SWD mode) cannot be configured as general purpose I/O. If there is such requirement to configure those pin as GPIO, it is needed to disable jtag at first. Please refer to detail in chapter 5.3.

SWD and JTAG selection algorithm

To switch SWJ-DP from JTAG to SWD operation, debugger host send the following sequence:
1. Send more than 50 SWCLKTCK cycles with SWDIOTMS=1 to ensure that both SWD and JTAG are in their reset states.
2. Send the 16-bit JTAG-to-SWD select sequence 0b0011110011100111(MSB first) on SWDIOTMS.
3. Send more than 50 SWCLKTCK cycles with SWDIOTMS=1.

Disable JTAG

It is able to call sys_jtag_off() to turn of jtag. For system security consideration, turn on jtag is not supported.

Share SWD/JTAG with GPIO

Some UART/I2C/I2S/SPI may map to the same pin with SWD/JTAG, and to share the same pin, the following procedure can be considered.

  • System boot up with JTAG on by default.
  • The code jump to main function.
  • Use one external GPIO to check whether JTAG will to be disabled or not. If JTAG is to be disabled, (system is in application mode), then disable jtag and configure the pin mux. Otherwise, if JTAG is not to be disabled (system is running on debugger mode), then do not disable jtag.
  • Peripheral example example_sources\gpio_jtag\ demonstrates the scenarios.