Announcements

Help us improve the Power & Sensing Selection Guide. Share feedback

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 All,

   

As you may know, PSoC 4 has limited flash when compared with PSoC 3 and PSoC 5LP. Using the GCC print and sprintf functions takes up ~30k of flash, which easily overflows PSoC 4’s flash space.To avoid this, we have developed the tinyprintf component and an example project showing its use. 

   


The component supports d, u, c, x, X, and s formats.  This component uses an open source printf solution created by Spare Time Labs 2.0. DRSW found this implementation on github. You can find the source at https://github.com/cjlano/tinyprintf. The solution is distributed under the BSD license. This basically means that the solution is to be taken as is and the author is not responsible under any circumstances for its use.

   


The project builds with 1656 bytes flash used with the UART and tinyprintf components initialized. With all the examples the project takes 3912 bytes of flash.

   

 

   

Regards,

   

Asha

8 Replies
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

Do you know whether this also works on the PSoC3 and 5? Would be useful there too...

0 Likes
Anonymous
Not applicable
        Very nice, shall be able to use it for the next project.   
0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

I already adapted and used it for a PSoC4 and it will work for any other PSoC as well.

   

 

   

Bob

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

Yes, I just checked: Avagadro posted May, 22nd a link to the tinyprintf library and since that time I use it for PSoC4.

   

Since I am quite content with the implementation of printf() in PSoC3 and 5 I didn't change something there.

   

 

   

Bob

0 Likes
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored
        I was just asking because now and then the question comes up how to save flash memory on PSoC3 or 5. So now there is one more answer in our toolbox 🙂   
0 Likes
Anonymous
Not applicable

 I am really glad someone has done something about this as I really need to be able to send data to a terminal in the PSoC4.  But I have loaded the project as is in the zip and I get compile errors.  I am using a PSoC4 kit and it has been working otherwise.  Here are the errors:

   

Error1:

   

An error occurred when binding instance "PSoC_4_Pioneer_Kit_1" of symbol "PSoC_4_Pioneer_Kit": (Unable to locate and customize component 'PSoC_4_Pioneer_Kit' used in schematic 'D:\Users\Sean\Documents\Cypress Projects - Examples\Psoc4 - tiny printf\PSoC4_printf.cydsn\TopDesign\TopDesign.cysch'.).

   

Error 2:

   

Every signal bit must have exactly one driver (e.g., connected to one schematic input terminal or one instance output terminal). The given bits do not have any drivers. Add drivers for the indicated signal bits.

   

Error3:

   

An error occurred trying to retrieve the DRCs for an instance, 'PSoC_4_Pioneer_Kit_1'. Unable to locate and customize component 'PSoC_4_Pioneer_Kit' used in schematic 'D:\Users\Sean\Documents\Cypress Projects - Examples\Psoc4 - tiny printf\PSoC4_printf.cydsn\TopDesign\TopDesign.cysch'.

   

 

   

Any help would be greatly appreciated especially if it is quick! 🙂

   

Sean

0 Likes
Anonymous
Not applicable

 Never mind.  I used an updated project here: http://www.element14.com/community/message/78621#78621/l/psoc-4-pioneer-kit-community-project023-tin...

   

It worked just fine.  Now if only there were clear instructions on what needs to be copied over to my existing project! 🙂  Sorry but some of this stuff is new to me.

0 Likes
DiBr_284171
Level 2
Level 2
First question asked 10 replies posted 5 replies posted

Very nice thanks !  Before your posting I used the following functions (an impementation of  itoa) to my programs to get arount one of the sprintf issues. Lookinf forward to using tinyprintf.

   

/**
     * C++ version 0.4 char* style "itoa":
     * Written by Lukás Chmela
     * Released under GPLv3.
     * http://www.jb.man.ac.uk/~slowe/cpp/itoa.html
     */
    char* itoa(int value, char* result, int base) {
        // check that the base if valid
        if (base < 2 || base > 36) { *result = '\0'; return result; }
   
        char* ptr = result, *ptr1 = result, tmp_char;
        int tmp_value;
   
        do {
            tmp_value = value;
            value /= base;
            *ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz" [35 + (tmp_value - value * base)];
        } while ( value );
   
        // Apply negative sign
        if (tmp_value < 0) *ptr++ = '-';
        *ptr-- = '\0';
        while(ptr1 < ptr) {
            tmp_char = *ptr;
            *ptr--= *ptr1;
            *ptr1++ = tmp_char;
        }
        return result;
    }

0 Likes