Loading...
 

SW4STM32 and SW4Linux fully supports the STM32MP1 asymmetric multicore Cortex/A7+M4 MPUs

   With System Workbench for Linux, Embedded Linux on the STM32MP1 family of MPUs from ST was never as simple to build and maintain, even for newcomers in the Linux world. And, if you install System Workbench for Linux in System Workbench for STM32 you can seamlessly develop and debug asymmetric applications running partly on Linux, partly on the Cortex-M4.
You can get more information from the ac6-tools website and download (registration required) various documents highlighting:

System Workbench for STM32


Seeking the guideline for using ITM in System Workbench for STM32

Hello,
I had searched through this forum and other resources to understand the functionality and capability of ITM buit-in to ARM Cortex-M. I’m trying to put things together, to come up with a quick and simple guideline for using ITM in System Workbench for STM32. For some of the part, I had the answer or believe known the the answer, and for other parts I’m still struggling to find the answer.

1. ITM is built-in to ARM Cortex-M to facility the debugging. Compare to Semihosting, it provides much better performance and can run normally without debugger connected. Check ITM for more information. And here is Semihosting for comparing.
2. The firmware preparation for using ITM.
The ITM has up to 32 Stimulus Port, currently in most of the case, we are only talking about to use port 0 for output printf style of message.
The firmware code will be needed as below.

ITM_SendChar( ch );  // the implementation of ITM_SendChar  is provided in CMSIS package.

It is a common practice to override the low level IO function of _write() to re-target the standard output to ITM/SWO, such as

int _write(int file, char *ptr, int len)
{
		int DataIdx;
		for (DataIdx = 0; DataIdx < len; DataIdx++)
		{
	   		ITM_SendChar( *ptr++ );
		}
		return len;
}

3. Program and configuration on host computer to view the ITM output
In this scenario, Serial Wire Viewer (SWV) often to be referred.
3.1 SWV within ST-Link Utility
One of the easiest way to view the ITM output is using ST-Link Utility. Of course that means assuming use ST-Link dongle to connect the target ARM processor and the SWO is wired to ST-Link properly.
The downside of this way is that, once start SWO in ST-Link Utility, the driver of st-link was taken and it is impossible to run Debug session from System Workbench for STM32. And further more, the ST-Link Utility seems only available on Windows platform. Personally I like to work on Linux platform much more than others.
3.2 through OpenOCD to redirect the ITM/SWO output to a file on host system.
This needs to provide a proper configuration file to OpenOCD when start it. For details of OpenOCD configuration, look command tpiu config in OpenOCD Command.
Here is a example for my STM32F4Discovery board.

#file stm32f4discovery_ITMp0.cfg
# This is an STM32F4 discovery board with a single STM32F407VGT6 chip.
# http://www.st.com/internet/evalboard/product/252419.jsp
	source [find interface/stlink-v2.cfg]
	source [find target/stm32f4x_stlink.cfg]
# use hardware reset, connect under reset
	itm port 0 on
	tpiu config internal Debug/swo.log uart off 25000000
	reset_config srst_only srst_nogate

It is possible to make the file of Debug/swo.log to be named pipe and then show the output constantly on screen. Since the named pipe is a function provided by the OS, this may only work on Linux and/or Mac OSX. I don’t know if it can work on Cygwin.
Here is a shell script I take from others and modified.

#!/bin/bash
pipe=Debug/swo.log

openocd  -f stm32f4discovery_ITMp0.cfg &
rm -f $pipe
if [[ ! -p $pipe ]]; then
   	mkfifo $pipe
fi

while true
	do
    	if read line <$pipe; then
        	echo $line
    	fi
done
echo "Reader exiting"


3.3 SWV within System Workbench for STM32 ?
Currently the answer is NO. At th is moment, there is no solution to redirect ITM/SWO output to windowed console within System Workbench for STM32. But this is really a desired feature to end user. Wish AC6 will consider it in the near future.

4. It is possible to use ITM for input source?
At first this sounds like insane, but I saw in the CMSIS package, along with ITM_SendChar(char c); there are functions of int32_t ITM_ReceiveChar (void) and int32_t ITM_CheckChar (void) provided. When look the source code further, all those operations based on volatile int32_t ITM_RxBuffer; , so does System Workbench for STM32 provide a way to write to the buffer through OpenOCD?

5. An extra 0x01 appears in ITM/SWO output stream data?
When look the file of swo.log in binary mode, there is an extra 0x01 to each valid character which was send through ITM_SendChar((char) c); , how this extra 0x01 been introduced? From OpenOCD or ITM/SWO ?
6. Using OpenOCD configuration of “tpiu config external uart TRACECLKIN_freq baudrate”
By using OpenOCD configuration of “tpiu config external uart ...” and connect an external 3.3v UART RDX to the pin of SWO on the target board, use a program to connect the tty Device with proper baudrate configuration, for example “screen /dev/ttyUSB2 115200” , to see the output stream data.
There an issue is that the extra 0x01 in the data stream, which described in “ 5. An extra 0x01 appears in ITM/SWO output stream data?” , some programs do not handle the extra 0x01 well than others, leave the output very hard to read.

Hi,

Great summary!

I’m in the same situation, I can get printf() to write to a file but ideally I would like it to print directly into the openocd console or another console view in eclipse. I also have the same problem with the additional 0x01 before each character, which is pretty annoying, and i have’nt been able to tell where it comes from. So currently i can only easily read debug info from within ST-link utility, but that doesn’t allow for simultaneous debugging, as you said.


I’m currently looking for a solution on my end. Have you made any progress?

Edit: I found a very useful link here where a lot of my questions are being answered: http://blog.japaric.io/itm/Question