cancel
Showing results for 
Search instead for 
Did you mean: 

I am using STM32MP157F-EV1. I want to enable the CM4 SWO output on the SWO debug pin. Is there any code example or sequence to accomplish this? It is a bit more complicated since this is an MPU target and you have to select between the A7 and the M4.

DPade.1
Associate III

I am currently running in Engineering mode. In this application I am not using Linux on the A7, so I want to enable the trace SWO output from the M4 processor.

3 REPLIES 3
PatrickF
ST Employee

HI @DPade.1​ ,

This page should help you:

https://wiki.st.com/stm32mpu/wiki/How_to_debug_with_Serial_Wire_Viewer_tracing_on_STM32MP15

Regards,

In order to give better visibility on the answered topics, please click on 'Select as Best' on the reply which solved your issue or answered your question. See also 'Best Answers'

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.
DPade.1
Associate III

Hello PatrickF and thanks for your response.

My question is more low level. How do I configure the trace funnel and associated ITM debug registers to route the M4 SWO function to the physical SWO pin? I want to use SWO also under Engineering Mode boot.

It would be nice if the HAL libraries would provide helper functions for the debug configurations. This is mostly relegated to the CMSIS drivers but those have no practical examples associated with them. It seems the debug configurations on the more complex chips (Cortex-M7, etc.) have little to no documentation providing configuration examples.

I managed to figure out the needed settings for the STM32H7 series, but this always seems to take a few days in digging around on Google for various blog posts...I almost never find how to configure the SWO function properly via ST documentation or examples.

DPade.1
Associate III

Hello PatrickF,

I was able to figure it out. It is much simpler than I thought since the CM4 ITM is directly connected to SWO, and SWO automatically muxes the CM7 (APB Mux) and CM4 inputs. In the end, the main issue was understanding the clock gating.

All I needed to do to enable the CM4 ITM output via SWO was enable the trace clock:

// 1) Enable Trace Clock (use default divider, TRACEDIV = 1)
RCC->DBGCFGR |= RCC_DBGCFGR_TRACECKEN;

After that, I just needed to give Keil the correct trace clock speed. Trace clock comes from AXI clock, which I currently have set to 64 MHz HSI. With the default TRACEDIV = 1, the trace clock is thus 64 MHz / 2 = 32 MHz. Further, Keil seems to take care of the SWO registers (SWO_CODR and SWO_SPPR) automatically, so I found there is no need to set them manually in firmware.

0693W00000QMIRcQAP.png 

I did not realize that the ITM (mcu_ss_ck) and SWO (sck_sys_dbg) are clocked separately and that the Trace Funnel is only used for the TPIU output on the STM32MP1 series. Fortunately the Reference Manual for the STM32MP1 had all the information I needed...I just need to dig through it and do some trial and error.