Skip to main content
Associate
July 26, 2024
Solved

How can i get printF to work in other .c files?

  • July 26, 2024
  • 3 replies
  • 1851 views

I just started out a project with FreeRtos and followed this and managed to get it to work.

How to redirect the printf function to a UART for debug messages 

I can also printF from the freertos.c StartXXXTask functions.

But one of the start task functions i call my own method in my custom .C file i can't seem to printF from it. Within that function i can run this and it works, but not printF.

HAL_UART_Transmit(&huart2, buf, strlen((char*)buf), HAL_MAX_DELAY);

 

Wondering what am I doing wrong?

    Best answer by iwagg

    Not sure what I did, but it's working now. 

    3 replies

    Andrew Neil
    Super User
    July 26, 2024

    @iwagg wrote:

     printF


    Why the uppercase 'F' - is this some custom "wrapper" for the standard printf ... ?


    @iwagg wrote:

    But one of the start task functions i call my own method in my custom .C file i can't seem to printF from it.


    What do you mean by that? It doesn't build? You get no output? Other...?

     

    A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
    iwaggAuthor
    Associate
    July 26, 2024

    Apologies, that is my typo, it's not a custom wrapper.

     

    It doesn't work as in no output. It compiles. Tried  putting a HAL uart transmit before and after the printf statement, those work and I get output, just no output from printf.

    Andrew Neil
    Super User
    July 26, 2024

    Does FreeRTOS have separate streams for each Task? Or require each Task to setup its own printf redirection?

    If so, that would be a FreeRTOS question - not specific to STM32 ...

    https://www.freertos.org/Documentation/RTOS_book.html

    https://www.freertos.org/RTOS-contact-and-support.html

     

    A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
    Tesla DeLorean
    Guru
    July 26, 2024

    Likely you haven't got the plumbing setup properly via _write() and __io_putchar()

    Could try

    char buf[64];

    HAL_UART_Transmit(&huart2, (void *)buf, sprintf(buf, "%d\n", 123), HAL_MAX_DELAY);

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    iwaggAuthorBest answer
    Associate
    July 29, 2024

    Not sure what I did, but it's working now.