1 Reply Latest reply on Sep 6, 2020 12:56 AM by AashitaR_11

    USB HID Bootloader- CE95391, I do not undestand bootloader code




      In my application I need a USB bootloader. I know that USB could takes time to enumerate so I try to avoid this issu with a switch between the bootloadable and the bootloader.


      I undestand that the Bootloadable_Load() in the bootloadable main.c is use to go to the bootlader.


      but I do not understand the code in the bootloader example :



      if((Wait_Forever_Read() == 0/*Pressed*/) || (BL_GET_RUN_TYPE == BL_START_BTLDR))









      -> why the bootloader have a "button test" ? the button test on the bootloadable is not enought ?


      -> i do not understand the other part of the if test : (BL_GET_RUN_TYPE == BL_START_BTLDR)

      and what this one does : BL_SET_RUN_TYPE(BL_START_BTLDR);  ?


      Thank you for your help

        • 1. Re: USB HID Bootloader- CE95391, I do not undestand bootloader code

          Hi ThBi_3905606,


          In the code example CE95391, the button test is used in the Bootloader Project for the Bootloader to wait for the command from the host to start the Bootloader and load a new Bootloadable project. When the kit button is pressed which means it is short to ground, it puts the wait forever pin state to be at 0. In the bootloader project of this code example, the wait for command parameter is enabled for the bootloader component. The zero value for this command is interpreted as wait-forever. You can read the description for the 'wait for command time' parameter in the bootloader component's  datasheet.


          In short, when the kit button is kept pressed after the device reset, the bootloader waits for the command from the host till the button is pressed. Unlike this, the kit buttons used in the Bootloadable project is to switch between the Bootloadable project and the Bootloader project as you can find clearly under the 'Operation' section of the documentation here : https://www.cypress.com/documentation/code-examples/ce95391-psocr-usb-hid-bootloader




          if((Wait_Forever_Read() == 0/*Pressed*/) || (BL_GET_RUN_TYPE == BL_START_BTLDR))





          The above lines of code check any of the two conditions to be true before starting the bootloader component. The conditions are:

          1. If the kit button is pressed after device reset and thus, wait forever pin is at state 0, it is waiting for the host to send commands.

          2. If the PC host has already sent command i.e BL_START_BTLDR, the BL_SET_RUN_TYPE starts the bootloader component.


          BL_GET_RUN_TYPE is a macro which basically decides how to proceed with the Bootloader Component.

          Please go through the above explanation and let us know in case of further clarifications.


          Best Regards,