how to jump to Bootloadable application program in case of using Bootloader

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

cross mob
YoIs_1298666
Level 5
Level 5
250 sign-ins 100 replies posted 100 sign-ins

Hello,

I am trying the Bootloader and the Bootloadable programs of "USB HID Bootloader".

If the SW_2 is pushed, the Bootloader is executed and the Bootloadable application is programmed by using the Bootloader Host.

If it is not pushed, the Bootloadable application is executed directly.

Please see main.c of the Bootloader below. It can run well.

I wonder if this is correct. Please tell me if there is something that I should bring.

int main()

{

    /* Indicates that the bootloader is running. */

    PWM_Start();

    PWM_TriggerCommand(PWM_MASK,PWM_CMD_START);

    if(Pin_SW_Read()== 0){

        /* Enters the bootloader to wait for the application update. */

        Bootloader_SET_RUN_TYPE(Bootloader_START_BTLDR);

        Bootloader_Start();

    }

    else{

        Bootloader_SET_RUN_TYPE(Bootloader_START_APP);

        Bootloader_Start();

    }

    /* Bootloader_Start() never returns. */

    for (;;)

    {

    }

}

無題1.png

Best regards,

Yocchi

0 Likes
1 Solution

Hello Yocchi-San,

Please make use of appended code and attached workspace.

#include <project.h>

#define Bootloader_activeApp      (Bootloader_MD_BTLDB_ACTIVE_0)

int main()

{

    /* Place your initialization/startup code here (e.g. MyInst_Start()) */

    CyGlobalIntEnable;

    if(Pin_Read()==0)

    {

        /* Turn on blue LED */

        Bootloader_Status_Blue_Write(0u);

        CyDelay(500);

      

        /* Start bootloader communication. This will wait for bootloading as configured by Wait for command*/

        Bootloader_Start();

    }

    else

    {

        /* Turn on red LED */

        Bootloader_Status_Green_Write(0u);

        CyDelay(500);

        

      

        /* Validate and schedule bootloadable. Perform software reset*/

        if(CYRET_SUCCESS == Bootloader_ValidateBootloadable(Bootloader_activeApp))

            {

                Bootloader_SET_RUN_TYPE(Bootloader_SCHEDULE_BTLDB);

                CySoftwareReset();

            }

                      

      

    }

  

    for(;;)

    {

        /* Place your application code here. */

    }

}

View solution in original post

7 Replies
NoriTan
Employee
Employee
25 sign-ins 5 questions asked 10 sign-ins

Maybe you are looking for this API function.

void Bootloader_Exit (uint8 appId)

Schedules the specified application and performs a software reset to launch a specified application.

If the specified application is not valid, the Bootloader (the result of the ValidateBootloadable() function execution returns other than CYRET_SUCCESS, the Bootloader application is launched.

Parameters:

appId

The application to be started:

□ Bootloader_EXIT_TO_BTLDR - The Bootloader application will be started on a software reset.

□ Bootloader_EXIT_TO_BTLDB;

□ Bootloader_EXIT_TO_BTLDB_1 - Bootloadable application # 1 will be started on a software reset.

□ Bootloader_EXIT_TO_BTLDB_2 - Bootloadable application # 2 will be started on a software reset. Available only if the "Dual-application" option is enabled in the component customizer.

These descriptions come from the "Bootloader and Bootloadable component datasheet v1.5"

Regards,

Noriaki

0 Likes
GeonaP_26
Moderator
Moderator
Moderator
250 solutions authored 100 solutions authored 50 solutions authored

Hello Yocchi-San,

Inorder to directly execute the the Bootloadable application, schedule Bootloadable and perform software reset. It is recommended to validate the application before scheduling the application.

When SW_2 is pushed, use Bootloader_Start(). It will validate the application, run communication subroutine, wait for bootloading, schedule the Bootloadable and reset the device.

0 Likes
YoIs_1298666
Level 5
Level 5
250 sign-ins 100 replies posted 100 sign-ins

Hello geon,

Please tell me the example code concretely.

Best regards,

Yocchi

0 Likes

Hello Yocchi-San,

Please make use of appended code and attached workspace.

#include <project.h>

#define Bootloader_activeApp      (Bootloader_MD_BTLDB_ACTIVE_0)

int main()

{

    /* Place your initialization/startup code here (e.g. MyInst_Start()) */

    CyGlobalIntEnable;

    if(Pin_Read()==0)

    {

        /* Turn on blue LED */

        Bootloader_Status_Blue_Write(0u);

        CyDelay(500);

      

        /* Start bootloader communication. This will wait for bootloading as configured by Wait for command*/

        Bootloader_Start();

    }

    else

    {

        /* Turn on red LED */

        Bootloader_Status_Green_Write(0u);

        CyDelay(500);

        

      

        /* Validate and schedule bootloadable. Perform software reset*/

        if(CYRET_SUCCESS == Bootloader_ValidateBootloadable(Bootloader_activeApp))

            {

                Bootloader_SET_RUN_TYPE(Bootloader_SCHEDULE_BTLDB);

                CySoftwareReset();

            }

                      

      

    }

  

    for(;;)

    {

        /* Place your application code here. */

    }

}

Hello geon,

Thank you for your support.

In conclusion, I simplified the code that you sent me.

It can run well. Is this right?

int main()

{

    /* Indicates that the bootloader is running. */

    PWM_Start();

    PWM_TriggerCommand(PWM_MASK,PWM_CMD_START);

    if(Pin_SW_Read()== 0){

        /* Schedules the Bootloader for the application update. */

        Bootloader_SET_RUN_TYPE(Bootloader_SCHEDULE_BTLDR);

        CySoftwareReset();

    }

    else{

        Bootloader_Start();

    }

    for (;;)

    {

    }

}

Best regards,

Yocchi

Hello Yocchi-San,

Yes. As we discussed it is always recommended to validate the bootlodable application before scheduling.

Hello geon,

I really appreciate your help.

Best regards,

Yocchi

0 Likes