Standard printf with redirect instead of custom printf
Opened this issue · 1 comments
Background info
Currently the custom Uart1_printf
function is used which requires the following includes:
# include <stdio.h> // For vsprintf() in Uartx_printf()
# include <stdarg.h> // For Uartx_printf()
# include <string.h> // For memset()
This results in a rather large increasement in the amount of bytes used in the program register (25% to 44% on 60663 bytes of programming memory). Using the standard printf function reduces this according to the functionality used. For example when only using printing a string without formatting, it goes from 25% to 26%, and when using formatting it goes to about 30%. So this is quite a difference that is very welcome.
Steps
- Find out usages of
stderr
and alike streams; - Put the current
Uart1_NNN
functions inside a#if 0
equally block; - Replace all the calls to
Uart1_printf
with calls toprintf
idem forputc
andputs
; - For
assert
anddebug
see if it should use the same stream as the standard output or whether a different stream could be used and implement those features accordingly; - Check whether it is possible to use one of the
printf
,puts
orputc
for the functionsUart1_putNum
andUart1_putBits
and implement those features. Otherwise rewrite the putNum and putBits functions to drop theUart1_
prefixes and useputc
for printing inside those functions; - Check whether tghe
gets
-family functions could be used instead ofUar1_gets
and change those features accordingly.
Step 1
Both the stdout
and stderr
streams redirect their messages to the UART1.
Remaining steps
After some testing in the code I found out that using printf drastically increases the size if implemented a lot. For example 57% with all Uart1_printf
calls replaced by printf
calls compared to 48% when using Uar1_printf
...
So for now I will be sticking with the uart printf!
Steps taken
I've created defines for uprintf
, uputc
, uputs
, uputnum
and uputbits
macros which are currently redirected to the Uart1_
equivalents.
From now on those functions should always be used for printing. That allows a easy change of stream.