are printf, fprintf, scanf etc threadSafe in threadX?
HI
i have a question about printf. fprintf,scanf etc
i'm redirecting those functions to use a UART replacing the int _write(int file, char *ptr, int len) and int _read(int file, char *ptr, int len) functions.
int _write(int file, char *ptr, int len)
{
HAL_UART_Transmit(&huart2,(uint8_t*)ptr, len, 1000);
return len;
}
int _read(int file, char *ptr, int len)
{
__HAL_UART_CLEAR_OREFLAG(&huart2);
HAL_UART_Receive(&huart2,(uint8_t*)ptr, len,HAL_MAX_DELAY);
HAL_UART_Transmit(&huart2,(uint8_t*)ptr,len, 1000);
return len;
}
now i'm using threadX and possibily call printf or the other function from multiple threads
is this approach already thread safe or i have to implement a mutex for the Uart?
If i have to use a mutex is that possible to get and put the mutex inside the _write or _read function or i have to get the mutex before call printf?
thank you
