Skip to main content
Graduate II
April 1, 2025
Question

IAR: How to redirect the printf function to a UART

  • April 1, 2025
  • 3 replies
  • 1169 views

Originally a comment on the How to redirect the printf function to a UART for debug messages Knowledge Base article.

Moved to main forum for better visibility & discussion


 

Hello @ST AME Support NF ,

I have tried example code.

..\Repository\STM32Cube_FW_F7_V1.17.2\Projects\STM32F746ZG-Nucleo\Examples\UART\UART_Printf

In ST CubeIDE and MDK-ARM it's working fine but in IAR(EWARM) IDE it's not working.

I tried to implement _write function but it's not triggered whenever i call printf.

Please guide me to implement this in IAR IDE.

    This topic has been closed for replies.

    3 replies

    Super User
    April 1, 2025

    @lavanya wrote:

    Please guide me to implement this in IAR IDE.


    It is implementation-defined, so probably best to ask IAR about that - they may well have their own way of doing this ...

    https://www.iar.com/support

     

    PS:

    https://community.st.com/t5/others-stm32-mcus-related/iar-redirect-printf-to-uart-and-fprintf-to-sd-card-fat-file/td-p/98596

    lavanyaAuthor
    Graduate II
    April 1, 2025

    Duplicate - merged.


    Hi  

    I have tried example code.

    ..\Repository\STM32Cube_FW_F7_V1.17.2\Projects\STM32F746ZG-Nucleo\Examples\UART\UART_Printf

    In ST CubeIDE and MDK-ARM it's working fine, But in IAR(EWARM) IDE it's not working.

    I tried to implement _write function but it's not triggered whenever i call printf.

    Please guide me to implement this in IAR IDE.

    Super User
    April 1, 2025

    Implement function in your code:

    size_t __write(int handle, const unsigned char * buffer, size_t size);

    Note the double __  !  For the CubeIDE (newlib) this function is _write with single _.

    Also with the semihosting, the function names differ. All this is described in the IAR C/C++ development document.