Default interfaces for STDIN, STDOUT and STDERR on PSoC?

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

cross mob
RaAl_264636
Level 6
Level 6
50 sign-ins 25 sign-ins 10 solutions authored

Hi,

   

 

   

perhaps a dumb question, but does anybody know to which interfaces the STDIN, STDOUT and STDERR streams are going on PSoC? Is this documented anywhere?

   

 

   

Regards,

   

 

   

Ralf

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

There is no OS for a PSoC. Hence there are no STDxxxes. When you want to send a message from your Cypress development or prototyping kit to the PC screen use a UART, sprintf() and send the buffer to the UART yourself. There is an integrated USB-UART bridge in the Kitprog part of those boards that allows to connect to terminal emulation programs as PuTTY.

   

 

   

Bob

View solution in original post

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

There is no OS for a PSoC. Hence there are no STDxxxes. When you want to send a message from your Cypress development or prototyping kit to the PC screen use a UART, sprintf() and send the buffer to the UART yourself. There is an integrated USB-UART bridge in the Kitprog part of those boards that allows to connect to terminal emulation programs as PuTTY.

   

 

   

Bob

0 Likes
RaAl_264636
Level 6
Level 6
50 sign-ins 25 sign-ins 10 solutions authored

Hi Bob,

   

 

   

thank you for your answer. That means, I can implement the standard streams by rewriting the _read() and _write() functions, right?

   

I know the way with sprintf(), but I'm searching a more convenient way. Also using sprintf() needs to have a buffer available. For my current project, there's also a display with T6963C controller available, but this display has an offset for displaying the characters, so doing the character value handling in _write() seems to be the right way.

   

 

   

So, I can implement the STDIN, STDOUT and STDERR in a rewritten _write()/_read(), and add additional interfaces like the display there.

   

 

   

Regards,

   

 

   

Ralf

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

Also using sprintf() needs to have a buffer available  Consider using malloc() and free() or a construct like

   

//***********************************************************************************//
//**************** Definitions and Macros *******************************************//
//***********************************************************************************//
#define PuTTY_printf(fmt,...)        do {\
                                        sprintf((char*)PuTTY_Buffer,fmt,##__VA_ARGS__); \
                                        PuTTYx_SpiUartPutArray(PuTTY_Buffer,strlen((char*)PuTTY_Buffer));\
                                        } while(0)

   

The _write() is a comparably slow function which seemingly does only bytewise output.

   

Reading using scanf() is not supported by the small newlib nano. You will get into troubles with the smaller PSoC4 devices due to flash usage.

   

 

   

Bob

RaAl_264636
Level 6
Level 6
50 sign-ins 25 sign-ins 10 solutions authored

Hi Bob,

   

 

   
    

The _write() is a comparably slow function which seemingly does only bytewise output.

    

Reading using scanf() is not supported by the small newlib nano. You will get into troubles with the smaller PSoC4 devices due to flash usage.

   
   

Definitively something I didn't realize, thank you for pointing this out. Hmmm... I'll have to think again about a solution. Your macro definition may point into the direction I want to have - I'll try it out and report back the result. If the idea works, it might be also helpful for others.

   

 

   

Regards,

   

 

   

Ralf

0 Likes

I have used this method and it works on PSoC5LP. Remember to set heap size to 0x200 (I learned that from Bob).

   

sprintf(desc,"Azimuth: %-.6f degrees\n",azimuth); // azimuth is double floating variable
terminal_print(desc);    // invoke function to print to termina

   

// The terminal_print function can be:

   

void terminal_print(char *desc)
    {
    UART_1_PutString(desc);
    }

   

// An alternate way to send the string ...
void terminal_print(char *desc)
    {
    char *p;
    p = desc;    // pointer to beginning of string
    // The while loop ends when null (\0) end of string is found
    while  (*p) UART_1_PutChar(*p++); // Send data to terminal
    }

   

To explain the second version of the function, the while loop is saying that "While contents AT the current pointer has a non-null character, continue the while loop. Put the character to the UART. Increment pointer and continue. When a Null, signifying end-of-string is found, exit the loop."  This loop can be modified to include a length counter that increments. Upon exit the length of the string is in the length variable that you incremented in the loop. Such a modification could be a custom replacement for the string length function.

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

That code snippet is more than an "idea", it is an excerpt from a working module 😉

   

 

   

Bob

0 Likes
RaAl_264636
Level 6
Level 6
50 sign-ins 25 sign-ins 10 solutions authored
    

That code snippet is more than an "idea", it is an excerpt from a working module 😉

   
   

With "idea" I meant my idea how to realize what I want to do 😉 I don't doubt that your macro is working.

   

 

   

Regards,

   

 

   

Ralf

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

Language barrier 😉

   

 

   

Bob

0 Likes
RaAl_264636
Level 6
Level 6
50 sign-ins 25 sign-ins 10 solutions authored

@78RPM:

   

Sorry, I didn't realize your posting 😕

   

I'll take your snippet into account. My goal was to be able to use multiple interfaces with one function, that's why I asked how the standard I/Os are implemented on PSoC.

   


Regards,

   

 

   

Ralf

0 Likes