Skip to main content
Visitor II
January 7, 2024
Question

swv itm data console stop printing after few lines

  • January 7, 2024
  • 7 replies
  • 4154 views

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

    This topic has been closed for replies.

    7 replies

    Super User
    January 7, 2024

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

    Visitor II
    January 7, 2024

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

     

     

     

    Graduate II
    January 7, 2024

    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 ?

    Visitor II
    January 7, 2024

    Ah no, it is not crash or hard fault.

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

    Super User
    January 7, 2024

    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. 

     

    Visitor II
    January 7, 2024

    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();

     

     

     

     

    Super User
    January 9, 2024

    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.

    Super User
    January 10, 2024

    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.

    Graduate II
    January 10, 2024

    If the clocking rate on the core and the clocking rate on the debugger are not the same it can potentially desynchronize over time. Because if you tell the baud rate for the manchester encoder is one thing, and the core's doing another thing they are going to diverge at some point.

    If this is using an ST-LINK/V3 the HSE_VALUE is closer to 8333333 than 8000000

    Would suggest reading the SWV baud rate divider value and back computing that the actual rate is. And printing out the Core speed based on the clock sources, and PLL settings.

    Did you check with STM32 Cube Programmer, and it's SWV Viewer?

    Graduate II
    January 10, 2024

    Here we do this so we can quick establish wtf a particular board is doing

    void SystemDiagnostic(void)
    {
     printf("\n\nCore=%d, %d MHz\n", SystemCoreClock, SystemCoreClock / 1000000);
     CORECheck();
     IDCODECheck();
     FPUCheck();
     printf("APB1=%d\n", HAL_RCC_GetPCLK1Freq());
     printf("APB2=%d\n", HAL_RCC_GetPCLK2Freq());
    }
    Visitor II
    January 11, 2024

    Hi Tesla,

    Thanks i used above code and PCLK1 and PCLK2 frequency are same 170MHz.

    I think this is the issue in STM cube ID software.

     

    I tested the same code in STM cube programmer, I did not find any issue at all.

    Screenshot from 2024-01-11 14-24-42.png

    Super User
    January 11, 2024

    I tested just prinf ... in IDE (1.13.1) :

    AScha3_1-1704984870719.png

    26242 lines text ..then error.

     

    this might be the problem:

    AScha3_0-1704984830909.png

    (But my buffer is already at 2000000; try to increase yours.)

    AScha3_2-1704985060416.png

     

    Visitor II
    January 11, 2024

    Hi AScha,

    I am using FreeRTOS and I am using UBUNTU and STM cube ID is 1.14.0.

    Im my case i have not seen above messages as my trace buffer size is 2000000.