9 Replies Latest reply on May 8, 2016 11:25 PM by user_246598725

    Default interfaces for STDIN, STDOUT and STDERR on PSoC?

    user_246598725

      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

        • 1. Re: Default interfaces for STDIN, STDOUT and STDERR on PSoC?
          user_1377889

          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

          • 2. Re: Default interfaces for STDIN, STDOUT and STDERR on PSoC?
            user_246598725

            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

            • 3. Re: Default interfaces for STDIN, STDOUT and STDERR on PSoC?
              user_1377889

              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

              1 of 1 people found this helpful
              • 4. Re: Default interfaces for STDIN, STDOUT and STDERR on PSoC?
                user_246598725

                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

                • 5. Re: Default interfaces for STDIN, STDOUT and STDERR on PSoC?
                  user_1377889

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

                     

                   

                     

                  Bob

                  • 6. Re: Default interfaces for STDIN, STDOUT and STDERR on PSoC?
                    user_246598725
                        

                    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

                    • 7. Re: Default interfaces for STDIN, STDOUT and STDERR on PSoC?
                      user_1377889

                      Language barrier ;-)

                         

                       

                         

                      Bob

                      • 8. Re: Default interfaces for STDIN, STDOUT and STDERR on PSoC?
                        user_302397898

                        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.

                        1 of 1 people found this helpful
                        • 9. Re: Default interfaces for STDIN, STDOUT and STDERR on PSoC?
                          user_246598725

                          @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