STM32CubeIDE and SWV ITM Data...once again. This is a bit long.
Looking for some clarification about printf and SWV ITM using an STM32F4-Discovery board (STM32F407VGT). Let's just assume we're working with boards/processors that support the function. What I have configured works but I'd like to understand this a bit better. I've done an online tutorial that begins with an empty STM32 project, then, in order for the SWV ITM Data Console to display the printf info, code was provided to be pasted into the syscalls.c file (not shown) with the associated 'write' function modified with the entry of 'ITM_SendChar()', as shown below:
__attribute__((weak)) int _write(int file, char *ptr, int len)
{
int DataIdx;
for (DataIdx = 0; DataIdx < len; DataIdx++)
{
// __io_putchar(*ptr++);
ITM_SendChar(*ptr++);
}
return len;
}
This works as the custom ITM_SendChar() function is defined with the syscalls.c code addition. No problem so far, this with the empty CubeMX generated code.
Now, using the (assumed) recommended process of including the necessary code into a new project to be able to use the SWV ITM printf type function, I select 'sys' in CubeMX and choose 'Serial Wire' or 'Trace Asynchronous sw', then generate the new code with either of those two choices. I modify only the 'write' function with the new 'ITM_SendChar() function entry (shown above), with no additional code added to the syscalls.c file, and it works. No problem, again. Apparently, the ITM_SendChar() function in core_cm4.h is now available to the project/app.
Here's the part that's unclear. Most of the information I've found indicates that the choice of 'sys/serial wire' or 'sys/trace asynchronous sw' is required to get the SWV ITM Data Console to display the printf data, but if I don't select either debug choice, the code is still generated, the functions are available and modifying only the 'write' function makes debugging with printf work. After all the searching and post reading about the SWV and printf not working can it be that simple that the necessary code is generated and made available (using CubeMX) by default and is ready to go no matter the sys/debug choices or is it something else that causes that code to be generated and available?
TJM