4

STM32F4 discovery (Cortex-M4) has ETB, a buffer storing instruction traces. How can I use OpenOCD and on-chip st-link debugger to pull out the traces from ETB?

I am little confused between SWO/SWD. What should I be using? Also, do I need any additional hardware for extracting traces?

Thank you

  • **SWO** is a serial single-wire protocol over which many STM32 (all STM32F4) can output trace data. – HelpingHand Apr 30 '20 at 19:28
  • **SWD** is a two-wire debug protocol / HW interface. Hence, it is more efficient than JTAG as long as you only want to address a single core (because SWD doesn't support daisy chaining multiple cores). It is supported by most (all?) STM32, especially by all STM32F4. You can use it to program the µC, debug it (read/write registers, memory, set breakpoints/watchpoints, etc. etc.). – HelpingHand Apr 30 '20 at 19:30
  • The two protocols together are usually referred to as **SWV** (3 pins, plus Vcc/GND). They usually come together, multiplexed at three of the four/five pins available for JTAG. – HelpingHand Apr 30 '20 at 19:32
  • Have you tried the *etm* commands? http://openocd.org/doc/html/Architecture-and-Core-Commands.html – Codo Apr 30 '20 at 19:51
  • 1
    @Codo - I had the same idea (see answer below), but I'm pretty sure now that the controller just doesn't offer the ETB feature. STM32F4 have been designed for a midrange market where lowering price by saving space on the die is a criterion for chip vendors... – HelpingHand May 02 '20 at 11:33

1 Answers1

6

I'm afraid I never heard of STM32F4 including an Embedded Trace Buffer (ETB) in the implemented subset of the ARM core and its CoreSight features. I think this is because ETB is an optional feature, and ST has decided not to configure/implement this ETB option in its STM32F4 controllers and the ARM core they embed.

I looked up the programming/reference manuals and datasheet of an upper-level representative of STM32F4xx family, and I didn't find anything about ETB, which seems to confirm this assumption.


Now, ETB is not the only option if one wants to stream trace data out of one's MCU:

  • STM32F4 controllers all have an Instruction Trace Macrocell (ITM), which can alternatively deliver a software-defined char output stream or snapshots of data values or the program counter that are collected either at your breakpoints or just periodically, with assistance by the Data Watchpoint/Trace (DWT) unit. You can use the ITM

    • to instrument the application with character output (printf())
    • to profile your application
    • to inspect certain properties/state flows of your software by tracing program breakpoints or data watchpoints

    The ITM is usable through the SWO pin, using any adapter hardware like any version of ST-Link, j-Link, uLink-* etc. It is a proper trace interface since it works without stopping the CPU at breakpoints, so examination won't break your system's real-time properties.

  • Many STM32F4 controllers (AFAIK, those with >= 100 pins) include an Embedded Trace macrocell (ETM), which is able to trace program counter (PC) and data of every CPU cycle, so you can use this one to trace the entire control flow (and data flow) of your controller, also without stopping it at any breakpoint.

    The humongous amount of data to be traced (make sure you have a free USB3 port...) can only be delivered in a useful way through the synchronous port interface around the GPIOE group (alternate functions TRACECLK+TRACED0/1/2/3 => 5 pins in total), which is connected to the Trace Port Interface Unit (TPIU) next to the ETM.

    In order to use this technology, you need the more expensive variants of debug adapters like j-Trace, uLink-Pro or Lauterbach. The cheapest ETM-capable adapter I'm aware of (haven't used it yet, though) is QTrace by PDQlogic starting around £379. The others are available for about 1-4 k£/k€/k$.


The way your question sounds tells me that you probably just started programming STM32's. Therefore I recommend you to get a development board with an embedded ST-Link inside. This is the cheapest solution to get (SWD debug running first, and then) SWO trace running. Atollic blog has a nice intro how to do that quickly.

HelpingHand
  • 1,294
  • 11
  • 27
  • Hi, thanks for the answer. I tried the ITM approach and it works fine. I can get the traces. However, I am interested in reading the ETB traces. I now have a NXP K64F freedom board, which has ETB implemented on it. Do you have any idea on how to access ETB using openOCD on K64F. Thanks – user3647365 May 25 '20 at 14:41
  • No, sorry. I'm afraid I haven't worked with that architecture, and I only used ETB on a completely different controller. – HelpingHand May 25 '20 at 15:41