cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 5, 3 & 1 MCU

Anonymous
Not applicable

Hi all,

   

how do I get printf() working with newlib-nano and a UART / USBUART

   

I am useing Creator 3.3 with the ARM GCC 4.9-2015-q1-update

   

first I've read various posts in this forum regarding formatted output via UART / USBUART and the use of sprintf() vs. printf(), for instance this one here: http://www.cypress.com/forum/psoc-5-device-programming/how-do-i-do-printf-function-psoc5?source=sear... 

   

When linking with newlib (Use newlib-nano = False) it works fine and the _write() stub functions I provide obviously overrides the weak implementation in newlib. In other words: printf() writes output to my USBUART / Putty

   

However, when linking with newlib-nano (Use newlib-nano = True) the _write() function in my stubs.c file is never called. When doing assembly stepping,  I can dig deeper in the call hierarchy but never end in a function _write() as in the newlib case.

   

Now my questions:

   

1) how is "stubbing" supposed to work on newlib-nano?

   

2) anybody got this working?

   

Note that I know the workarounds / alternatives with sprintf() and then streaming the char arr to an output, that's not the point here.

   

Just thought it would be nice to have something tiny working the "usual C way"

   

Regards,

   

Christof

0 Likes
Reply
1 Solution
Anonymous
Not applicable

increasing heap size solved the problem.

   

Original answer Cypress support:

   


In default PSoC 5LP projects will be having a heap size of 0x80, this is to decrease the project size. For newlib nano to use the printf you may need to have more heap size. Can you try increasing it to 0x200 or more. [*.cydwr file -> Systems tab]
 

   

HTH others as well,

   

Christof

View solution in original post

0 Likes
Reply
6 Replies
Esteemed Contributor II

Welcome in the forum, Christof!

   

Use

   

/* 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;
}

   

 

   

Bob

0 Likes
Reply
Anonymous
Not applicable

Hi!

   

I am using this.

   

As pointed out above, when linking with newlib-nano instead of newlib this function is never called. When linking with newlib it works flawlessly.

   

Christof

0 Likes
Reply
Esteemed Contributor II

Christof,

   

Error confirmed.

   

I would suggest you to create a support case to get that answered. At top of this page "Design Support -> Create a Support Case"

   

Would be nice when you keep us informed here in the forum.

   

 

   

Bob

0 Likes
Reply
Anonymous
Not applicable

Bob,

   

will do.

   

In addition I have placed a question to the ARM guys who are maintainers of the newlib-nano. But I guess the behavior is very depending on how 3rt paties (in this case Cypress) are building this library (we have no sources from Cypress)

   

Regards,

   

Christof

0 Likes
Reply
Esteemed Contributor II

Cypress has very tight contact to ARM, there is Heinz Holzapfel (hpha@cypress.com) sitting in Portland who might help you. I would suggest to send the Cypress case number to him together with a bit of explanation.

   

 

   

Bob

0 Likes
Reply
Anonymous
Not applicable

increasing heap size solved the problem.

   

Original answer Cypress support:

   


In default PSoC 5LP projects will be having a heap size of 0x80, this is to decrease the project size. For newlib nano to use the printf you may need to have more heap size. Can you try increasing it to 0x200 or more. [*.cydwr file -> Systems tab]
 

   

HTH others as well,

   

Christof

View solution in original post

0 Likes
Reply