printf to USB-CDC on FreeRTOS

932 Views Asked by At

I'm working on a STM32 Cortex M4 with a FreeRTOS running. I try to redirect my printf to the USB CDC output but it seems like my implementation isn't thread safe. A loop of printf('test') prints

ettttt
tttetttttttst
ttetettttttettttttettttttt
ttttttttttttt
t
tttttttttetttttttstttt
tettttttttttttt
t
tttttttetttetttttttett
ttttettttttetettetttt
ttttttttt
ttetetttt
t
ttt

I use the following putchar prototype

PUTCHAR_PROTOTYPE {
    CDC_Transmit_FS((uint8_t*)&ch, 1);
    return ch;
}

Additionally I use the printf-stdarg.c, at least I thought I do. But when I change

int printf(const char *format, ...)
{
        va_list args;
        va_start( args, format );
        return print( 0, format, args );
}

to an empty implementation

int printf(const char *format, ...)
{
        return 0;
}

it still prints to the console as before. So it seems like it's not actually using the implementation from printf-stdarg.c. My idea was to surround the print call with a mutex.

0

There are 0 best solutions below