1.5.4 Bootloader User SW Interface

The MCC generated project is designed to give the user an example of how to create a bootloader and accompanied application program within the MCC framework. MCC will generate the bootloader code and create a buildable and runnable project out of the box. The bootloader project starts in main() and uses the below functions. A listing of the generated code can be found at the link Bootloader Demo Project

void BOOT_DEMO_Tasks()

void BOOT_DEMO_Tasks() is the first bootloader call made in the demo. The code first determines if the user is requesting to enter bootloader mode by calling EnterBootLoadMode(). If this is true, then the bootloader is entered. If bootloader mode is not being requested, the firmware then verifies the bootloader by calling VerifyApplication(). If this returns false, it implies there is not a valid application image in flash and it also jumps to the bootloader. Otherwise, it jumps to the application program.

void BOOT_DEMO_Initialize()

This routine does any extra initialization needed by the bootloader.

void RunBootLoader()

This is a in infinite loop that will continue to process bootloader commands sent over the bootloader communication device.

bool EnterBootLoadMode()

This routine is responsible for checking for some type of user indication on whether to enter bootloader mode or not. At the beginning of the bootloader code, this function is called to determine if the firmware needs to download a new application before proceeding to the real application. For the demonstration code, this is done by checking on the status of a GPIO pin. If the GPIO pin is asserted, then the bootloader code is entered. If not, then the bootloader code will continue to verify the application code. The user could easily modify this code to check for traffic on a UART or something else just as easily. All the function needs to do at the end is to return true if the bootloader should switch to the bootloader kernel or continue on with the normal boot sequence.

bool VerifyApplication()

This routine is called to verify that the code in flash is a valid. The default generated example code just checks to see if the first address in the application code space is not 0x00FFFFFF. Since this is the last address programmed by the PC flash programming tool, if this address is valid that means all preceding locations must have been programmed. A more complete solution would also perform a checksum of the flash memory and compare it against expected checksum. If the call to VerifyApplication() fails, it will return false which will then force the bootloader to enter the bootloader mode.

void BOOT_StartApplication()

Once the bootloader is done running and it has found that there are no external requests to enter the firmware download mode and that the current application is valid, the bootloader jumps to the routine BOOT_StartApplication(). BOOT_StartApplication() will jump to the address in the Application space which was entered in the MCC bootloader build screen. If the user has enabled any specific peripherals or configured the GPIOs in the bootloader, these settings will remain and may need to be changed by the application code. This is further discussed in Application Development Considerations