Adjusting OpenBLT for your microcontroller system

The OpenBLT bootloader ships with multiple demo programs for readily available and low cost microcontroller boards. These are great for familiarizing yourself with and evaluating the OpenBLT bootloader. But how do you get the OpenBLT bootloader running on your own microcontroller system? The goal of this article is to answer exactly this question.

The approach to take and the effort required, depends on the microcontroller you selected for your system. If your microcontroller is the same or compatible with one for which demo programs are already available, then it is just a matter of some minor reconfiguration. Otherwise, new demo programs need to be created specifically for your microcontroller. The OpenBLT bootloader contains a template for creating a new demo bootloader and demo user program to assist you with this task. This assumes that your microcontroller family is already supported by OpenBLT. If this is not the case, then a new microcontroller port needs to be developed as well. A template for new microcontroller port is available, which forms a good starting point and significantly lowers the effort for this task. The following sections describe all three of these scenarios in more detail.

Reconfigure existing demo programs

If your microcontroller is similar to the one used in an existing demo program, you can use this demo program as a foundation and do some minor reconfiguration to get it working on your system. Each demo consists of two programs: a bootloader and a user program. The user program is nothing more than a minimal software program that can be programmed with the bootloader for testing and demonstration purposes.

Bootloader

Start with the “blt_conf.h” configuration header file. Update the value of macro BOOT_NVM_SIZE_KBwith the amount of internal flash memory available on your microcontroller. Continue with updating the values of macros BOOT_CPU_XTAL_SPEED_KHZand BOOT_CPU_SYSTEM_SPEED_KHZto reflect your clock configuration. Next configure the communication medium with which you intend to make firmware updates. This is done with the BOOT_COM_xxxmacros.

At the start of function main(), the demo bootloader configures the system clock to reflect what was specified by the macros BOOT_CPU_XTAL_SPEED_KHZand BOOT_CPU_SYSTEM_SPEED_KHZ. Update the system clock configuration accordingly. After this, the GPIO pins are configured. Specifically those for the firmware update communication peripheral and an LED for visual feedback. It could also be that a digital input (pushbutton) is configured for an optional backdoor into the bootloader. Update the GPIO configuration for your system. Don’t forget to enable the related peripheral clocks as well, if applicable.

As a next step, find out where the LED is controlled and update the GPIO that it is connected to. It is typically in the functions LedBlinkXxx(). If the demo bootloader support the optional backdoor entry via a digital input, update the GPIO of the digital input. It is typically in function CpuUserProgramStartHook().

User program

Repeat the steps regarding the system clock and GPIO configuration as described in the previous section for the bootloader, as these apply to the user program as well. Depending on the user program configuration, it typically supports functionality to automatically reactivate the bootloader when it detects a new firmware update request. This is implemented in the “boot.c” source-file within the user program. Check that it is configured for the correct communication peripheral and update where necessary.

In a nutshell, these are all the changes to the source code that normally need to be made to reconfigure existing demo programs for your system. The estimated time needed to complete these steps is 1 – 2 hours.

Create new demo programs

If your microcontroller is not supported by any of the demo programs, then the best way forward is by creating new demo programs, so a bootloader and a user program. Luckily, you do not need to start from scratch, as the OpenBLT download package includes templates to assist you with this task. The template can be found in directory ./Target/Demo/_template/.

The template bootloader is in sub-directory Boot/and the template user program is in sub-directory Prog/. Both templates contain an example Makefile that can be inspected to backtrack the source-files that need to be compiled and linked into the final executable. Just keep in mind that the Makefile for the template bootloader is set up to include the sources for a microcontroller family port template. You want to adjust this such that it includes the sources of the port for your microcontroller family instead.

More importantly, both templates contain special markers formatted as comments to point you to code locations that need to be updated or implemented for your microcontroller. These comments also include an explanation of what needs to be done. In the template bootloader, the marker looks like /* TODO ##Boot … */. In the template user program, the marker looks like /* TODO ##Prog … */. Refer to the image at the start of this article for an example of what these markers look like.

The recommended approach is to first setup a project in your integrated development environment for the bootloader to the point that you can build the template. Next, use your editor’s search feature to look for the ##Bootmarker and implement those parts. Once done, you might want to minimize the bootloader’s ROM footprint as described in this blog article.  Finally, repeat the same steps for the user program, with the only difference being that you need to look for the ##Progmarker. The estimated time needed to complete these steps is 4 – 8 hours.

Develop a new microcontroller port

The OpenBLT Wiki contains a list with all the supported microcontroller families. In case your microcontroller family is not yet supported, a new microcontroller port needs to be developed. The OpenBLT dowload package contains a template for this task. It is located in directory: ./Target/Source/_template/. The new port template contains a special marker formatted as a comment to point you to code locations that need to be updated specifically for your microcontroller. These comments also include an explanation of what needs to be done. In the port template, the marker looks like /* TODO ##Port … */. Refer to the image at the start of this article for an example of what this marker looks like.

The recommended approach is to create the bootloader program based on the bootloader template, as described in the previous section, to the point that you can build the bootloader. Next, use your editor’s search feature to look for the ##Bootmarker and implement those parts. You now have a bootloader that builds but the port functionality still needs to be implemented. For this, use your editor’s search feature to look for the ##Portmarker and implement those parts. Once the port and bootloader are ready, continue with the user program, as described in the previous section.

Developing a new port involves developing the communication driver for the firmware update media of your choice and developing the flash memory driver. The time needed to complete these steps is therefore dependent on how familiar you are with your microcontroller. It could take just a few days all the way up to a few weeks.

Outsourcing

This article presented detailed instructions for all the different scenarios you can encounter, while tasked with getting the OpenBLT bootloader up-and-running on your microcontroller system. If you would rather not perform these steps yourself, Feaser can assist you.

Feaser offers bootloader integration services on customer supplied hardware. With this you would lend Feaser your development system for a short amount of time and demo programs will then be created for you and directly on your hardware. The delivery includes a detailed getting started user manual to assist you with getting the demo programs running quickly.

Additionally, Feaser can develop new microcontroller ports on demand, provided that we have the capacity to take on such a project. Otherwise, we can attempt to connect you with an experienced embedded software contractor from our network, who might be interested in taking on this task.

Follow and like us:
This entry was posted in OpenBLT and tagged , , . Bookmark the permalink.