cancel
Showing results for 
Search instead for 
Did you mean: 

IAR: How to redirect the printf function to a UART

lavanya
Associate III

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.

3 REPLIES 3

@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

lavanya
Associate III

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.

Pavel A.
Evangelist III

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.