cancel
Showing results for 
Search instead for 
Did you mean: 

printf will miss some data during large amount of print

JZhan.9
Associate II

I am using nucleo-H473ZI2 with CubeIDE. When I was trying to print a 1024-long int array, the SWV ITM Data Console will not be giving me all 1024 values.

I implement printf to ITM Stimulus port by writing this function in main.c:

int _write(int file, char *ptr, int len)
{
  /* Implement your write code here, this is used by puts and printf for example */
  int i=0;
  for(i=0 ; i<len ; i++)
    ITM_SendChar((*ptr++));
  return len;
}

Then I am trying to print out all values in the array:

  int print_array[1024];
  for(int i=0; i<1024; i++){
	  print_array[i] = i;
  }
  printf("Hello World!\n");
  //Print out array values
  for(int i=0; i<1024; i++){
	  printf("%d, \n", i);
	  HAL_Delay(5);
  }
  HAL_Delay(1000);
  //Print some more to make sure all data is finished printing
  for(int i=0; i<2; i++){
	  printf("Hello World\n");
	  HAL_Delay(5);
  }
  HAL_Delay(100);
 
  while(1);

But the result I get in the SWV ITM Data Console will only be consisting around 900 numbers instead of 1024 numbers. And the amount of number is fluctuating as well.

I am wondering why this happened, and whether there is any way to avoid it?

Thank you very much!

5 REPLIES 5

Thank you very much, at least I know I am not the only one.

JZ

Not really designed/prioritized for high bandwidth output. Buffering on the ST-LINK is finite.

Try buffering on the STM32 side, and using the VCP

Try something more industrial https://www.segger.com/products/debug-probes/j-link/models/j-link-ultra-plus/

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

An alternative for high speed / high volume SWO (I use 12 Mbit/s on F429):

http://adastra-soft.com/poor-man-arm-cortex-m-swo/