2 Replies Latest reply on Feb 17, 2020 6:06 AM by KyTr_1955226

    Dual-Interface Bootloader: Unable to load on either interface

    KyTr_1955226

      Hello!

       

      I'm currently working on creating a dual-interface (USB HID and UART) bootloader, which I made a thread about several months ago:

      https://community.cypress.com/thread/49426?q=Bootloader%20with%20both%20UART%20and%20USB%20HID%20Interfaces

       

      I'm finally getting around to implementing this, and I can't seem to get it to work correctly.  Neither the USB HID or UART interfaces are loading properly.  I have at least confirmed that saving the desired interface to an I2C FRAM in the application and loading it in the bootloader works properly, so no worries on that count.  It looks to be the actual loading that's the problem.

       

      I took the advice of the thread above, set the bootloader component to Custom Interface, and set my bootloader functions as follows using the functions generated for the PC_UART and USBFS components:

      typedef enum{
          INTERFACE_UART = 0,
          INTERFACE_HID = 1,
      } interface_t;
      
      interface_t Btldr_Interface = INTERFACE_UART;
      
      interface_t GetCommInterface (void){
          uint8_t rd_byte;
          
          FRAM_ReadBytes(&rd_byte,BTLDR_INTERFACE_ADDR,1);
          return (interface_t)rd_byte;
      }
      
      void CyBtldrCommStart (void){
          
          if (Btldr_Interface == INTERFACE_HID){
              USBFS_CyBtldrCommStart();
          } else {
              PC_UART_CyBtldrCommStart();
          }
          
      }
      
      void CyBtldrCommStop (void){
          
          if (Btldr_Interface == INTERFACE_HID){
              USBFS_CyBtldrCommStop();
          } else {
              PC_UART_CyBtldrCommStop();
          }
          
      }
      
      void CyBtldrCommReset(void){
          
          if (Btldr_Interface == INTERFACE_HID){
              USBFS_CyBtldrCommReset();
          } else {
              PC_UART_CyBtldrCommReset();
          }
          
      }
      
      cystatus CyBtldrCommWrite(uint8* buffer, uint16 size, uint16* count, uint8 timeOut){
          
          if (Btldr_Interface == INTERFACE_HID){
              return USBFS_CyBtldrCommWrite(buffer,size,count,timeOut);
          } else {
              return PC_UART_CyBtldrCommWrite(buffer,size,count,timeOut);
          }
          
      }
      
      cystatus CyBtldrCommRead (uint8* buffer, uint16 size, uint16* count, uint8 timeOut){
          
          if (Btldr_Interface == INTERFACE_HID){
              return USBFS_CyBtldrCommWrite(buffer,size,count,timeOut);
          } else {
              return PC_UART_CyBtldrCommWrite(buffer,size,count,timeOut);
          }
          
      }
      

       

       

      The main() in the bootloader is very simple:

      int main(void)
      {
          CyGlobalIntEnable; /* Enable global interrupts. */
      
          FRAM_I2C_Start();
          
          Btldr_Interface = GetCommInterface();
          if (Btldr_Interface == INTERFACE_UART){
              HB_LED_Write(1);   
          } else {
              HB_LED_Write(0);   
          }
          
          for(;;)
          {
              Bootloader_Start();
          }
      
      }
      

       

       

      I'm starting debugging with the UART interface (since it's much easier to see the data than in USB) and what I'm finding is interesting.  When I enter the bootloader, I get what appears to be constant repeating serial data coming out of the PSoC UART that I don't get when the bootloader is UART only:

      uart.png

      Here's a capture in hex:

      uart_hex.png

      I have honestly no idea what the heck the problem is.  In the previous version of this code (bootloader was UART only) there are no issues with loading, but something that I'm doing in changing it to dual-interface must be throwing it for a serious loop somewhere.

       

      I have attached an archive of the bootloader project (I can't post the app code, but it really shouldn't matter in this case)

      Might anyone have any ideas of what might be going on?

       

      Thanks in advance!