cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F407VET6 DEMCR base address

Gonzalo
Associate

Good morning,

I'm trying to develop a simple Hello World printf example by writting "Hello World" into the port0 of ITM. There are several tutorials telling that 0xE000EDFCU is the base address to set the bit TRCENA to 1. However, when I try to debug my application using the ST-LINK and the SWV ITM Data Console, the port 0 does not display the message, even if the trace is enabled. Is it 0xE000EDFCU the correct base address? The Reference Manual does not contain any information about it. Thanks in advance.

 

main.c

 

 

#include <stdint.h>
#include <stdio.h>

int main(void)
{
    printf("Hello World\n");
	for(;;);
}

 

 

 syscalls.c (lines modified)

 

 

//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++)
  {
    // __io_putchar(*ptr++);
	ITM_SendChar(*ptr++);
  }
  return len;
}

 

 

3 REPLIES 3

Not sure it needs to be constantly re-enabled.

PB3/SWO needs physical connectivity, some ST boards need solder bridges made, check them.

Also there needs to be agreement between the STM32 and debugger about what speed the core is running at, as this along with the SWCLK rate determines the baud rate internally for the SWV interface.

Most of the SWD stuff is going to be in the Programming Manuals, or ARM TRM, not the stuff around the core which goes into the Reference Manuals

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

So I actually checked in the ARM M4 TRM and the address for DEMCR is, indeed, 0xE000EDFC. Also, I have noticed that in debug mode, in variables I can see how "ch" is updating the letters of "Hello world", so I don't get why it is not displayed in the port0 in the SWV ITM Data Console


@Tesla DeLorean wrote:

Also there needs to be agreement between the STM32 and debugger about what speed the core is running at, as this along with the SWCLK rate determines the baud rate internally for the SWV interface.

I've tried with 16 and 168 MHz in the Core Clock setting in SWV, but it still doesn't work. Any ideas I could implement there?

Thanks in advance.

Pavel A.
Evangelist III

@Gonzalo In your main.c just include the proper CMSIS header file for your STM32 and that's all. You can call ITM_SendChar(). When the debugger connects to the MCU, and ITM is enabled in the debugger options, the debugger will configure all the registers itself.

I've tried with 16 and 168 MHz in the Core Clock setting in SWV, but it still doesn't work.

Obviously you need to specify the correct core clock value. (debuggers can get it as well to make the setup fully automatic, but none do so AFAIK). The clock value is in the standard variable SystemCoreClock (in Hz).

In CubeIDE debugger you also have to start the ITM logger by clicking the red record button of the ITM console window.