10 Replies Latest reply on Jun 18, 2015 4:13 PM by ken.arton

    Debugging PSoC4 "on the fly" ?




      I've been working on a frequency counter project using PSoC4, and it is now nearing completion.  It uses feedback via the code to keep the frequency locked to a target value.  It is working quite well, but I'd like to be able to capture in detail what is going on when the code is correcting for frequency error.

      Of course I can, and have, used the normal debug facilities to halt execution and display the current value of selected variables, but this is of little help in understanding the operation of a feedback loop.

      What I really want is to capture some variable values on the fly without halting execution, or at least without causing too much execution delay.  Given that an SWDIO/SWDCLK link is in place for debug, I feel that this should be possible.  At the PC end the PSoC Creator program would need to capture values and write them to a file so that I could analyse them later.  I would limit execution to a few hundred loops, so the file would not get too large.

      I have done this kind of thing with other programs in the past, but running on the PC itself, just by inserting a Write to File command at required places in the code.  So I am wondering if something similar would be possible with an external microprocessor.

      Does anyone have suggestions or ideas on this?
      Or perhaps it's just not possible ?


      Thank you for any advice.   Ken.


        • 1. Re: Debugging PSoC4 "on the fly" ?

          When using a CY8CKIT-042 or -044 for developing, you could use an UART connected to the KitProg of the development kit. On the PC-side you may run PuTTY or a self-written program reading data from com-port and writing it to a file.


          When there is room enough in sram (the -044 has some more) you may use a large UART-Tx buffer to keep the system undisturbed by the transmission.





          • 2. Re: Debugging PSoC4 "on the fly" ?

            Any chance you can add a UART into design to output data ?


            UART takes care of itself once you write its FIFO.




            You could consider Python programming the SWD interface, thsi manual


            discusses the commands SWD can use and access M0 silicon.








            Regards, Dana.

            • 3. Re: Debugging PSoC4 "on the fly" ?

              Thanks both for prompt replies.

              This is encouraging, as you are confirming that it is possible.
              I'm using the CY8CKIT-049-42xx as the functional device, and programming it via
              a CY8CKIT-042 4 Pioneer Kit with the programming connections tapped off. 

              Your comments about using a UART have prompted me to read the section 3.3 in CY8CKIT-042 PSoC 4 Pioneer Kit Guide, Doc. # 001-86371, on USB-UART Bridge.
              This seems to say that UART functionality is already built-in on the CY8CKIT-042 board.
              Is that correct ?
              If so, then I just need to connect the RX and TX lines as instructed, then follow the instructions in section 6.1.  I'm not sure if I have HyperTerminal, but can easily download PuTTY if necessary.

              I could have worked this out for myself, but had paid no attention to the UART stuff, as I was not aware of its purpose.

              I guess your suggestion to program the SWD interface, using Python, is an alternative to using a UART.  I've downloaded the programming spec, but will try the UART route first

              It might take me a little while for me to work through this, but I will update the post with my progress.

              Many thanks for your help.   Ken.

              • 4. Re: Debugging PSoC4 "on the fly" ?

                The 042 board has not only a PSOC 4 on it but a 5LP. The 5LP acts


                as proigrammer/debugger. But you can create a different program


                with it, and use a serial connection to the 4, and a USBUART or just


                UART to the PC. Note once you reporgram the 5LP you can no longer


                debug the PSOC 4 unless you reprogram the 5LP with its "normal"










                You could ask Cypress for the source, and mod that firmware to both


                debug and add the link to the 4.




                 Note you can do a USBUART bridge to 4 or an I2C bridge to 4.








                Regards, Dana.

                • 5. Re: Debugging PSoC4 "on the fly" ?

                  There is a documentation (with pictures) on how to use the UART interface of a -042 Kit and PuTTY, quite easy.


                  Cypress has an FRam-kit and uses this feature to prove its working. The documentation shows  (page 28) the FRam-kit stuck on top of the -042 and 2 wire-bridges which in real do not use the FRam-Kit but an interconnection of the -042.





                  • 6. Re: Debugging PSoC4 "on the fly" ?

                    Thanks again to you both for this further info.

                    I think I'll first try Bob's suggestion, as in fact I think it is the same
                    as I have found in the CY8CKIT-042 PSoC 4 Pioneer Kit Guide.  The documentation link
                    to FRam Kit contains useful stuff on using PuTTY (which I have now downloaded), so thanks
                    for that.

                    Best regards,   Ken.

                    • 7. Re: Debugging PSoC4 "on the fly" ?



                      An update on progress with Uart etc.


                      First, I tried implementing the UART function as you suggested, but could not get it to work.  I then spotted the comment in the datasheet that UART is not available on PSoC4, so gave up on this fairly quickly.  Your earlier posts seemed to say it should work, so I'm confused now regarding UART.
                      I then tried I2C, ie the USB-I2C Bridge, with Bridge Control Panel.


                      Because my target PSoC4 device is not on same board as the PSoC5, I had to make some mods to the CY8CKIT-042  PSoC 4 Pioneer Kit board.  I removed zero ohm resistors R24 and R25, which route the I2C lines to the on-board PSoC4, and attached wires to connect to the off-board target PSoC4.  I first connected them to pins P3_0 and P3_1 as that is where they go for on-board PSoC4, but this did not work.  So I then tried pins P4_0 and P4_1, and now it worked !  In the .cydwr file the P3_0 and P3_1 pins are labelled SCB1, while the P4_0 and P4_1 pins are labelled SCB0.  I don't understand what the difference is, nor why SCB0 is OK but SCB1 is not.


                       [ As an aside, it was very fiddly to mod the board -- it would be nice if it had jumpers and connectors to do the job ]

                      Anyway, I can now capture data from my running PSoC4 chip.

                      My problem now is getting the data out in the right format.
                      I have used the code snippet in CY8CKIT-042 PSoC 4 Pioneer Kit Guide, which works, but seems to capture only one byte rather than the whole variable value.  The detailed info on the SCB APIs in the datasheet is not of much help.  I have tried playing about with, eg, read buffer size, but to no avail.  I'm fairly sure it's my code that need fixing, rather than anything in the Bridge Control Panel.

                      On each pass through a forever loop I need to capture a mix of:
                              Integer numbers,  Floating point numbers, and Character strings.

                      I wonder if you can point me to some example code which would help me to understand what I need to do ?

                      Many thanks,   Ken.

                      • 8. Re: Debugging PSoC4 "on the fly" ?

                        "I then spotted the comment in the datasheet that UART is not available on PSoC4, so gave up on this fairly quickly."


                        That was quite too quickly! Of course there are UARTs within a PSoC4, even several and when using a PSoC 42xx even several different ones!


                        Despite from the connection of your Pioneer board and your own pcb you always have the chance to use two pins of your board as Rx and Tx of an UART running at 115200Baud and with a fairly large buffer to avoid blocking and connecting the two pins to the Pioneer Kit PSoC5 Rx and Tx pins on J8(9) and J8(19) and a GND connection..


                        Follow all the advices given in the Pioneer Kit Guide concerning the USB-UART bridge.





                        • 9. Re: Debugging PSoC4 "on the fly" ?

                          Hello again,

                          Thanks Bob for your further comments on UART.
                          However, I have invested quite a lot of time in getting the USB-I2C route working, and don't want to abandon this and start again with UART, unless there is a really good reason to do so.

                          USB-I2C used with the Bridge Control Panel works fine, and does not seem to slow down the execution time.

                          However, I do still have a problem as mentioned in my previous post, of getting the data out. The I2C link handles data a byte at a time.  If the variable I am monitoring, target_variable, is one byte ( ie type uint8 ) there is no problem.  But if it is more than one byte, eg type int or float, then I cannot for the life of me work out how to get the link to access anything other than the first byte (LSbyte).

                          Here is a snippet of code to try to read target_variable where it is type uint16 (two bytes):

                           uint8 rdBuf[10];     // I2C read buffer.  I assume this must be uint8 since I2C handles bytes.
                           while(1u)       // Loops forever.
                                 byteCnt = 2;
                                 indexCntr = 0;
                                 for(indexCntr=0; indexCntr<byteCnt; indexCntr++)  rdBuf[indexCntr] = target_variable;
                                   // etc
                          It is obvious that above will just read the same byte twice.
                          I have tried using pointer constructions, but there just seems to be no way to get at the "internal" bytes of a multi-byte variable.

                          My C knowledge is very limited, and I am clearly missing something quite basic.
                          Can anyone offer advice on this, or even better direct me to existing code which uses USB-I2C to capture integers and floating point numbers.

                          Many thanks,   Ken.

                          • 10. Re: Debugging PSoC4 "on the fly" ?

                            You need to retreive the msb and the lsb in two different variable.


                            Here is an example:


                            rdBuf[indexCntr] = target_variable & 0xFF;//Retreive LSB


                            rdBuf[indexCntr + 1] = (target_variable & 0xFF) >> 4 ;//Retreive MSB