Untangle Yourself with an SD Card Bootloader

Created: December 6, 2017
Updated: September 25, 2020

A cable being plugged into a PCB

Like Ray LaMontagne, I’ve got trouble. Smartphone trouble, trouble, trouble, trouble. I can figure out the apps I want, and I’ve got the games I need (wait, I might have those priorities backward), but transferring all my images and data is a bit more of a pain. There always seem to be music that gets left behind or images that, for whatever reason, refuse to back-up. I consider myself pretty savvy, but when I got a new smartphone I was starting to worry, worry, worry, worry. I couldn’t even imagine if I was trying to transfer data from a larger device—getting all of the files from a hard drive or something larger seems like it would throw me for even more of a loop.

When I purchased my new smartphone, the sales team helped me out by using a utility app that migrated my data from the old to the new smartphone with ease. I didn’t have to flounder with thirty cords and cables and hunt through all of my collections to determine what was being transferred over anymore. Now take this experience, and apply it to your work: how often do you have to replace the firmware of a microcontroller? And how often do you wish you could avoid that clumsy process of plugging in cables? One way to simplify this process is by using an SD card bootloader.

Flexible Updating With an SD Card Bootloader

Conventionally, a microcontroller is programmed using a programming cable. This can become cumbersome and tedious if you are working in a space-restricted environment or if you’re like me and you tend to leave your unfinished tasks hanging out all over the place. Furthermore, it lends itself to outside interference. What if you trip on a cable and knock everything off a table? Or spend several hours trying to figure out why data is not transferring only to realize that the cable simply was not plugged in tightly enough?

In a microcontroller, a bootloader is a special program that receives the application firmware from an external source and writes it to the internal program memory. It tends to have a small footprint and resides in a reserved section of the program memory. When the microcontroller is powered on and attempts to read the latest firmware present in external media or resources, the bootloader program will erase the existing firmware in the program memory and write the new firmware onto it.

You could customize your bootloader to obtain its new firmware from serial interfaces, LAN, external media, and more. But my personal preference is for the SD card: it does not need to be a complicated setup on a computer, and it is practically wireless. Using an SD card for your bootloader program turns updating firmware into a matter of inserting the SD card and resetting the microcontroller.

With a bootloader, updating firmware can be done on the spot and with minimum interruption to the system operation. This feature makes bootloaders, and especially SD card bootloaders, incredibly helpful in embedded systems that may require updating or troubleshooting in the course of their deployment. If the specifications of your firmware may need to evolve with time or update regularly then an SD card bootloader would make the process that much easier.

Writing code on a computer
Make sure the microcontroller has space for both the bootloader and the main application.

Don’t Knock Yourself Down Again

The main idea behind an SD card bootloader is that the bootloader program is going to read the binary or hex file of the main application from an SD card and write this file into the program memory of the microcontroller. Keeping this central process in mind, here are some other issues to consider:

Program Memory Allocation: While there are clear benefits of having an SD card bootloader, not all microcontrollers can be loaded with a bootloader program. A bootloader is an application by itself. As such, it does require a certain amount of program memory space that may not be available if you’re using a microcontroller with smaller memory space or your application firmware is too large. Allocate adequate program memory space for both the bootloader and firmware application if you’re planning to incorporate a bootloader.

Implementing an SD Card Interface: An SD card bootloader will require additional components to be built on your hardware to accommodate the SD card storage. It will incur additional cost if your main application does not require the SD card interface. Besides that, you’ll need to implement the File Allocation Table (FAT32) stack on your bootloader program to ensure that your bootloader program can read the binary or hex file of the new firmware.

Program Memory Flash Write Sequence: A bootloader basically rewrites a range of address in its internal flash with bytes of information of the application firmware to be loaded. This will require executing the right sequence of command on specific registers to erase and write on the internal flash. Ensure that the right address is being written onto and that the bootloader does not actually erase itself mistakenly.

Mapping the Binary Files to the Right Address: A normal application is usually written on the starting address of 0x00000000. However, with a bootloader, the starting address of the main application or the bootloader may differ, depending on how they are allocated in the program memory space. Modify the memory link file to ensure that hex files of both programs are compiled for the right memory address.

Rigorous Testing: The purpose of an SD card bootloader is to simplify firmware updating in the field, not to add unnecessary errors or difficulties to the process. It is important that you test your bootloader thoroughly and ensure that both the bootloader and the main application runs as expected. If the main application is being written improperly or mapped incorrectly you may find that the system will behave erratically.

Clipboard with a timer, list, and checkmark box checked
You’ll want to ensure the bootloader is writing the right code at the right space.

There are other benefits, too, to using a bootloader program aside from quality firmware development. When you need to access an easy-to-use PCB layout tool that includes everything needed to build high-quality manufacturable circuit boards, look no further than CircuitMaker. In addition to easy-to-use PCB design software, all CircuitMaker users have access to a personal workspace on the Altium 365 platform. You can upload and store your design data in the cloud, and you can easily view your projects via your web browser in a secure platform.

Start using CircuitMaker today and stay tuned for the new CircuitMaker Pro from Altium.

Recent Articles

Back to Home