How to use printf() in Psoc Creator project ?

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Leo_liu1
Level 4
Level 4
50 replies posted 25 replies posted 10 replies posted

Hi ,

I can only print data using UART_UartPutString() function,but i can not use printf() function to print data,no error,but print nothing.

Is something i did not do?

#include "stdio.h"

heap is set as 0x200

UART_UartPutString( "Hello World!\r\n" );

printf("HI World!\r\n");

Thanks,

Leo

0 Likes
1 Solution
5 Replies
David_Zhang
Level 5
Level 5
Distributor - Arrow(GC)
First like received 50 sign-ins 25 sign-ins

hi  Lucas:

  What you provide the link , it can use in psoc4200 and high Muc, but in psoc4000 &PSOC4000S , the IDE has no compont of  UART_2.5. Just has uart(scb), so  can't use you example;

pastedImage_0.png

i find an example of PSOC4200 of printf;

https://www.cypress.com/documentation/code-examples/ce224431-psoc-4-uart-printf?source=search&keywor...

CE224431;

and  i copy this below code to pso4000s , it can;t work ,

#include <stdio.h>

#if defined (__GNUC__)

   

    /* Add an explicit reference to the floating point printf library to allow

       use of floating point conversion specifier. */    

    asm (".global _printf_float");

    /* For GCC compiler revise _write() function for printf functionality */    

int _write(int file, char *ptr, int len)

    {      

        /* Warning suppression for unused function parameter */

file = file;

int i;

        /* Character is sent via UART */

        for (i = 0; i < len; i++)

        {

            UART_UartPutChar(*(ptr++));

        }         

        return(len);

    }

#endif /* (__GNUC__) */

/* Start UART operation */

    UART_Start();

printf(helloworld\r\n");

0 Likes
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

Once, I wrote the following topic

printf and float rhapsody (aka, yet another printf and floating topic)

Today I tried it with CY8CKIT-145-40xx (CY8C4045AZI-S413)

main.c (Note: we need to provide an implementation of _write())

==============

#include "project.h"

#include "stdio.h"

int _write(int file, char *ptr, int len)

{

    (void) file ;

    int i ;

    for (i = 0 ; i < len ; i++) {

        UART_UartPutChar(*ptr++) ;

    }

    return len ;

}

int main(void)

{

    CyGlobalIntEnable; /* Enable global interrupts. */

    UART_Start() ;

    UART_UartPutString("\r\nHello From UART\r\n") ;

    printf("Hi from printf()\r\n") ;

    for (;;) {

    }

}

==============

Tera Term Log (Sorry, I could not get rid of the garbage at the top ...)

000-TeraTerm-log.JPG

moto

0 Likes
lock attach
Attachments are accessible only for community members.
David_Zhang
Level 5
Level 5
Distributor - Arrow(GC)
First like received 50 sign-ins 25 sign-ins

hi Motoo:
    i  try you project , it's ok to printf();

but we i use you code in my porject , i can;t work , can you help to check the project , tks;

0 Likes
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Dear DaZh-san,

First of all, an important WARNING!

============================

In the "Touch.zip" you attached a file named "CE210289_CapSense_P4_Linear_Slider01_timing.html" seemed to be infected.

000-Infected.JPG

I recommend you to run a virus scan on your PC to get rid of the potential threat(s).

============================

Now returning to the main story.

I've already written this in my previous post

printf and float rhapsody (aka, yet another printf and floating topic)

===================

(2.2) Expand the heap

Project > Design Wide Resources > System

Heap Size (byte) 0x80 -> 0x200 (value may vary depending on your requirement)

=============

The heap size of your project was "0x80", which was the default size.

002-System-Heap.JPG

You need to double click the "System" in the "Design Wide Recources" in your Project Explorer.

And double clock the "Value" field of Heap Size and modify it from "0x80" to "0x200"

or some value big enough to work with "printf()"

004-heap-200.JPG

I tested your project with my board which has CY8C4146LQI-S433,

as right now this one is the closest to your device as far as I can access.

I modified your main.c and added a debug line using UART_UartPutString().

=======================

    UART_UartPutString("printf test with heap 0x80\r\n") ;

  

    while(1)

    {

        printf("Hi from printf()\r\n") ;  

        CyDelay(300);

    }

=======================

Then when I ran with the heap size of 0x80, the output was

005-test_heap_80.JPG

And when I ran with the heap size of 0x200, the output was

006-test_heap_200.JPG

Attached is your project with the heap size of 0x200.

moto

0 Likes