PROGRAMMING MICROCONTROLLERS: AN OVERVIEW

Programming Microcontrollers: An Overview

Article by:
Date Published:
Last Modified:
WarningThis page is in notes format, and may not be of the same quality as other pages on this site.

1. Interfaces

ARM DSTREAM?

1.1. JTAG

JTAG is a standard defining connections and protocols for testing/verifying PCBs and the devices on them. It is named after the Joint Test Action Group which defined the standard. It is formally codified in 1990 by IEEE in the standard IEEE 1149.1-1990[7]. ICs supporting JTAG expose a Test Access Port (TAP) which the JTAG device connects to, allowing bi-directional serial data transfer. JTAG requires 4 signal lines (ignoring the rarely seen 2-signal variant).

Although JTAG was initially designed for board-level testing and verification to address common soldering faults in the 1980’s, it has evolved and is now most commonly used today as an in-circuit programming/debug protocol for microcontrollers, microprocessors, FPGAs, and other similar programmable ICs.

JTAG allows the following:

  • Processing halting

  • Single-stepping

  • Writing to non-volatile memory (programming)

Table 1. JTAG pin functions.
NameI/O (w.r.t. programmer)Description

TCK

Output

The Test Clock pin is driven by the programmer and provides a clock for the data on the other pins.

TDI

Output

The Test Data In pin is driven by the programmer and provides serial data to the target during programming/debugging.

TDO

Input

The Test Data Output pin is driven by the target device and provides serial data to the programmer during programming/debugging.

TMS

Output

The Test Mode Select pin is used to set the state of the Test Access Port controller.

nTRST

Output

The "Tap Reset" pin is driven active low to reset the target device. Typically pulled high on the target board. Sometimes just called TRST, although always active low.

A 2-wire (excluding GND) "reduced pin count JTAG" is specified in IEEE 1149.7[7]. The two wires that are used are TMSC (test serial data) and TCKC (test clock). This 2-wire variant is not common.

CoreSight is an collection of technologies to allow for the debugging of ARM based SoCs. It includes systems built on JTAG for debugging.

RTCK (return clock) is a signal created to use be able to use synchronized TAP controllers in ARM9 and ARM11 cores. It is an output of the target system back to the JTAG adapter and is used for synchronization purposes. The RTCK is usually driven by the last flip-flop in the synchronization chain on the target device. The adapter will not change TCK until it gets back a signal on RTCK, this process is called adaptive clocking[8].

1.2. SWD

SWD (Single Wire Debug) is a two-wire programming/debugging interface for programmable ICs such as microcontrollers. It is a popular alternative to JTAG. It is formally specified in the ARM Debug Interface v5.

Table 2. SWD wire functions.
NameI/O (w.r.t. programmer)Description

SWCLK

Output

Clock output to target device. Frequency selection is up to the host to decide, up to about 60MHz in practice[9].

SWDIO

Bi-directional

Synchronous bi-directional data.

Whilst officially just a 2-wire interface, it is commonly bundled with 1-2 other signals.

Table 3. Additional SWD wire functions.
NameI/O (w.r.t. programmer)Description

VTREG

Input

Target \(V_{CC}\) voltage so the adapter knows what counts as a logical 1 and 0 on the other wires.

SWO

Input

nRST

Output

Used to reset the target device. Active low logic.

SWCLK, SWDIO and SWO should be pulled high by approx. \(10k\Omega\) so that they remain in a stable state when not driven[10].

SWD uses a bus called DAP (Debug Access Port). On this bus there is one master, the DP (Debug Port, typically a USB dongle when programming microcontrollers), and one or more slaves called APs (Access Ports). There are three different Debug Ports[9]:

  1. JTAG Debug Port (JTAG-DP): Uses the standard JTAG interface.

  2. Serial Wire Debug Port (SW-DP): Uses the SWD protocol.

  3. Serial Wire / JTAG Debug Port (SWJ-DP): A combination of the previous two, this port can either use SWD or JTAG to access the DAP bus. The TCK and TMS JTAG signals are re-used for the SWD SWCLK and SWDIO signals.

ARM specifies the following two Access Ports:

  1. Memory Access Port (MEM-AP): Provides access to core memory and registers.

  2. JTAG Access Port (JTAG-AP): Provides access to a JTAG chain from the DAP.

WarningNot all microcontrollers connect SWCLK/SWDIO up to the main VDD voltage domain. For example, in STM32F07x/04x devices, the SWCLK and SWDIO pins are supplied by the VDDIO2 domain, so make sure to connect the right pins up to VTREG.

1.3. SWV

