Dual-Interface Bootloader: Unable to load on either interface

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
KyTr_1955226
Level 6
Level 6
250 sign-ins 10 likes given 50 solutions authored

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%20Int...

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!

0 Likes
1 Solution
Alakananda_BG
Moderator
Moderator
Moderator
50 likes received 250 sign-ins 250 replies posted

Hi,

I have attached the screenshot of the code, where you had given write inside the read function, due to which you were getting constant repeating serial data.

Please do the change as shown in the screenshot below in your code and it should work.

pastedImage_0.png

Regards

Alakananda

Alakananda

View solution in original post

0 Likes
2 Replies
Alakananda_BG
Moderator
Moderator
Moderator
50 likes received 250 sign-ins 250 replies posted

Hi,

I have attached the screenshot of the code, where you had given write inside the read function, due to which you were getting constant repeating serial data.

Please do the change as shown in the screenshot below in your code and it should work.

pastedImage_0.png

Regards

Alakananda

Alakananda
0 Likes

Alakananda,

You're absolutely right. 

Well don't I feel silly now...

What a brain-fart on my end, it was staring me right in the face!

Probably should have waited a day before posting a thread, this is absolutely something one would catch after taking a break and looking at it again fresh.

Sometimes a 2nd pair of eyes will notice what's been you've been looking right past the entire time.

0 Likes