2022-09-07 08:36 AM
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.
2022-09-07 08:55 AM
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
2022-09-07 10:17 AM
@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.
2022-09-07 10:26 AM
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
2022-09-08 01:10 PM
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.
2022-09-09 02:48 PM
@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.