Migrating projects with the custom fputc() function
Technical Note 220216
Architectures:
Arm
Component:
compiler
Updated:
3/1/2022 4:16 PM
Introduction
Some projects with a custom fputc()
function generate no output when they are migrated to EWARM 9.20.1 or later version.
Discussion
This Technical Note applies to projects matching all these points:
- Uses Full Library configuration, in other words the
_DLIB_FILE_DESCRIPTOR = 1
.
and - Only uses the
printf()
function and/orputchar()
function for output.
and - Has implemented a custom
fputc()
function.
Other migrated projects are not affected.
Suggestions:
- Evaluate if the project needs Full library configuration. If not, switching to Normal library configuration could solve the problem.
- If Full library configuration is needed: Implement
__write()
instead offputc()
.
Note: The recommended way to do retargeting is to implement __write()
. This is described in the IAR C/C++ Development Guide, in the chapter The DLIB runtime environment, in the section Retargeting—Adapting for your target system, under the heading Standard streams for input and output.
Background:
EWARM 9.20.1 introduced an optimization in the run-time library.
- The aim of that optimization is to avoid including (in the linked
.out
file)file descriptor
(includingmalloc()
). - In other words, the optimization shrinks linked output in 9.20.1 and later versions.
Example:
This link holds two example projects for retargeting printf()
to UART1
when fputc()
and __write()
has been retargeted. The example (on the MCB2130 board) shows how to migrate from EWARM 9.10.2 to EWARM 9.20.2.
Conclusion
For migrated projects where this ‘no output’ issue occurs, the change from a custom fputc()
function to a custom __write()
function solves the issue.
A benefit is that the size of the linked .out
file shrinks, when doing retargeting with a custom __write()
function.
All product names are trademarks or registered trademarks of their respective owners.