You Are Here: Home » AVR ATmega Projects » LCD Projects » How To Write a Simple Bootloader For AVR In C language

How To Write a Simple Bootloader For AVR In C language




The BootLoader is a code which executes when a microcontroller is powered ON or reset. It basically sets an environment for the application code to execute. It is the Boot-Loader that sets the hardware and loads the application code from any storage medium or received through external communication and let the application to execute. Thus a Boot-Loader has to perform the following basic function : Initialize the controller peripherals,

Initialize the devices in the board, Allow an option for the user to select from the available applications to load, Load the selected application, Let the application code to execute. Apart from the above mentioned functions some Boot-Loaders can perform many other functions and there are Boot-Loaders which don’t perform all these functions like provide option to select the required application etc. The Boot-Loader codes in microcontrollers are actually very small and simple compared to the Boot-Loaders in advanced devices like PC. In most of the microcontroller the functionality of a Boot-Loader is limited only to set the initial clock and other settings for the microcontroller, load an application binary from the serial port etc.In an AVR microcontroller writing a Boot-Loader code is comparatively easy, since any code which is written to the BLS section of the flash memory can have complete access to the hardware of the microcontroller. The flash memory of the AVR microcontroller is divided into two sections; an Application flash section and a Boot-Loader section (BLS).

How To Write a Simple Bootloader For AVR In C language

Any code which executes from the BLS can use Self Programming Mode (SPM). Using the SPM feature a code from the BLS section can read or write the entire flash memory including the BLS section where the code is running from. This feature can be used to load any application code binary to the flash memory and let it execute. The required initialization of the controller peripherals like USART, port bits etc. and the initialization of the external devices like LCD etc. can be done from the BLS itself before loading the application code.

In this project discuss how to write a simplest Boot-Loader code for the AVR microcontroller which can initialize the peripherals like USART, LED port and initialize a 4 bit LCD connected to the controller and then load any application which has been flashed into the built-in EEPROM of the microcontroller. The microcontroller used in this project is ATMEGA16, and the programmer used is USBASP. The AVR studio 4 is used as the IDE and the burner software used is AVR-BURNO-MAT.

The AVR flash memory is divided into two sections namely the application section and the Boot-Loader section (BLS). In case of the ATMEGA16 it has 16 KB of flash memory of which the 15KB is application section and the remaining 1KB is BLS. The memory architecture of the ATMEGA16 is shown in the following figure;

The code for both the BLS and application section can be written as normally does and there is no much difference. The only thing to be careful about is the size of the code binary. It should not be more than 1KB, otherwise it won’t be able to code programmed into the BLS. The project on AVR BLS coding discusses how to program a simple code into the BLS of ATMEGA16 microcontroller with the help of AVR studio as IDE, USBasp as the programmer and AVR-Burnomat as the burner software.

How To Write a Simple Bootloader For AVR In C language schematic

In this particular project the Boot-Loader is coded to perform UART initialization along with a simple LED pin initialization and also an external hardware initialization of the 4 bit LCD. Hence the application codes does not require those codes in them, still they works because before executing the application codes the initialization functions will be executed by the Boot-Loader.

The BLS code has the initialization functions which should not be there in the application codes. The initialization functions used in the Boot-Loader code for this project are given below;

 

For more detail: How To Write a Simple Bootloader For AVR In C language

Leave a Comment

You must be logged in to post a comment.

Read previous post:
NIST invents fleet and fast test for nanomanufacturing quality control (w/ Video)

Manufacturers may soon have a speedy and nondestructive way to test a wide array of materials under real-world conditions, thanks...

Close
Scroll to top