cancel
Showing results for 
Search instead for 
Did you mean: 

IAR - Redirect printf to UART and fprintf to SD card FAT File system

KGane.1
Associate III

I am using IAR EWARM 9.10.2 and would like to redirect printf to UART and fopen/fclose/fprintf to SD card hosting FAT File System(R0.12c (March 04, 2017)). Any guide on how to do redirect io streams on IAR would be helpful.

Thanks in advance.

5 REPLIES 5

https://wwwfiles.iar.com/arm/webic/doc/ewarm_developmentguide.enu.pdf

Is suspect you need to replace __write function with your own, or redirect the linker to use yours rather than it's own.

--redirect __write=__write_kgane

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

@Community member​ Thank you!.

I tried redirecting fpintf to SD card. I found templates for file operation in \IAR Systems\Embedded Workbench 9.0\arm\src\lib\file.

Implemented __open/__close/__write/__read/__/lseek. When running code in IAR debug mode, the execution trapped using BKPT instruction. Seems the IDE is semi-hosting.

0693W00000Suk27QAB.png 

0693W00000Suk22QAB.png

Perhaps a check-box item in the project/build metadata, or can be changed via a #pragma

Sorry, team Keil here, but I'd expect IAR would facilitate relatively easily

https://stackoverflow.com/questions/10503680/use-of-arm-semihosting

Some of the redirect examples talk of the buffered write, where you provide that functionality.

--redirect __write=__write_bufferred

https://www.iar.com/sv/knowledge/learn/programming/overriding-and-redirecting-library-modules-without-rebuilding-the-entire-library/

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Pavel A.
Evangelist III

Just select a non-minimal variant of the IAR runtime library, that uses file handles (or descriptors).

Do not select semihosting, of course.

Then your _write replacement will receive the file handle/descriptor number.

Send the data for different descriptors to different destinations, as you like. Values 1 and 2 are stdout and stderr.

KGane.1
Associate III

@Community member​ , @Pavel A.​ Thank You.

I can redirect to both UART and SD Card using "Full" Library Configuration. I had to disable "Buffered terminal output" in IAR. In addition to own implementation of __open/__close/__write/__read/__/lseek, putchar and getchar needs modification to call to UART TX & RX functions.

The following TN is useful.

https://www.iar.com/knowledge/support/technical-notes/compiler/migrating-projects-with-the-custom-fputc-function/