cancel
Showing results for 
Search instead for 
Did you mean: 

STM32CubeIDE 1.9.0 Tracebuffer full!

chriskuku
Senior II

I'm running a debugee (DIYMORE STM32F407VGT6 Board) attached to SWD link adapter of a STM32F407G-DISC1 with onboard MCU disabled.

I'm logging Debug messages from my C-Application using the follwoing code:

while (1)
	    {
	      /* USER CODE BEGIN 3 */
	  	 pin_state = !pin_state;
	  	 HAL_GPIO_WritePin(Led2_GPIO_Port, Led2_Pin, pin_state);
	  	 // synchronous delay for 500 ms
	  	 HAL_Delay(500);
	  	 if(count++ % 10 == 0)
	  		 sprintf(buf,"count=%d\n",count),ITM_SendString(buf);
 
	    }
	    /* USER CODE END WHILE */
 
}
 
void ITM_SendString(char *str)
{
	while(*str){
		ITM_SendChar(*str++);
	}
}

When I run the debug configuration, the trace buffer overflow occurs. It is currently set to 2,000,000. Increasing it to 10,000,000 just makes the overflow happen somewhat later.

OTOH, I'm wondering why such a small debug printf every 5 seconds or so, can cause a buffer overflow.

Core Clock is 168MHz, divider is set to autodetect. I see a value of 86 or so and 2000 KHz max SWO clock.

Any clues why this happens?

5 REPLIES 5
Nikita91
Lead II

Your code with a coma after the sprintf compile, but I don't know wat is generated.

try:

if(count++ % 10 == 0)
{
   sprintf(buf,"count=%d\n",count) ;
   ITM_SendString(buf);
}

chriskuku
Senior II

That's plain C, otherwise I would consider the C-compiler faulty.

And rewriting the code the way you suggested doesn't make the error (tracebuffer overflow)

go away either. Once the error has occured, STM32CubeIDE gets hung and the busy rainbow ball (Mac) is idling.

Bob S
Principal

How is buf declared?

This may not be your problem, but <flame on>for crying out loud this is 2022, why are people still using sprintf() instead of snprintf()<flame off>. Use snprintf() to make SURE you never overflow your buffer, even if you KNOW you've declared the buffer to be large enough.

chriskuku
Senior II

Found the problem: in the settings for the SWV ITM Console I had - without thinking about it - ticked on "Trace Events". These lead to the overflow.

BTW, in the dark theme white text on a little less white background don't look nice. I'd rather change that but what are the names for these colors ?

chriskuku
Senior II

@Bob S​ : how is buf declared?

static char buf[32];

yes, I know, not using snprintf() is bad style, but bear with me, I'm programming in C since 1980 or so :)

This should not be an excuse. cough cough - wiping the dust off my K&R book.