How to Initialize Peripherals from Boot Loader Section

In almost all the microcontroller codes the peripheral initialization functions like uart initialization, spi initialization are written along with the different application codes. These initialization functions are actually repetitions of the original initialization functions. The same is the case with the external hardware initialization like LCD initialization, GSM modem initialization etc. Suppose the case in which the application codes required are stored in a memory chip or SD memory card so that there is an option to select between the applications. If all the application codes have the same functions for peripheral and external hardware initialization that will simply increase the size of the code only and the size of the memory required to store the codes. It will take too much time for the Boot-Loader to load such a large size application and there will be flash memory shortage issues due to the large code size.
How to Initialize Peripherals from Boot Loader Section
These issues can be solved by doing the initialization of the peripherals and the external hardware in the code running from the BLS itself.
The code running from the BLS is executed first and then only the application code runs. Hence before the application runs the peripherals and the external hardware will be already initialized.
Thus the programmer don’t have to write all the initialization function sand hence he/she can concentrate on coding the particular application with that peripheral device only. This saves the time required for the code development. The code size also reduces in this method and the portability of the code increases. The Booting time of the microcontroller also improves due to the small code size. This project demonstrates how one can initialize the peripherals of the ATMEGA16 microcontroller irrespective of the application code using the code running from the BLS. The AVR studio4 is used as IDE in this project, USBASP is used as the programmer hardware and the AVR-BURNO-MAT is used as the burning software.
How to Initialize Peripherals from Boot Loader Section schematic
In the AVR microcontroller the flash memory is divided into two parts, namely Application Section and Boot Loader Section.  A code can be programmed into either the Application Section or the Boot loader Section (BLS). The code programmed into the Application section runs normally and is used for common applications, whereas the code running in the BLS is provided with some special features like Self Programing Mode (SPM) instructions, it can change the fuse bits etc. or in other words the code running in the BLS has complete access to the hardware. Also the microcontroller can be made to start executing from the BLS on a reset. Hence the one time initialization codes for the peripherals irrespective of the application codes are always written in the BLS.
In case of the ATMEGA16 it has 16 KB of flash memory of which the 15KB is application section and the rest 1KB is BLS. The memory architecture of the ATMEGA16 is shown in the following figure;
For more detail: How to Initialize Peripherals from Boot Loader Section

Related Post

Be the first to comment

Leave a Reply

Your email address will not be published.


= 5 + 8

Read previous post:
'Female traders can reduce market crashes', research says

Researchers in the Department of Economics at the University of Leicester have found that male traders on average earn less...