Cypress Perform

Home > Design Support > Cypress Developer CommunityTM > Cypress Forums > PSoC® 5 > How do I do a "printf()" function in PSOC5?

Bookmark and Share
Cypress Developer CommunityTM
Forums | Videos | Blogs | Training | Rewards Program | Community Components



How do I do a "printf()" function in PSOC5?
Moderator:
ANCY

Post Reply
Follow this topic



How do I do a "printf()" function in PSOC5?

EdmundR posted on 20 Feb 2013 3:33 PM PST
Member
4 Forum Posts

I tried the method suggested for the PSOC3 to replace the putchar() function, but that wouldn't even compile.




Re: How do I do a "printf()" function in PSOC5?

H L posted on 20 Feb 2013 05:30 PM PST
Top Contributor
679 Forum Posts

That's a PSOC3 specific for Keil compiler, yours is psoc5 and it would be GCC.

Try use sprintf to an array and use putstring to the UART you use.

 



Re: How do I do a "printf()" function in PSOC5?

Bob Marlowe posted on 21 Feb 2013 11:14 PM PST
Top Contributor
1768 Forum Posts

Using the function sprintf() to get a formatted string would be the way I recommend. This string can be sent to LCD, UART or whatever your preferred output devive is.

 

Bob



Re: How do I do a "printf()" function in PSOC5?

EdmundR posted on 21 Feb 2013 09:22 PM PST
Member
4 Forum Posts

Thanks guys.

I had aready figured that one out, but I was hoping for a more elegant solution.



Re: How do I do a "printf()" function in PSOC5?

kkaptruski posted on 11 Mar 2013 05:10 AM PST
Member
7 Forum Posts

Hi EdmundR!

I got this working on PSoC5LP with the GCC backend provided by PSoC Creator. The GCC backend in PSoC creator is a product "Sourcery G++ Lite" from CodeSourcery. They use NewLib for their libc implementation. NewLib relies on (small) stub functions, which you can define yourself. See https://sites.google.com/site/stm32discovery/open-source-development-with-the-stm32-discovery/getting-newlib-to-work-with-stm32-and-code-sourcery-lite-eabi for an example of writing these stubs.

You can take a look in the installation directory of PSoC creator:

$ pwd
/cygdrive/c/Program Files (x86)/Cypress/PSoC Creator/2.2/PSoC Creator/import/gnu_cs/arm/4.4.1
$ ls share/doc/arm-arm-none-eabi/pdf/getting-started.pdf
share/doc/arm-arm-none-eabi/pdf/getting-started.pdf
$ ls share/doc/arm-arm-none-eabi/pdf/libc.pdf
share/doc/arm-arm-none-eabi/pdf/libc.pdf


 



Re: How do I do a "printf()" function in PSOC5?

H L posted on 11 Mar 2013 05:56 AM PST
Top Contributor
679 Forum Posts

 Hi, 

That is very interesting. I would like to learn how to do this, Can you tell me what needs to be done?

Say if I have a UART named UART1, what is the procedure to use UART1 as the output of putchar().

Tks

 



Re: How do I do a "printf()" function in PSOC5?

kkaptruski posted on 12 Mar 2013 02:32 AM PST
Member
7 Forum Posts

Hi!

 

As said, you need to write some stub functions, as done here: sites.google.com/site/stm32discovery/open-source-development-with-the-stm32-discovery/getting-newlib-to-work-with-stm32-and-code-sourcery-lite-eabi. So I added that file newlib_stubs.c to my project in PSoC Creator, and did some modifications. For the moment, I have commented out all stubs, except _isatty, _read, _write (I don't think you actually need to comment out the other stubs, but I didn't want to introduce too much new code the first time). I leaved _isatty as is, and modified _read, _write for my usage  (i.e. input/output of UART in your case). The line #include "stm32f10x_usart.h" is of course replaced with the Cypress files you need.



Re: How do I do a "printf()" function in PSOC5?

kkaptruski posted on 12 Mar 2013 02:38 AM PST
Member
7 Forum Posts

Also note that printf with float formatting does not work here. This is good in our embedded environment, otherwise printf would take up more codespace.



Re: How do I do a "printf()" function in PSOC5?

H L posted on 12 Mar 2013 02:55 AM PST
Top Contributor
679 Forum Posts

 Thanks,

I'll try that. :-)

 






ALL CONTENT AND MATERIALS ON THIS SITE ARE PROVIDED "AS IS". CYPRESS SEMICONDUCTOR AND ITS RESPECTIVE SUPPLIERS MAKE NO REPRESENTATIONS ABOUT THE SUITABILITY OF THESE MATERIALS FOR ANY PURPOSE AND DISCLAIM ALL WARRANTIES AND CONDITIONS WITH REGARD TO THESE MATERIALS, INCLUDING BUT NOT LIMITED TO, ALL IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT OF ANY THIRD PARTY INTELLECTUAL PROPERTY RIGHT. NO LICENSE, EITHER EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, IS GRANTED BY CYPRESS SEMICONDUCTOR. USE OF THE INFORMATION ON THIS SITE MAY REQUIRE A LICENSE FROM A THIRD PARTY, OR A LICENSE FROM CYPRESS SEMICONDUCTOR.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms and Conditions of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms and Conditions of this site. Cypress Semiconductor and its suppliers reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

Spec No: None; Sunset Owner: GRAA; Secondary Owner: RAIK; Sunset Date: 01/01/20