The printf() function frozen in new create project

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

cross mob
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Hi everyone,

   

I am using the CY8CKIT-042 pioneer kit and PSOC Creator 3.2 SP1 to develop my first PSOC application.

   

Firstly, I create an example project - BLE HID mouse, after doing the Build and Program, the kit works fine and the Putty on PC can receive the debug message.

   

And when I create a new project and revise the _write() for using printf() function (refer to the debug.c of example project), when I do the Debug, the firmware will be frozen at printf(), I found it will run into the infinite loop CY_ISR() in Cm0Start.c.

   

I tried the puts() function, it frozen too; It seems to happen when I called the function of stdio.h.

   

I have checked the Build Settings of the new project, it is same with the example project.

   

please see the attached main.c.

   

Aaron Deng

0 Likes
1 Solution
Anonymous
Not applicable

Can you check what is the size of the heap memory allocated to the system from the project's CYDWR -> Systems tab?

   

Assuming that you have proper libraries to use that function in your system, you may have to increase the memory set for heap size in your project. 

View solution in original post

0 Likes
7 Replies
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Use the sprintf() function, there is no implementation for a system

   

printer in the libraries.

   

 

   

Regards, Dana.

0 Likes
Anonymous
Not applicable

but why the example project using the printf() can do ? or I missed something? 

0 Likes
Anonymous
Not applicable

Can you check what is the size of the heap memory allocated to the system from the project's CYDWR -> Systems tab?

   

Assuming that you have proper libraries to use that function in your system, you may have to increase the memory set for heap size in your project. 

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

roit, can you enlighten me about printf() in a psoc project, what is it printing to ?

   

 

   

I do not see any sdtio.h in the workspace after a build, so I cannot figure out what

   

the STD is ?

   

 

   

Regards, Dana.

0 Likes
Anonymous
Not applicable

Finally, I resolved this problem after growing the heap size to 0x400, the original is only 0x80.

   

Roit, thanks you very much!!

   

Does it means that the printf() function will consume more RAM space?

   

Aaron Deng

Anonymous
Not applicable

@Aaron,

   

Yes, the more heap size allocated, the more RAM will the project consume. If RAM usage is a concern, you can write a loop in your own project to send the data byte by byte over UART and no need to store it in a "file".

   

 

   

@Dana,

   

The printf() functions internally use character transfer over UART. But before sending, the input is saved as a "file" in the heap and then used to send the character byte by byte. So bigger the "file" that you want to save, the more heap size should be allocated.

   

Hope this helps.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

I dug out this code from a Cypress example:

   

 

   

/* For GCC compiler revise _write() function for printf functionality */
int _write(int file, char *ptr, int len)
{
    int i;
    file = file;
    for (i = 0; i < len; i++)
    {
        UART_PutByte(*ptr++);
    }
    return len;
}

   

This you should provide for using the printf() function directly.

   

Regarding the heap:

   

I frequently use malloc() and free() which gets and releases memory from/to the heap instead of using the stack or global data storage. Feels like being quite more flexible. Thus my heap size is usually quite a bit more than 0x0080

   

 

   

Bob

0 Likes