Bootloader in Microcontrollers
Have you ever wondered how microcontrollers get programmed from your PC or are you tired of removing microcontroller from your system and use a special programmer, then you are in the right page.
Bootloader is a software code(written by manufacturer) that resides in microcontroller memory. This code helps microcontroller to get programmed from host PC. Generally RS232 UART protocol is used to program the controller but some of them also use SPI, I2C or Modbus ASCII.
When microcontroller is powered ON or reset, it checks for the bootloader condition. If condition is satisfied then bootloader code will be executed and if not, then user application will start running. Bootloader condition can be checked either by hardware or software.
Types of bootloader:
- In system programming (ISP)
- In Application programming (IAP)
Nowadays every microcontroller has both of the above programming techniques. Here there is no need to remove chip from the system. It depends on the user to select one of them.
We will discuss both of the techniques in detail.
In System Programming(ISP)
In this mode, bootloader is located in Boot ROM which is seperate from user application memory. This block is write-protected.
Here bootloader condition is checked by the hardware itself. Let’s take an example of AT89C51xD2 microcontroller which supports 8051 architecture and has ISP mode of programming. By referring datasheet of this controller, we came to know that PSEN pin is used to monitor for bootloader condition. If this pin is grounded(PSEN=0) during reset falling edge, it forces on-chip bootloader execution.
On startup, PSEN pin is in high impedance state. Hence it must be tied to pull up to avoid any unnecessary bootloader requests.
For implementing ISP in our system, we can insert a sliding switch across PSEN pin. This will lead us to have two modes viz- bootloader mode and application mode. The connection diagram is shown below-
In Application Programming(IAP)
In this mode, bootloader is located in same memory block as of user application. Hence user can create custom bootloader and use it to program microcontrollers. One of the best example of IAP is over the air programming(OTA).
IAP allows microcontroller to program memory without removing chip from system and while user application is running.
Here user has to define bootloader condition. For example, user can check state of pushbutton after reset. If condition satisfies then program execution should go to custom bootloader and if not then to application program.
When writing custom bootloader, user must take note of that checking of bootloader condition has to be the first code after reset or power ON.
I hope you find this blog interesting and got to learn something new. Leave a comment below if you have any doubts, I'll be happy to help.