2025-04-10 7:26 AM
I have a STM32L432 Nucleo-32 board and I'm trying to use ITM printf trace.
I created new project with configuration: "Targeted Project type: Empty" "targeted language: C++". I'm not using HAL libraries.
In the syscalls.c I added following code:
//Debug Exception and Monitor Control Register base address
#define DEMCR *((volatile uint32_t*) 0xE000EDFCU )
/* ITM register addresses */
#define ITM_STIMULUS_PORT0 *((volatile uint32_t*) 0xE0000000 )
#define ITM_TRACE_EN *((volatile uint32_t*) 0xE0000E00 )
void ITM_SendChar(uint8_t ch)
{
//Enable TRCENA
DEMCR |= ( 1 << 24);
//enable stimulus port 0
ITM_TRACE_EN |= ( 1 << 0);
// read FIFO status in bit [0]:
while(!(ITM_STIMULUS_PORT0 & 1));
//Write to ITM stimulus port0
ITM_STIMULUS_PORT0 = ch;
}
__attribute__((weak)) int _write(int file, char *ptr, int len)
{
(void)file;
int DataIdx;
for (DataIdx = 0; DataIdx < len; DataIdx++)
{
ITM_SendChar(*ptr++);
}
return len;
}
I didn't make any changes to the Clock and as far as I know the default clock for STM32L432 is 4MHz. Here is the debug and ITM configuration:
I also started recording in ITM Data Console window.
I don't see any traces in the SWV ITM Data Console window. Any ideas why? What am I doing wrong?
Solved! Go to Solution.
2025-05-30 7:13 AM
Yes... that simple. Maybe because the MCU has too few pins.
2025-05-30 7:29 AM
@CTapp.1 wrote:I though that's what it used to program the target device?
SWDIO & SWCLK are used for programming and debugging.
But this thread is about using the ITM Trace output, which goes via SWO - an extra pin!
2025-05-30 7:34 AM
@Pavel A. wrote:Yes... that simple. Maybe because the MCU has too few pins.
I don't think it is because the MCU has too few pins, because SWO is available on pin PB3.
2025-05-30 10:58 AM - last edited on 2025-06-02 1:57 AM by Andrew Neil
2025-06-09 4:44 AM
Doh! I knew that, having just built a board that uses it!
Must read things properly before hitting "Reply" :)