Using printf() with FreeRTOS sometimes causes hardfaults
I am working on using FreeRTOS for a project, and have implemented printf() debugging by redirecting it to a uart. This works great most of the time, and is very helpful for FreeRTOS debugging, as FreeRTOS_printf() and FreeRTOS_debug_printf() will leverage this functionality.
Unfortunately, it seems to cause hard faults frequently, but not in every case.
One call that consistently caused a hard fault was
FreeRTOS_printf( ( "FreeRTOS_connect: %u to %xip:%u\n", [...]);Another one I had to manually remove was
FreeRTOS_debug_printf( ( "Socket %u -> [%s]:%u State %s->%s\n", [...]);I came across a previous post which seemed to have a similar issue, but it appeared to have been resolved.
Is there more configuration that I need to implement to have this work in every case? Or is there something else I am missing?
Some more details about my implementation:
I am using CubeMX to generate my code
I am using OpenOCD and GCC
My printf implementation uses the following code
#ifdef __GNUC__
# define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
# define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */
PUTCHAR_PROTOTYPE
{
HAL_UART_Transmit(&huart3, (uint8_t *)&ch, 1, 0xFFFF);
return ch;
}
Thanks for reading, any insight is appreciated!
