Skip to content

Target trace usage (UART, SWO, RTT)

Dmitry Rezvanov edited this page Nov 24, 2024 · 9 revisions

UART

  1. Connect the UART pins to MioLink (target's TX to probe's RX and vice versa, target's RX to probe's TX);
  2. Open a terminal program (e.g., Putty) and connect to MioLink's second VCOM with the same parameters configured on the target (example on the screenshot, 115200 8N1):
    image
  3. That's it!

UART on the 10-pin JTAG connector (works only for MioLink):

When the target is debugged via the SWD interface, the JTAG TDI and TDO pins can be used as UART TX and RX, respectively (TDI - MioLink TX, TDO - MioLink RX).
This allows, for example, using a single 10-pin connector for both target debugging and debug output from the target. To enable this feature, add the command monitor uart_on_tdi_tdo enable to the GDB commands.
To disable, use monitor uart_on_tdi_tdo disable.
Note that after changing this setting, you need to reopen the port in the terminal program.
Also, this setting is NOT saved in non-volatile memory, so you'll need to re-enter the command after restarting the probe.

SWO

  1. Connect the debugger's SWO pin to the target's SWO pin;
  2. Configure TRACESWO on the target side. MioLink currently supports only UART mode (Manchester support is planned later);
    Example of TRACESWO setup for STM32F1:
DBGMCU->CR |= DBGMCU_CR_TRACE_IOEN;
DBGMCU->CR &= ~(DBGMCU_CR_TRACE_MODE);

TPI->ACPR = 71;  // Output bits at 72000000/(71+1)=1MHz.
TPI->SPPR = 2;   // Use Async mode (1 for RZ/Manchester)
TPI->FFCR = 0;   // Disable formatter

ITM->LAR = 0xC5ACCE55;
ITM->TCR = (1 << ITM_TCR_TraceBusID_Pos) | ITM_TCR_SYNCENA_Msk | 
 		 ITM_TCR_ITMENA_Msk;
ITM->TER = 0xFFFFFFFF;
  1. Enable the SWO on the probe side: add the command monitor swo enable <baudrate> decode <channel> to your GDB command list.
    Here, baudrate is the interface speed, and channel is the channel where the data is sent (e.g., ITM_SendChar sends data to channel 0).
    Example (1Mbaud, channel 0): monitor swo enable 1000000 decode 0
  2. As with UART mode, open a terminal program and connect to MioLink's second VCOM.
    This time, parameters don't matter since we already set the speed and channel through the GDB command.
  3. That's it!
    Keep in mind that the monitor swo command does not persist its state, so SWO parameters need to be set again after restarting the probe.

RTT

  1. Set up RTT in your target’s firmware by including the appropriate RTT initialization functions from the SEGGER RTT library.
    It is usually enough to simply add the SEGGER RTT files to the project and call SEGGER_RTT_Init before using RTT;
  2. Enable the RTT on the probe side: add the command monitor rtt enable to your GDB command list.
  3. Open a terminal program and connect to MioLink's second VCOM.
    This time, serial parameters don't matter.
  4. That's it!
    Keep in mind that the monitor rtt enable command also does not persist its state, so RTT should be enabled again after restarting the probe if you need it;
  5. If you encounter issues, you can check the current RTT status with the command monitor rtt status.

Troubleshooting

This page describes only the basic setup for UART, SWO, and RTT.
If you encounter any issues, please refer to the Black Magic Probe documentation for further information: SWO, RTT.