7 Replies Latest reply on Feb 26, 2019 10:45 PM by himam_31

    Re-program from within application


      I have a PSoC5LP application which includes  bootloader and bootloadable components. On power-up, the bootloader checks the state of a  pushbutton. If the pushbutton is pressed, it enters the boot mode  and waits indefinately for data over the USB to reprogram the application. Whilst in boot mode, a LED flashes indicating that it is in boot mode. This works perfectly as intended.

      I have a C# project running on my PC which is based on the 'USBBootloaderHost_VC2015' application contained in USBBootloaderHost_VC2015.zip which is attached to application note AN73503_USB_HID_Bootloader_for_PSoC_3_and_PSoC_5LP_0.pdf downloaded from the Cypress web site.

      I can successfully program the PSoC5LP device by switching it into boot mode as described above and running the PC application which verifies that the PC application is running correctly.

      I want to be able to send a command over the USB while the PSoC5LP is running the application, to tell it to switch into boot mode to allow me to upload a firmware update.

      The way I am trying to accomplish this is for the PC to send a text string "Program" via the USB to the PSoC5LP. When the PSoC5LP receives this string, it responds with "Ok". The PSoC5LP shuts down all the peripherals, and calls Bootloadable_1_Load(); which forces a reset into boot mode. indicated by the LED flashing.

      Meanwhile, when the PC receives the "Ok", it waits for 5 seconds to allow the PSoC5LP to switch into boot mode, then starts the reprogram sequence which fails on attempting to send the first block of data.

      I have a USB analyser connected between the PC and the PSoC5LP, so I am able to monitor all the USB communications.

      I can see the "Program" string and the "Ok" response  followed 6 seconds later by a number of descriptor blocks, but no data blocks.

      Putting a breakpoint in the PC software following the  line 'status = BootloaderHIDDevice.WriteOutput();' in the WriteData function, I can see that it returns a status of false.

      What is going wrong?!

        • 1. Re: Re-program from within application



          I assume that you have USB component in the application as well. Have you configured the USB device in application as HID? Are you able to see the USB Bootloader HID device getting enumerated after the switching? For starting the bootload process, host should send "Enter Bootloader Command" Did the application send the command?


          Can you attach the screenshot of the USB trace?




          • 2. Re: Re-program from within application

            I have a USB component in both the bootloader and the application. Both are configured as a HID device with the same VID and PID and device number.

            In the USB Bootloader Host program running on the PC, GetHidDevice() is called at the start of the function 'WriteData. which returns 'true' which, I assume, means that the USB device has been enumerated successfully. 


            I do not understand your question "For starting the bootload process, host should send "Enter Bootloader Command" Did the application send the command?"

            The host software sends the text string "Program" to the PSoC application.   The application recognises this string and returns the string "Ok" then calls Bootloadable_1_Load(); to switch it into boot mode.

            I can verify that this is happening by the fact that the PC receives the string "Ok" and the LED on the PSoC flashes indicating that it is in boot mode.


            USB analyser screen dump attached. If you need any more detail I can expand and highlight any transactions or provide the whole transfer as a XML file. Please note - only complete, acknowledged transactions are shown. USB transactions.jpg

            • 3. Re: Re-program from within application


              Since my last post, I have tried a number of things, none of which appear to have made any difference. They are:

              Giving the USB component in the boot loader and the USB component in the application different serial numbers.

              Adding calls to CyGlobalIntEnable and USBFS_Start to the boot loader.

              Forcing a disconnect of the USB device in the PC software after receiving "Ok" from the PSoC and reconnecting at the start of the Program sequence.

              As I said, none of these changes has got me any closer to re-programming the chip.


              Any suggestions what the problem might be?

              • 4. Re: Re-program from within application

                Can we see the packets which are NACKed. I want to check the USB data transfer between host and device after reset and enumeration. Can you try using the default Bootloader Host tool available with PSoC Creator (After the reset and device in bootloader host mode ).




                • 5. Re: Re-program from within application

                  Hello Hima

                  As requested, attached are screenshots uf the USB transactions showing the NAK'd transactions. NAK'd transactions are identified by a red arrow on the icon in the leftmost column. All NAK transactions consist of an empty IN transaction followed by a NAK packet. One of the NAK transactions is expanded to show this. The number in parenthesis after 'IN Transaction' in column 2 indicates the number of NAK'd transactions sent.

                  The third screenshot shows when the application is run and controlled by the custom PC software, showing the 'Program' and 'ok' "handshake" strings, putting the board into boot mode followed by the PC executing it's version of 'Bootloader Host' as described in an earlier post, which results in a few GetDescriptor transactions followed by nothing apart from a "Programming Failed" message! The program hangs.

                  In comparison the first and second screenshots shows the communication when, as before, the application is run and controlled by the same custom PC software to set the board into bot mode. A breakpoint in the PC software now stops further execution of the custom software. At this point the 'Bootloader Host sofware from within PSoC Creator 4.2 is used to program the board in the same way as would have been done if the board had been switched on in boot mode. The programming of the board now runs successfully to completion.

                  The third screenshot is a continuation of the second and shows in the last two lines the start of the program data being transferred to the targetCapture-4.pngCapture-5.png


                  • 6. Re: Re-program from within application

                    I have found a solution to my problem. It appears to be linked to the way I am generating the 5 second delay in my PC program, and the period of the delay.

                    I was using a thread.Sleep(5000); instruction to generate the delay. I have now modified my program so that it uses a timer to generate the delay, but a delay of 5 seconds still caused an error.

                    Looking at the data on the USB analyser, I could see a reset lasting for 6.7 seconds following the receipt of the "Ok" response from the PSoC indicating that the device was held in reset for this period when switching into boot mode. This was also indicated by a delay of around 6 seconds between the PSoC application program stopping, and the LED starting to flash indicating that the device was in boot mode.

                    Increasing the delay in my PC program to 8 seconds resulted in the program running without error.

                    Thank you for all your help so far. I would welcome any comments on my findings.

                    Below is a screenshot of the USB transactions using an 8 second timer delay, showing the 6.7s reset with the remainder taken up in multiple NAK'd IN transactions at t=69.261701


                    • 7. Re: Re-program from within application

                      Thank you for sharing this. We are glad that the issue has been resolved.