Skip to content

Commit 22d6bfa

Browse files
florolfaescolar
authored andcommitted
logging: backend: swo: add Kconfig option for SWO protocol
The TPIU supports serializing the data stream both using an UART-like NRZ protocol as well as using Manchester encoding. Using Manchester encoding has the advantage that it enables receivers that support it to recover the clock from the SWO signal itself. This is particularly useful in situations where the clock rate changes dynamically or is unknown (for example when debugging the clock tree setup or working with a device with a misbehaving main oscillator). Add a Kconfig choice to switch the protocol, keeping the current default of using the NRZ encoding. Signed-off-by: Florian Larysch <[email protected]>
1 parent 706ba43 commit 22d6bfa

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

subsys/logging/backends/Kconfig.swo

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,24 @@ config LOG_BACKEND_SWO_FREQ_HZ
3535
reset. To ensure flawless operation the frequency configured here and
3636
by the SWO viewer program has to match.
3737

38+
choice
39+
prompt "SWO protocol"
40+
default LOG_BACKEND_SWO_PROTOCOL_NRZ
41+
42+
config LOG_BACKEND_SWO_PROTOCOL_NRZ
43+
bool "NRZ encoding"
44+
help
45+
Use UART-like NRZ encoding. This is the most common option, but requires the SWO output
46+
frequency to be known on the receiving side.
47+
48+
config LOG_BACKEND_SWO_PROTOCOL_MANCHESTER
49+
bool "Manchester encoding"
50+
help
51+
Use Manchester encoding. This is less widely supported, but permits the clock to be
52+
recovered automatically on the receiving side.
53+
54+
endchoice
55+
3856
backend = SWO
3957
backend-str = swo
4058
source "subsys/logging/Kconfig.template.log_format_config"

subsys/logging/backends/log_backend_swo.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ static void log_backend_swo_init(struct log_backend const *const backend)
100100
ITM->TER = 0x0;
101101
/* Disable ITM */
102102
ITM->TCR = 0x0;
103-
/* Select NRZ (UART) encoding protocol */
104-
TPI->SPPR = 2;
103+
/* Select TPIU encoding protocol */
104+
TPI->SPPR = IS_ENABLED(CONFIG_LOG_BACKEND_SWO_PROTOCOL_NRZ) ? 2 : 1;
105105
/* Set SWO baud rate prescaler value: SWO_clk = ref_clock/(ACPR + 1) */
106106
TPI->ACPR = SWO_FREQ_DIV - 1;
107107
/* Enable unprivileged access to ITM stimulus ports */

0 commit comments

Comments
 (0)