cancel
Showing results for 
Search instead for 
Did you mean: 

SWV Not Working - tried everything, then check the TRACE Clock source!

David George
Associate III

If you're still not seeing any "ITM printf()" output in the SWV ITM Data Console and you've checked the following;

  • the SWO signal is connected to the ST Link
  • provided a _write() function that calls ITM_SendChar()
  • ticked Enable Port 0 in Seral Wire Viewer settings
  • ticked the Serial Wire Viewer Enable box in the Debug configuration 
  • set the Core Clock (MHz) frequency to the system core frequency in the Debug configuration 

Then I can suggest one more thing to check, this had me stuck for a while until I found out why.

 

The ITM/SWV Unit is not clocked directly from the System Clock, its actually clocked from the PLL1R output. If you scroll down on the CubeMX Clock Configuration page, you'll find the TRACE Clock Mux, its set to PLL1R as the source.

 

DavidGeorge_1-1730299176200.png

Go back up to the PLL1 block and see what the DIVR1 output clock frequency is - this is the Trace/SWV clock frequency you need to use.

 

DavidGeorge_0-1730299094375.png

 

In my design, I had changed the PLL1R divider as I needed an different frequency for another peripheral, this stopped the SWV ITM data working because the frequency no longer matched the debug configuration. 

Now setting the Core Clock (MHz) frequency to the PLL1R frequency in the Debug configuration got the SWV ITM Trace working again.

DavidGeorge_3-1730299601669.png

 

 

 

2 REPLIES 2

>>tried everything

Perhaps its just not possible, and there are more productive uses of time..

I've read the post, and I don't know which STM32 you're talking about, nor how you have PB3/SWO wired, nor to what.

TRACE or ITM? Not seeing any reference to a J-Trace or trace connector.

Most CMx it's a relationship with the core itself. Baud dividers come from the trace units registers

Perhaps try at a low / uniform speed? Say 16 MHz if that's HSI frequency, and then everything else at DIV1

Guessing an ST-LINK/V2 from the 2 MHz connection speed.

Is this an authentic ST-LINK? What exactly are we working with here?

Does the SWV console in STM32 Cube Programmer work?

Any probeable signal on SWO/PB3 pin?

https://mcuoneclipse.com/2021/05/22/swo-with-arm-cortex-m33/

https://community.st.com/t5/stm32cubeide-mcus/trace-swo-output-in-non-debug-mode/td-p/281533

 

/*!
 * \brief Initialize the SWO trace port for debug message printing
 * \param portBits Port bit mask to be configured
 * \param cpuCoreFreqHz CPU core clock frequency in Hz
 */
void SWO_Init(uint32_t portBits, uint32_t cpuCoreFreqHz) {
  uint32_t SWOSpeed = 64000; /* default 64k baud rate */
  uint32_t SWOPrescaler = (cpuCoreFreqHz / SWOSpeed) - 1; /* SWOSpeed in Hz, note that cpuCoreFreqHz is expected to be match the CPU core clock */
 
  CoreDebug->DEMCR = CoreDebug_DEMCR_TRCENA_Msk; /* enable trace in core debug */
  *((volatile unsigned *)(ITM_BASE + 0x400F0)) = 0x00000002; /* "Selected PIN Protocol Register": Select which protocol to use for trace output (2: SWO NRZ, 1: SWO Manchester encoding) */
  *((volatile unsigned *)(ITM_BASE + 0x40010)) = SWOPrescaler; /* "Async Clock Prescaler Register". Scale the baud rate of the asynchronous output */
  *((volatile unsigned *)(ITM_BASE + 0x00FB0)) = 0xC5ACCE55; /* ITM Lock Access Register, C5ACCE55 enables more write access to Control Register 0xE00 :: 0xFFC */
  ITM->TCR = ITM_TCR_TraceBusID_Msk | ITM_TCR_SWOENA_Msk | ITM_TCR_SYNCENA_Msk | ITM_TCR_ITMENA_Msk; /* ITM Trace Control Register */
  ITM->TPR = ITM_TPR_PRIVMASK_Msk; /* ITM Trace Privilege Register */
  ITM->TER = portBits; /* ITM Trace Enable Register. Enabled tracing on stimulus ports. One bit per stimulus port. */
  *((volatile unsigned *)(ITM_BASE + 0x01000)) = 0x400003FE; /* DWT_CTRL */
  *((volatile unsigned *)(ITM_BASE + 0x40304)) = 0x00000100; /* Formatter and Flush Control Register */
}

 

https://mcuoneclipse.com/2021/05/22/swo-with-arm-cortex-m33/

 

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Hi, it wasn't meant to be post for help, I just wanted to raise the point that the TRACE clock frequency is often overlooked in posts about SWV not working in CubeIDE.  

Hopefully of help to someone in the future.