Site icon Pallav Aggarwal

How to implement firmware update for your microcontroller(MCU)?


Firmware upgradability feature is so critical that it can almost kill your business if you don’t have it.

One might ask, why field firmware update is so critical for any product these days?

Some of the possible answers could be:

I hope with the above points you are convinced that firmware update feature is quite important for any product. Now, lets us is what if we want to implement it in our MCU based products.

Is it easy to implement firmware update feature?

I am sure you are afraid of firmware update feature implementation because you have never tried it. It seems little complex when you think about it but it is not that difficult.

Let me know if you have tried the implementation and could not complete due to complexity involved. Please contact me, I will try to help.

Some of the key challenges while implementing firmware update are as mentioned below:

Although there are a couple of challenges associated with the firmware update implementation, it is not that complex that you need any special guidance or expertise. Let me try to help by providing you with basic implementation steps.

Steps to implement firmware update feature

  1. You need to download the firmware and check its integrity. If you have firmware encrypted, you need to also decrypt after it is downloaded.
  2. You must have a bootloader code that will check at every boot if there a new firmware available or not. If available, it will update the firmware using in-application programming. Otherwise, it will pass the handle to the main program execution.
  3. New firmware can be stored in the following:
    1. External memory (EEPROM, SPI Flash, SD card, etc.)
    2. If you are using GPRS modem, they also have space available for file storage which could be used.
    3. One can also have MCU with bigger flash memory like double the size of the program.
    4. Download the file in RAM if you are 100% sure of power availability/backup.
  4. The main program will check periodically on the cloud or get a trigger via an external interface for downloading the new firmware. Once downloaded and checked the integrity, will set the flag and initiate the soft restart.
  5. There are different ways, you can download the full firmware or can implement sector wise download and re-flashing. Both have their pros and cons. I recommend downloading complete file so that uncertainty of proper file download won’t be there.
  6. While firmware update is in-progress, power should not go away. One strategy could be power-off all not-required sections on the board and use a big size cap/super cap/battery backup to ensure power availability during reflash. Consider 1.5 time of re-flashing time as the back up.
  7. Rollback mechanism should also be created so that in case the new firmware doesn’t work for whatever reason, it should easily roll back to the old one and product becomes operational.
  8. Mechanism to update the boot-loader itself should not arise so think thoroughly before implementation and test it really well. If you are unsure, please do implement a mechanism to update boot-loader also.
  9. One can off-load in-application programming to another small external MCU which will update the firmware via UART, etc. These days many MCU provides boot-loader in ROM which provides easy UART based programming interface already implemented. In this case file will be downloaded and stored in the Memory connected to this special MCU whose purpose is to program the main MCU. This special MCU Can be programmed in such a way that it keeps the bootloader, & 2 copies of firmware one old and another new in the memory.

You should also make sure whatever way you are implementing this feature, it is quite generic and not using some very specific feature of an MCU which will only be available on one of your project’s MCU. Generic implementation can always be reused across your projects where different MCU from different vendors are used. In special cases you might want to ignore this advice.

I hope above explanation has helped you understand the basic concept of firmware update and its implementation.

Do you have a firmware update feature implemented in your product?

Let me know if you need any help. I will be happy to help.

If you have any suggestions or feedback please share it in the comments below or send me an email.

Read my other articles on Embedded System Design.

Exit mobile version