The printf function consumes significant flash memory in PSoC® 4. Is there any alternate function for printf?
The printf function is provided in the tool chain (ARM® GCC). As an alternative, use the iprintf() function provided in this KB. This function has the optimized code to implement some of the most commonly-used features of the printf function.
The iprintf() function supports only the following format specifiers:
Table 1. iprintf() Format Specifiers
|%s||Array of char|
|%d||Integer in decimal format|
|%c||Char single character|
|%x||Integer in hexadecimal format|
To test the code, follow the steps given below:
- Create a project named “Design01”.
- Download and extract iprintf.zip. Copy the files iprintf.c and iprint.h to the “Design01.cydsn” folder.
- Add iprintf.c and iprint.h to the project.
- Add #include “iprintf.h” in the main.c file as shown in step 6.
- Place the SCB-based UART Component in the design and configure its parameters depending on the requirements. Name the UART Component as “SCB_1”. If you want a different name, then modify the call SCB_1_UartPutChar(ch) in the iputc() function present in the iprintf.c file.
If you are using the Software UART Component (SW_Tx_UART) with the instance name SW_Tx_UART_1, then use the function SW_Tx_UART_1_PutChar() in iputc() function.
- Use the iprintf() function call in the main() function as shown in the following code. This code continuously prints the string “abcd” and the incrementing numbers in decimal, ASCII, and hexadecimal formats.