Serial Wire Viewer (SWV) is the protocol used by the SWO pin on the SWD connector[11]. It is only available for ARM Cortex-M3 cores and higher, it is NOT available on Cortex M0 or M0+ cores.

32 available ITM stimulus ports. ARM recommends[11]:

  • Port 0 is used for text data (e.g. data from printf())

  • Port 31 is used for RTOS event data

  • All other channels are up to the user to decide.

SWV can give you printf() style debugging output, in where the printf() function calls the CMSIS ITM_SendChar() function.

1.4. ETM

4-bit.

1.5. Semihosting

Semihosting is an ARM feature which allows an ARM-based target to communicate with and use the input/output (IO) facilities on the host computer which is running a debugger[13]. Semihosting is commonly used to send printf() calls on the target to the host, and be displayed whilst debugging through a terminal on the host.

NoteARM processors prior to ARMv7 use the SVC instructions, formerly known as SWI instructions, to make semihosting calls. However, if you are compiling for an ARMv6-M or ARMv7-M, for example a Cortex-M1 or Cortex-M3 processor, semihosting is implemented using the BKPT instruction[13].

1.6. Segger Real-Time Terminal (RTT)

The Segger Real-Time Terminal (RTT) provides a bi-directional data transfer mechanism between a host and target microcontroller. RTT emulates a telnet connection on the host machine[12]. For example, to connect to Channel 0 (designed for terminal use), you connect via a Telnet client to localhost:19021.

It is currently supported by the following cores[14]:

  • ARM Cortex-M0/M0+/M1/M3/M4/M7/M23/M33

  • Renesas RX100/200/600

Example target-side code to send a message to the host via Segger RTT on Channel 0[14].
int main(void) {
  do {
    SEGGER_RTT_WriteString(0, "Hello World from SEGGER!\r\n");
    _Delay(100);
  } while (1);
  return 0;
}

2. TagConnect

Segger has jumped on the band wagon and provides a "J-Link 6-pin Needle Adapter" which looks like a re-branded TagConnect to mate with their J-Link programmer.

3. Cortex Debug Connector Pinouts

There are industry-standard connector sizes and pinouts for debugging the Cortex range of ARM-based microcontrollers (e.g. microcontrollers with a Cortex-M0, Cortex-M0+, Cortex-M3, e.t.c.).

3.1. 10-pin, 1.27mm Pitch

The 10-pin, 2x5, 1.27mm pitch (0.050") connector is the most common debug connector used with Cortex-based microcontrollers.

arm cortex 10pin debug connector pinout
Figure 1. Standard pinout for the ARM Cortex 10-pin programming connector configured for (A) JTAG and (B) SWD. NC pins are Not Connected (i.e. not used)[1].

The official connector is the Samtec FTSH-105-01, yet luckily these header-style connectors are standardized across manufacturers and almost any 1.27mm 2x5 header-style connector will work.

samtec ftsh 105 01 l dv k 2x5 1.27mm header
Figure 2. 3D model of the Samtec FTSH-105-01 10-pin 2x5 1.27mm pitch SMD header[2].

Sometimes Pin 7 is removed from the male header, and the female header has a blank position in the same location (i.e. no receptacle). This is to "key" the header so it can’t be mated incorrectly. Another way of preventing incorrect mating is to use a keyed shroud.

Pin 9 (GND) can also be used for detection.

3.2. 14-pin TI Connector

14pin ti jtag connector pinout
Figure 3. Pinout for the TI 14-pin JTAG connector[3][4].

The EMU0 and EMU1 pins can be used for cross-core triggering (e.g. one core halts and signals the other cores to halt)[4]. They are not supported by ARM DSTREAM[5].

The BeagleBoard Rev D and Beagleboard-xM use this connector.

beagleboard photo jtag 14pin ti debug conn highlighted
Figure 4. Photo highlighting the 14-pin TI style JTAG connector on the BeagleBoard-xM[6].

3.3. 20-pin ARM "Standard" Debug Connector Pinout

This is the most common 20-pin debug connector pinout for an ARM device.

arm cortex 20pin arm standard debug connector pinout
Figure 5. Pinout for the 20-pin "standard" ARM debug connector[1].
NotePin 2 may be specified as either VCC (optional) or NC (not connected). In most situations I’ve seen this as NC.

3.4. 20-pin Cortex Debug + ETM Connector Pinout

arm cortex 20pin coresight debug connector pinout
Figure 6. Pinout for the "Cortex Debug + ETM Connector" 20-pin debug connector[1].

Supported by the ULINKPro.

3.5. 38-pin MICTOR Connector

Connecting a trace probe to a ARM target.

References


Authors

Twitter

Related Content:

Tags:

comments powered by Disqus