Printf working but missing the last character

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

cross mob
duno_297731
Level 3
Level 3
10 sign-ins 10 replies posted 10 questions asked

hey,

I wanted to use printf() in my project, so I looked up how to make it work. I included stdio.h, increased the heap size to 0x200, and added the following to the beginning of my code:

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

{

     int i;

     file = file;

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

     {

         UART_PutChar(*ptr++);

     }

     return len;

}

this makes it so I can use printf, but when I printed printf("uart test") it output "uart tes", missing the last character. I tried printing twice; "test1" and "test2" and the first string came out correctly ("test1") but the second printf was missing the last character again, giving "test". I can sprintf after with no issues, just the last printf() loses the last character

what is going on there? what do I need to adjust?

I'm using the CY8CKIT-059 and a FTDI cable (which has been working fine)

0 Likes
1 Solution

Bob,

I can't post the project to which I was adding it due to the code being proprietary. I made a new project to re-create the problem and it just worked. I'll have to look at what in the code might be interfering.

xzng, I'll try that

View solution in original post

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

Can you please post your complete project or a shortened version that shows the error so that we all can have a look at all of your settings. To do so, use

Creator->File->Create Workspace Bundle (minimal)

and attach the resulting file.

Bob

0 Likes

Bob,

I can't post the project to which I was adding it due to the code being proprietary. I made a new project to re-create the problem and it just worked. I'll have to look at what in the code might be interfering.

xzng, I'll try that

0 Likes
Vison_Zhang
Moderator
Moderator
Moderator
First comment on KBA 750 replies posted 250 sign-ins

0x200 heap size maybe not enough, try to change the heap size to 0x300.

0 Likes