cancel
Showing results for 
Search instead for 
Did you mean: 

ITM printf trace

DPiór.1
Associate III

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:

debugger configuration.png

ITM configuration.png

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?

14 REPLIES 14

Yes... that simple. Maybe because the MCU has too few pins.

PavelA_0-1748614318287.png

 


@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!

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

@Pavel A. wrote:

Yes... that simple. Maybe because the MCU has too few pins.

PavelA_0-1748614318287.png

 


I don't think it is because the MCU has too few pins, because SWO is available on pin PB3. 

@DPiór.1 Because the chip has too few pins, they had to use PB3 for a LED:

PavelA_0-1748627892245.png

 

 

 

Doh! I knew that, having just built a board that uses it!

Must read things properly before hitting "Reply" :)