cancel
Showing results for 
Search instead for 
Did you mean: 

swv itm data console stop printing after few lines

GaneshKGrg
Associate II

Hi There,

I am using a SWV ITM to print the messages but it always stoped printing after 221 counter number as below image. Could any tell us what needs to be set to see continues printing. 

Screenshot from 2024-01-07 10-10-54.png

16 REPLIES 16
Pavel A.
Evangelist III

What do you use to print? printf from the newlib/nano? With FreeRTOS? 

GaneshKGrg
Associate II

With FreeRTOS. Below is the code sample.

 

 

void StartDefaultTask(void *argument)
{
  /* USER CODE BEGIN 5 */
	uint32_t i = 0;
  /* Infinite loop */
  for(;;)
  {
	  printf("%lu: StartDefaultTask\n", i++);
	  osDelay(300);
  }
  /* USER CODE END 5 */
}

/* USER CODE BEGIN Header_Task2_init */
/**
* @brief Function implementing the Task2 thread.
*  argument: Not used
* @retval None
*/
/* USER CODE END Header_Task2_init */
void Task2_init(void *argument)
{
  /* USER CODE BEGIN Task2_init */
	uint32_t i = 0;
  /* Infinite loop */
  for(;;)
  {
	  printf("%lu: Task2_init\n", i++);
	  osDelay(300);
  }
  /* USER CODE END Task2_init */
}

 

 

 

Is it crashing, or Hard Faulting ?

If you stop in the debugger, where does it stop? In the for loop in _write() ?

Using ST-LINK?Which version, which firmware?

Do you see the same behaviour if you use the SWV function of STM32 Cube Programmer ?

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

Aha so that's printf. Most likely you have a C library reentrancy issue with printf (a.k.a. Dr. Nadler's syndrome). To test this, please call printf in a loop 230 times before starting the RTOS scheduler and see if it all prints out. 

 

Ah no, it is not crash or hard fault.

When i debug, It does go inside the _write() function but never print out.

I call printf 230 times before RTOS scheduler and it can print out 230 times but it stoped at 81 counter value inside rtos task.

 

 

  uint8_t i = 0;
  for (i = 0; i < 230; i++)
  {
	  printf("%u: Before Task initialised\n", i);
  }
  /* USER CODE END 2 */

  /* Init scheduler */
  osKernelInitialize();

 

 

 

 

Well so the problem is not in SWV/ITM but in integration of printf (and likely other newlib library stuff too) and FreeRTOS.

This is complicated, and one of recent CubeIDE updates seems to have regression in multi-thread locks. Please google (or whatever search engine you prefer) for STM32 + newlib + locking.

Thanks Pavel A, 

I google it but seems like nobody has found the proper solution.

I will not use SWV for now. I think i will use serial to print the data.

Pavel A.
Evangelist III

Your problem is not in SWV but in printf. Like it fails with ITM it will fail for you with a UART without a proper fix.