2024-01-07 02:18 AM
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.
2024-01-07 03:38 AM
What do you use to print? printf from the newlib/nano? With FreeRTOS?
2024-01-07 10:42 AM - edited 2024-01-07 10:52 AM
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 */
}
2024-01-07 10:53 AM
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 ?
2024-01-07 11:20 AM - edited 2024-01-07 11:20 AM
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.
2024-01-07 01:12 PM
Ah no, it is not crash or hard fault.
When i debug, It does go inside the _write() function but never print out.
2024-01-07 01:25 PM - edited 2024-01-07 01:31 PM
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();
2024-01-09 01:27 PM
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.
2024-01-10 03:01 PM
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.
2024-01-10 03:44 PM
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.