printf usage in stm32
Hi,
I am using printf for my application to debug the output using UART.
But I am facing the problem.
void StartSender1(void const * argument)
{
/* USER CODE BEGIN 5 */
/* Infinite loop */
for(;;)
{
printf("Sender1 Sending\n");
osMessagePut(Queue1Handle,0x1,200);
printf("Sender1 Delay\n");
osDelay(1000);
}
/* USER CODE END 5 */
}
void StartSender2(void const * argument)
{
/* USER CODE BEGIN 5 */
/* Infinite loop */
for(;;)
{
printf("Sender2 Sending\n");
osMessagePut(Queue1Handle,0x2,200);
printf("Sender2 Delay\n");
osDelay(2000);
}
/* USER CODE END 5 */
}
/* USER CODE BEGIN Header_StartReceiver /
/*
@brief Function implementing the Receiver thread.
@param argument: Not used
@retval None
/
/ USER CODE END Header_StartReceiver /
void StartReceiver(void const * argument)
{
/ USER CODE BEGIN StartReceiver */
osEvent retvalue;
/* Infinite loop */
for(;:wink:
{
retvalue=osMessageGet(Queue1Handle,2000);
printf("Start Receiver Value : %d\n",(int)retvalue.value.p);
}
/* USER CODE END StartReceiver */
}`Now, I have asked in some forum and suggested this.
The library printf may not be thread safe, and may use excessive CPU time spin waiting on the communications channel, possibly even with interrupts disabled.
I personally NEVER use printf in embedded code. I have my own serial output routines that I can send message through to track the program, that I know have been made thread safe, and have know blocking characteristics.
Can printf be implemented in a thread safe manner?
Regards,
Kumar