Skip to content

Commit 3a86b72

Browse files
committed
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 <[email protected]>
1 parent f4a0beb commit 3a86b72

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

subsys/logging/backends/Kconfig.swo

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ config LOG_BACKEND_SWO_PROTOCOL_MANCHESTER
5252

5353
endchoice
5454

55+
config LOG_BACKEND_SWO_SYNC_PACKETS
56+
bool "Synchronization packet transmission"
57+
default y
58+
help
59+
Generate synchronization packets with a unique pattern in the bitstream.
60+
If the SWO pin is used for simple UART text output on a generic terminal application,
61+
these packets show up as special characters in regular intervals.
62+
You can avoid that by disabling this setting.
63+
5564
backend = SWO
5665
backend-str = swo
5766
source "subsys/logging/Kconfig.template.log_format_config"

subsys/logging/backends/log_backend_swo.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,13 @@ static void log_backend_swo_init(struct log_backend const *const backend)
110110
DWT->CTRL &= (DWT_CTRL_POSTPRESET_Msk | DWT_CTRL_POSTINIT_Msk | DWT_CTRL_CYCCNTENA_Msk);
111111
DWT->CTRL |= (DWT_CTRL_POSTPRESET_Msk | DWT_CTRL_POSTINIT_Msk);
112112
/* Configure Formatter and Flush Control Register */
113-
TPI->FFCR = 0x00000100;
113+
TPI->FFCR = TPI_FFCR_TrigIn_Msk;
114114
/* Enable ITM, set TraceBusID=1, no local timestamp generation */
115-
ITM->TCR = 0x0001000D;
115+
uint32_t tcr = ITM_TCR_ITMENA_Msk | ITM_TCR_DWTENA_Msk | (1 << ITM_TCR_TRACEBUSID_Pos);
116+
#if CONFIG_LOG_BACKEND_SWO_SYNC_PACKETS
117+
tcr |= ITM_TCR_SYNCENA_Msk;
118+
#endif
119+
ITM->TCR = tcr;
116120
/* Enable stimulus port used by the logger */
117121
ITM->TER = 1 << ITM_PORT_LOGGER;
118122

0 commit comments

Comments
 (0)