From f40699d2f98cdffe86bdbb5262a5e0115a87ce62 Mon Sep 17 00:00:00 2001 From: Fabian Otto Date: Tue, 17 Jun 2025 09:39:50 +0200 Subject: [PATCH] logging: backend: add KConfig option for SWO sync packets Add KConfig LOG_BACKEND_SWO_SYNC_PACKET to allow disabling SWO synchronization packets. Useful if the SWO is used as a UART replacement to avoid that the sync packets show up as special characters in a terminal application. Signed-off-by: Fabian Otto --- doc/releases/release-notes-4.2.rst | 4 ++++ subsys/logging/backends/Kconfig.swo | 9 +++++++++ subsys/logging/backends/log_backend_swo.c | 8 ++++++-- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/doc/releases/release-notes-4.2.rst b/doc/releases/release-notes-4.2.rst index f0702517b45b..bc1247e109e7 100644 --- a/doc/releases/release-notes-4.2.rst +++ b/doc/releases/release-notes-4.2.rst @@ -190,6 +190,10 @@ New APIs and options * :c:func:`display_clear` +* Logging + + * :kconfig:option:`CONFIG_LOG_BACKEND_SWO_SYNC_PACKETS` + * Networking: * IPv4 diff --git a/subsys/logging/backends/Kconfig.swo b/subsys/logging/backends/Kconfig.swo index 5fabe50b62ee..e4acaac7f18c 100644 --- a/subsys/logging/backends/Kconfig.swo +++ b/subsys/logging/backends/Kconfig.swo @@ -52,6 +52,15 @@ config LOG_BACKEND_SWO_PROTOCOL_MANCHESTER endchoice +config LOG_BACKEND_SWO_SYNC_PACKETS + bool "Synchronization packet transmission" + default y + help + Generate synchronization packets with a unique pattern in the bitstream. + If the SWO pin is used for simple UART text output on a generic terminal application, + these packets show up as special characters in regular intervals. + You can avoid that by disabling this setting. + backend = SWO backend-str = swo source "subsys/logging/Kconfig.template.log_format_config" diff --git a/subsys/logging/backends/log_backend_swo.c b/subsys/logging/backends/log_backend_swo.c index 666333b95e0a..4bf4efef14e6 100644 --- a/subsys/logging/backends/log_backend_swo.c +++ b/subsys/logging/backends/log_backend_swo.c @@ -110,9 +110,13 @@ static void log_backend_swo_init(struct log_backend const *const backend) DWT->CTRL &= (DWT_CTRL_POSTPRESET_Msk | DWT_CTRL_POSTINIT_Msk | DWT_CTRL_CYCCNTENA_Msk); DWT->CTRL |= (DWT_CTRL_POSTPRESET_Msk | DWT_CTRL_POSTINIT_Msk); /* Configure Formatter and Flush Control Register */ - TPI->FFCR = 0x00000100; + TPI->FFCR = TPI_FFCR_TrigIn_Msk; /* Enable ITM, set TraceBusID=1, no local timestamp generation */ - ITM->TCR = 0x0001000D; + uint32_t tcr = ITM_TCR_ITMENA_Msk | ITM_TCR_DWTENA_Msk | (1 << ITM_TCR_TRACEBUSID_Pos); +#if CONFIG_LOG_BACKEND_SWO_SYNC_PACKETS + tcr |= ITM_TCR_SYNCENA_Msk; +#endif + ITM->TCR = tcr; /* Enable stimulus port used by the logger */ ITM->TER = 1 << ITM_PORT_LOGGER;