Skip to content

Commit 8d09755

Browse files
fbnorsjhedberg
authored andcommitted
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 <fabian.otto@rohde-schwarz.com>
1 parent 3ae0d39 commit 8d09755

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

doc/releases/release-notes-4.3.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ New APIs and options
176176

177177
* Logging:
178178

179+
* :kconfig:option:`CONFIG_LOG_BACKEND_SWO_SYNC_PACKETS`
180+
179181
* Added options to skip timestamp and level in log backends.
180182

181183
* :kconfig:option:`CONFIG_LOG_BACKEND_SHOW_TIMESTAMP`

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
@@ -112,9 +112,13 @@ static void log_backend_swo_init(struct log_backend const *const backend)
112112
DWT->CTRL &= (DWT_CTRL_POSTPRESET_Msk | DWT_CTRL_POSTINIT_Msk | DWT_CTRL_CYCCNTENA_Msk);
113113
DWT->CTRL |= (DWT_CTRL_POSTPRESET_Msk | DWT_CTRL_POSTINIT_Msk);
114114
/* Configure Formatter and Flush Control Register */
115-
TPIU->FFCR = 0x00000100;
115+
TPIU->FFCR = TPIU_FFCR_TrigIn_Msk;
116116
/* Enable ITM, set TraceBusID=1, no local timestamp generation */
117-
ITM->TCR = 0x0001000D;
117+
uint32_t tcr = ITM_TCR_ITMENA_Msk | ITM_TCR_DWTENA_Msk | (1 << ITM_TCR_TRACEBUSID_Pos);
118+
#if CONFIG_LOG_BACKEND_SWO_SYNC_PACKETS
119+
tcr |= ITM_TCR_SYNCENA_Msk;
120+
#endif
121+
ITM->TCR = tcr;
118122
/* Enable stimulus port used by the logger */
119123
ITM->TER = 1 << ITM_PORT_LOGGER;
120124

0 commit comments

Comments
 (0)