I start using SWD feature in my STM32 discovery board. I redirecting openocd trace output to text file (because I don't find any good SWD monitor for Linux). I don't know why i get two character when I send only one.
In my output file, every character is preceded different ASCII code (mostly no printable). This preceded code is constant because of the port. For example:
Port 0:
0x01 [Character] 0x01 [Character] etc.
Port 1:
0x09 [Character] 0x09 [Character] etc.
Port 2:
0x11 [Character] 0x11 [Character] etc.
Port 3:
0x19 [Character] 0x19 [Character] etc.
I find in github code who use [preceded code] >> 3 formula to get port number. Its works.
I'm using CubeMX & HAL utility like this:
ITM->PORT[portNum].u8 = (uint8_t)ch;
to send "ch" character.
Why I need to use byte operation? This preceded code have other information except port number? I try fund this in diocumentation but every example use ST monitor
I will understand what is exactly preceded code in SWD?
Take a look at my answer here: https://stackoverflow.com/a/57014035/6552613
What you see is the framing that enables data from multiple ITM ports to be multiplexed onto the byte stream on the SWO pin.
If you want to know exactly how the framing is built up, read the "Instrumentation Trace Macrocell" chapter of ARM document DDI0314.