Skip to content

Using the disable bootloader feature

Paulo Matias edited this page Oct 21, 2013 · 1 revision

Introduction

The --disable-bootloader option can be used to set the device in such a way that it will cause the bootloader to be skipped. This way, you can save 5 seconds of device boot time which would otherwise be taken by the bootloader.

This option should be used with caution. If something goes wrong, you will need a JTAG programmer to fix things up. But the purpose of UHB is, in first place, to avoid to using JTAG, so let us take some steps to make this process the safest possible.

Create a way to call the bootloader from your program

Make sure there is a way to call the bootloader from inside your program once it is loaded. For example, if you use USB HID communication in your program, you can define some command which would quit your application and start the bootloader.

The code below is an example on how to call the bootloader in a STM32F407VG device. It is meant for gcc (just change the asm syntax if you are using mikroC). It should be easy to adapt to other ARM microcontrollers, just remember to fix the bootloader code position in memory and the stack pointer (which in this example are 0x000e0001 and 0x2001fffc, respectively).

static __attribute__((noreturn)) void enter_bootloader(void) {
    int i;

    // Disable USB HID
    // (not needed if you are not using USB HID in the first place)
    HID_Disable();

    // Delay
    for(i = 0; i < 1000; i++)
        asm("nop");

    // Jump to bootloader
    asm(
        "movw r0, #0xfffc   \n\t"
        "movt r0, #0x2001   \n\t"
        "mov sp, r0         \n\t"
        "movw r0, #0x0001   \n\t"
        "movt r0, #0x000e   \n\t"
        "bx r0"
    );

    while(1); // Should never be reached
}

Test it

Remember to first program the device without using the --disable-bootloader option, and then to test the means you created to enter the bootloader from inside your program.

You can check if it is working by letting mikroe-uhb run waiting for the bootloader, and then entering the bootloader from inside your program (not by resetting the device or by replugging the USB cable).

Only then, disable the bootloader

Reprogram your device with the same hex file, but now using the --disable-bootloader option.

Test again if you make any changes to your program

To be safe, never program using --disable-bootloader a hex file which you did not test before.