2023-01-24 06:40 AM
Hi!
I have a problem setting up Serial Wire Output over ITM. I followed every tutorial on the Internet (including this forum) and I still haven't made any progress.
I run the MCU on 280 Mhz:
In Pinout & Configuration -> DEBUG I configured Serial Wire as debug interface.
I've implemented my own _write() function as below:
int _write(int file, char *ptr, int len) {
int DataIdx;
for (DataIdx = 0; DataIdx < len; DataIdx++) {
ITM_SendChar(*ptr++);
}
return len;
}
Next I just call printf inside some loop in main():
while(1) {
printf("counter = %d\n", counter++);
delay = 280000;
while(delay--);
}
My debug configuration looks like this:
And my SWV ITM configuration looks like this:
Please help me figure out how to get it up and running, because I'm getting frustrated after all my failures in tutorials.
Regards,
Piotr
2023-01-26 12:18 AM
> Can you tell me something more about these 'subtle difference'?
If my memory serves, the ITM clock has additional divisor or multiplier. New ST tools know this and compensate.
2023-01-26 01:25 AM
Which tools are you talking about? I use STM32CubeIDE v.1.9.0, CuveMX v.6.5.0
2023-01-26 02:15 AM
Hello @ypiotrp (Community Member)
I successfully tested printf stdio redirected to ITM SWO on STM32H7A3VIT on custom board with STLinkV2-1 standalone and STM32CubeIDE v1.11.0 (but it also works with v1.9.0)
Here a screenshot of SWV ITM Data Console, SWV Data Trace Timeline Graph and Live Expression:
I can suggest to check following point:
If you have syscalls.c in your project, simply re define __io_putchar in the main.c.
/* USER CODE BEGIN 4 */
int __io_putchar(int ch)
{
ITM_SendChar(ch);
return(ch);
}
/* USER CODE END 4 */
Include stdio.h header and your code to printf and increment counter variable.
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "stdio.h"
/* USER CODE END Includes */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
uint8_t counter = 0;
/* USER CODE END PV */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
printf("Counter= %d\r\n", counter);
counter++;
HAL_Delay(500);
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
In the debug configuration, enable SWV with the same CPU clock (280MHz)
Launch the debugger, open SWV ITM Data Console, enable ITM Stimulus Ports 0 (optionally set counter variable in data trace comparator)
Start Trace (red button icon) and resume debugger.
Good luck,
Best regards,
Romain,
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2023-01-27 12:52 AM
OK, I got it working!
Sorry for the trouble explaining it to me. It turned out I made a mistake and soldered SWO wire to wrong pin in my custom SWD plug.
I have the last question. Is there some simple way to access SWO data from localhost:61235? I tried connecting to that port using PuTTy but without any success :(
Regards,
Piotr
2023-01-31 04:28 AM
putty 🙂
you need a "debug" connection; new version of Cube programmer should work...(i didnt test)