Alternate printf Function for PSoC® 4 - KBA87093

Version: *B



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


%sArray of char
%dInteger in decimal format
%cChar single character
%xInteger in hexadecimal format


To test the code, follow the steps given below:


  1. Create a project named “Design01”.
  2. Download and extract Copy the files iprintf.c and iprint.h to the “Design01.cydsn” folder.
  3. Add iprintf.c and iprint.h to the project.
  4. Add #include “iprintf.h” in the main.c file as shown in step 6.
  5. 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.

  6. 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.