jdbruijn / LedCube

Program to control an 8x8x8 RGB LED cube.
http://vidavidorra.github.io/LedCube-Documentation
GNU General Public License v3.0
0 stars 0 forks source link

Standard printf with redirect instead of custom printf #13

Closed vidavidorra closed 8 years ago

vidavidorra commented 8 years ago

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

vidavidorra commented 8 years ago

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.