cancel
Showing results for 
Search instead for 
Did you mean: 

Trying to print "Hello World" NUCLEO-L4R5ZI with ST-Link SWD

Zofiaisthebest
Visitor

Hi everyone,

 

I am new to the embedded world and I currently have a STM32 Nucleo L4R5ZI board. I am trying to print "Hello World" to the SWV ITM Data Console through port 0. I am following the Fastbit tutorial on Udemy which uses a STM32F407VG board.

 

I created a empty project that doesn't use any HALs or generated code from the CubeMX software. I included the stdio.h header file and have the printf("Hello World\n"); in the main loop of main.c file:

 

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


#if !defined(__SOFT_FP__) && defined(__ARM_FP)
  #warning "FPU is not initialized, but the project is compiling for an FPU. Please initialize the FPU before use."
#endif

int main(void)
{

	printf("Hello World\n");
    /* Loop forever */
	for(;;);
}

 

 

In the syscalls.c files, I created a new function as stated below which I got from the tutorial:

 

 

//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;
}

 

 

 

I then changed my write function as well:

 

 

__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;
}

 

 

 

I then created a debug configuration using the following settings:
Screenshot 2024-07-20 212012.png

I then open the debugger and have a SWV ITM Data Console with port 0 enabled and have the trace started. When I run the code, nothing appears on the console. 

 

What could be the issue? I thought it was an issue with the registers, but I verified the ITM_STIMULUS_PORT0 
 and ITM_TRACE_EN registers. I couldn't find the address for the DEMCR register.

 

Any help with be greatly appreciated!

 

 

0 REPLIES 0