n00b: how to create basic debug feedback with PSOC Creator? similar to printf or serial.print on Arduino?

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

cross mob
DaVi_4379521
Level 1
Level 1
First like received

Hello All!

Is there a way I can echo simple printf commands inside the IDE for debugging purposes?

With Arduino I use serial.print() religiously to debug programs as I work.   Seeing what's inside variables, creating breakpoints to see if a program has gone awry, etc.

I've tried to replicate that approach with my CY8CKIT-059, but the USB UART serial interface is much more complex.  As I learn it, I'm trying to debug it too (LOL!)

0 Likes
1 Solution
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

Yes, it's the first trap I was caught, too 😉

As far as I know of, there are at least two approaches we could take

(1) use printf with changing the configuration (USBUART)

(2) use UART_PutString() (any UART)

For (1) There is an AN "KBA89724", it uses USBUART.

I also posted a topic regarding to this.

printf and float rhapsody (aka, yet another printf and floating topic)

I'd recommend you to use USB-Serial function of KitProg

As I don't want to connect 2 cables to CY8CKIT-059.

For (2), I'd do something like below

schematic

000-schematic.JPG

Pin List

001-pin-list.JPG

Then change some build settings, if you need to support "float"

From the menu  Project > Build Settings...

Select ARM GCC xxx > Linkder > Command Line, then add Custom Flags

Add "-u _printf_float" for print, sprintf, and "-u _scanf_float" for scanf, sscanf.

002-Build_Settings_ARM_GCC_xx_Linker_Command_Line.JPG

Similarly in the Linker > General

Set "Use newlib-nano Float Formatting" to True

002-newlib_nano_printf_float.JPG

As floating point requires more memory, we also need to change the heap size

Select and double click to open Workspace Explorer > <the project> > Design Wide Resources

003-System.JPG

Then change the Heap Size bigger, the default is 0x80, I changed it to 0x400 here

005-HeapSize.JPG

Now, the program

main.c

=================

#include "project.h"

#include "stdio.h"

char str[64] ; /* print buf */

void print(char *str)

{

    UART_PutString(str) ;

}

int main(void)

{

    int icount = 0 ;

    float fcount = 0.0 ;

    CyGlobalIntEnable; /* Enable global interrupts. */

    UART_Start() ;

    sprintf(str, "UART Test (%s %s)\r\n", __DATE__, __TIME__) ;

    print(str) ;

    for(;;)

    {

        sprintf(str, "counts: %5d, %5.2f\r\n", icount, fcount) ;

        print(str) ;

        icount++ ;

        fcount += 0.01 ;

        CyDelay(1000) ; /* wait 1000ms = 1 sec */  

    }

}

=================

I used "Tera Term" for the serial terminal, and the output was

007-TeraTerm-log.JPG

moto

View solution in original post

0 Likes
1 Reply
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

Yes, it's the first trap I was caught, too 😉

As far as I know of, there are at least two approaches we could take

(1) use printf with changing the configuration (USBUART)

(2) use UART_PutString() (any UART)

For (1) There is an AN "KBA89724", it uses USBUART.

I also posted a topic regarding to this.

printf and float rhapsody (aka, yet another printf and floating topic)

I'd recommend you to use USB-Serial function of KitProg

As I don't want to connect 2 cables to CY8CKIT-059.

For (2), I'd do something like below

schematic

000-schematic.JPG

Pin List

001-pin-list.JPG

Then change some build settings, if you need to support "float"

From the menu  Project > Build Settings...

Select ARM GCC xxx > Linkder > Command Line, then add Custom Flags

Add "-u _printf_float" for print, sprintf, and "-u _scanf_float" for scanf, sscanf.

002-Build_Settings_ARM_GCC_xx_Linker_Command_Line.JPG

Similarly in the Linker > General

Set "Use newlib-nano Float Formatting" to True

002-newlib_nano_printf_float.JPG

As floating point requires more memory, we also need to change the heap size

Select and double click to open Workspace Explorer > <the project> > Design Wide Resources

003-System.JPG

Then change the Heap Size bigger, the default is 0x80, I changed it to 0x400 here

005-HeapSize.JPG

Now, the program

main.c

=================

#include "project.h"

#include "stdio.h"

char str[64] ; /* print buf */

void print(char *str)

{

    UART_PutString(str) ;

}

int main(void)

{

    int icount = 0 ;

    float fcount = 0.0 ;

    CyGlobalIntEnable; /* Enable global interrupts. */

    UART_Start() ;

    sprintf(str, "UART Test (%s %s)\r\n", __DATE__, __TIME__) ;

    print(str) ;

    for(;;)

    {

        sprintf(str, "counts: %5d, %5.2f\r\n", icount, fcount) ;

        print(str) ;

        icount++ ;

        fcount += 0.01 ;

        CyDelay(1000) ; /* wait 1000ms = 1 sec */  

    }

}

=================

I used "Tera Term" for the serial terminal, and the output was

007-TeraTerm-log.JPG

moto

0 Likes