Keil Logo

Enable 4-Pin Trace (ETM)

To enable CoreSight ETM tracing on STMicroelectronics STM32F4xx devices:

  • Connect ULINKpro to the board's Cortex Debug+ETM connector and to the host computer.
  • Enable the Trace Port Interface as described in the STM32F4 Series Reference Manual chapter TRACE Pin Assignment (steps listed below).
  • Configure µVision to capture ETM trace data (steps listed below).

Enable the Trace Port Interface

  1. Create a text file, for example Trace.ini, and enter the following code:
    ** Define the function to enable the trace port
    FUNC void EnableTPIU(void) {
    // Enable trace port and clock signals
                                          // RCC_AHB1ENR:   IO port E clock enable
      _WDWORD(0x40023830, _RDWORD(0x40023830) | 0x00000010);
      _WDWORD(0x40021000, 0x00002AA0);    // GPIOE_MODER:   PE2..PE6 = Alternate function mode
      _WDWORD(0x40021008, 0x00003FF0);    // GPIOE_OSPEEDR: PE2..PE6 = 100 MHz speed
      _WDWORD(0x4002100C, 0x00000000);    // GPIOE_PUPDR:   PE2..PE6 = No Pull-up/Pull-down
      _WDWORD(0x40021020, 0x00000000);    // GPIOE_AFRL:    PE2..PE6 = AF0
      _WDWORD(0xE0042004, 0x000000E0);    // Set 4-pin tracing via DBGMCU_CR
    ** Invoke the function at debugger startup
    ** Execute upon software RESET
    FUNC void OnResetExec(void)  {

    TRACED[0..3] are output on the pins PE3 through PE6. The trace clock, TRACECK, is configured on pin PE2.  By default, these pins are not assigned and need to be configured using the TRACE_IOEN and TRACE_MODE bits of the DBGMCU_CR register.

    This is done by using the _WDWORD command to configure the DBGMCU_CR  register: _WDWORD(0xE0042004, 0x000000E0);

    The special function OnResetExec() executes upon software RESET. Refer to TPUI Initialization after RESET (Cortex-M) for details.

  2. Open the dialog Options for Target — Debug and insert Trace.ini into the Initialization File field.

    Configure the device for tracing

Configure µVision to capture ETM trace data

  1. Enable Use, select ULINK Pro Cortex Debugger, and click Settings to open the Target Driver Setup dialog.

    Select ULINKpro as the debugger adapter

  2. Click the Trace tab.

    Set ETM trace options

  3. The Core Clock must correspond to the device configuration.
  4. Set Trace Port to Sync Trace Port with 4-bit Data. This setting must always correspond to the setting made in the Trace.ini file.
  5. Set Trace Enable and ETM Trace Enable.
  6. Optionally, enable Unlimited Trace to navigate through the complete data stream history. Make sure to enable this option when measuring the system's energy consumption with PowerScale.

Start the debugging session and verify the captured trace data with a µVision window.


  • Always synchronize the settings in the *.ini file with the settings in the Target Driver Setup - Trace Port dialog.
  • ETM tracing works in Serial Wire Debug as well as in JTAG Debug mode.
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.