Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

How to Program in Boot Loader Section- (Part 31/46)

By Ashutosh Bhatt June 14, 2013

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. The code running in the BLS section can execute Self Programing Mode (SPM) instructions which are blocked for the code running in the Application section. Using SPM instructions the code from the BLS can rewrite the code in the application section or the code in the BLS itself. The BLS section is normally used for storing the Boot-loader code for the microcontroller. The Boot-Loader code can be used for initializing the peripherals in the microcontroller, initialize the devices connected to the microcontroller, select the application to load and execute from a storage medium, load the selected application to the application section, jump to the application section and execute the application.

This project tries to program a simple LED blinking code into the BLS and another similar kind of simple code in the Application section and observes the code executing in the BLS and then makes a jump to the Application section code. Programing a simple code into the BLS, make the microcontroller to execute the program in the BLS after a reset and jumping from the BLS to the application code are the initial steps to create a Boot-Loader code for the microcontroller. In this project ATMEGA16 microcontroller is used and AVR studio is used as the IDE. The programmer used in this project is Usbasp and the burner software used is AVR-Burnomat. 

 

 

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 rest 1KB is BLS. The memory architecture of the ATMEGA16 is shown in the following figure;

 

Architechure of AVR Flash Memory

Fig. 2: Architechure of AVR Flash Memory

 
The code for the BLS or application section is 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 following section discusses how to program a 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.
Open the AVR studio, copy and paste a simple led blinking code which is given below;
 
//#######################################################################//
#define F_CPU 8000000
 
#include <avr/io.h>
#include <util/delay.h>
 
int main ( void )
{
            DDRD |= 0x80;
 
            while(1)
            {
                        PORTD &= 0x7F;                 //led on
                        _delay_ms ( 500 );
                        PORTD |= 0x80;                 //led off
                        _delay_ms ( 500 );
            }
 
}
//#######################################################################//
Before compiling the few settings need to be done. Select the target as ATMEGA 16 as shown in the figure.
AVR Studio Window
Fig. 3: AVR Studio Window
 
The code should be compiled in such a way that it will get flashed at the BLS only. For that one need to do the memory settings as shown below. Select the memory as “flash” name the memory as “.text “give the memory address as “0x1C00”.
Memory Settings to flash code in BLS of AVR
Fig. 4: Memory Settings to flash code in BLS of AVR
 
Now build the code. Once the compilation has been completed a hex file will be generated. The USBASP programmer is currently not supported by the AVR studio 4. Hence software called AVR-BURNO-MAT can be used for flashing the hex file.
One must write the fuse bits before flashing the code so as to enable the features such as to enable the internal oscillator and to select the reset vector as 0x1C00.
 
 
FUSE BITS CONFIGURATION
 
 
FUSE
 
 
VALUE
OCDEN
1
OCD1
0
JTAGEN
0
SPIEN
1
CKPOT
1
EESAVE
0
BOOTSZ1
0
BOOTSZ0
0
BOOTRST
0
BODLEVEL
1
BODEN
1
SUT1
0
SUT0
0
CKSEL3
0
CKSEL2
1
CKSEL1
0
CKSEL0
0
Fig. 5: Fuse Bit Configuration
 
The AVR-BURNO-MAT is the best application available for writing the fuse bits into the AVR microcontroller. The fuse bit selection in the AVR-BURNO-MAT is shown in the following figure.
Fuse Bit Configuration
Fig. 6: Fuse bit selection in AVR-BURNO-MAT
This is the fuse bit setting which are about to written into ATMEGA16. Now click the “write button” and the fuse bits will get written into it.
Now one can flash the code to the boot loader section using the AVR-BURNO-MAT itself. Select the required hex file which has been generated by the AVR-STUDIO. Select the file format as Intel Hex. Now click the write button and the code will get written into the microcontroller.
 
Fuse bit selection in AVR-BURNO-MAT
 
Fig. 7: Code Flashed in boot loader using the AVR-BURNO-MAT
 
Once the flashing has been completed the LED starts Blinking, which means the code has been programmed successfully into the BLS and the microcontroller starts executing from the BLS section on reset. Now one can try to write a code for the BLS section which when done executing the code can make a jump to the application section using the jump instruction. The following section discuss about how to do that. For the BLS a simple LED blinking code which can blink the led 5 times with a delay of 500ms can be written. At the end of the code one can write a statement asm ( “jmp 0x0000” )
How to Program in Boot Loader Section
for making a jump to the address 0x0000 which is the starting address of the application section. The code is as shown below.
//#####################################################################//
#define F_CPU 8000000
#include <avr/io.h>
#include <util/delay.h>
int main ( void )
{
            DDRD |= 0x80;
            PORTD &= 0x7F;
            _delay_ms ( 500 );
            PORTD |= 0x80;
            _delay_ms ( 500 );
            PORTD &= 0x7F;
            _delay_ms ( 500 );
            PORTD |= 0x80;
            _delay_ms ( 500 );
            PORTD &= 0x7F;
            _delay_ms ( 500 );
            PORTD |= 0x80;
            _delay_ms ( 500 );
            PORTD &= 0x7F;
            _delay_ms ( 500 );
            PORTD |= 0x80;
            _delay_ms ( 500 );
            PORTD &= 0x7F;
            _delay_ms ( 500 );
            PORTD |= 0x80;
            _delay_ms ( 500 );
            asm ( “jmp 0x0000” );
}
//#####################################################################//
For the application section one can write another code which blinks the led with a delay of 2 seconds so that whenever the code jumps from the BLS to the application section it can be easily identified by the difference in the delay with which the LED blinks. The code is as shown below.
//#####################################################################//
#define F_CPU 8000000
#include <avr/io.h>
#include <util/delay.h>
int main ( void )
{
            DDRD |= 0x80;
            while(1)
            {
                        PORTD &= 0x7F;
                        _delay_ms ( 2000 );
                        PORTD |= 0x80;
                        _delay_ms ( 2000 );
            }
}
//#####################################################################//
Flash the led blinking with small delay to the BLS before flashing the led blinking with large delay to the application section. One should disabled the flash memory erasing option at the AVR-BURNO-MAT before flashing the code to the application section.
Code Flashed in boot loader using the AVR-BURNO-MAT
Fig. 8: Disabled flash memory Erasing option in AVR-BURNO-MAT
Now it can be observed that when the microcontroller resets the led blinks with small delay for 5 times which happens while the code is executing in the BLS. After the led starts blinking with large delay which happens only after a jump occurred to the application section.This was only the first step towards writing a Boot-Loader code for the AVR microcontroller. After practicing this project one can try out more complex things like initializing the peripherals from the BLS, using SPM flash to flash, SPM EEPROM to flash, and then the basic Boot-Loader code

 

Project Source Code

###


#define F_CPU 8000000
#include <avr/io.h>
#include <util/delay.h>
 
int main ( void )
{
DDRD |= 0x80;
 
PORTD &= 0x7F;
_delay_ms ( 500 );
PORTD |= 0x80;
_delay_ms ( 500 );
 
PORTD &= 0x7F;
_delay_ms ( 500 );
PORTD |= 0x80;
_delay_ms ( 500 );
 
PORTD &= 0x7F;
_delay_ms ( 500 );
PORTD |= 0x80;
_delay_ms ( 500 );
 
PORTD &= 0x7F;
_delay_ms ( 500 );
PORTD |= 0x80;
_delay_ms ( 500 );
 
PORTD &= 0x7F;
_delay_ms ( 500 );
PORTD |= 0x80;
_delay_ms ( 500 );
 
asm ( "jmp 0x0000" );
}

###

 


Project Source Code

###

//########## Test-Application##########// #define F_CPU 8000000
#include <avr/io.h>
#include <util/delay.h>
int main ( void )
{
	DDRD |= 0x80;
	while(1)
	{
		PORTD &= 0x7F;
		_delay_ms ( 2000 );
		PORTD |= 0x80;
		_delay_ms ( 2000 );	 }
}

###

 


Project Components

  • ATmega16
  • LCD
  • LED
  • Resistor

Project Video


Filed Under: AVR
Tagged With: avr microcontroller, bootloader, circuit, program a bootloader, project
 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: Internet of Things
Explore practical strategies for minimizing attack surfaces, managing memory efficiently, and securing firmware. Download now to ensure your IoT implementations remain secure, efficient, and future-ready.

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions

  • Voltage mode pushpull is a nonsense SMPS?
  • Input impedance matching network
  • High Side current sensing
  • The comparison of different Tcl script checkers
  • Reducing "shoot-through" in offline Full Bridge SMPS?

RSS Electro-Tech-Online.com Discussions

  • Is AI making embedded software developers more productive?
  • Back to the old BASIC days
  • Parts required for a personal project
  • PIC KIT 3 not able to program dsPIC
  • Failure of polypropylene motor-run capacitors

Featured – RPi Python Programming (27 Part)

  • RPi Python Programming 21: The SIM900A AT commands
  • RPi Python Programming 22: Calls & SMS using a SIM900A GSM-GPRS modem
  • RPi Python Programming 23: Interfacing a NEO-6MV2 GPS module with Raspberry Pi
  • RPi Python Programming 24: I2C explained
  • RPi Python Programming 25 – Synchronous serial communication in Raspberry Pi using I2C protocol
  • RPi Python Programming 26 – Interfacing ADXL345 accelerometer sensor with Raspberry Pi

Recent Articles

  • What is AWS IoT Core and when should you use it?
  • AC-DC power supply extends voltage range to 800 V DC
  • Infineon’s inductive sensor integrates coil system driver, signal conditioning circuits and DSP
  • Arm Cortex-M23 MCU delivers 87.5 µA/MHz active mode
  • STMicroelectronics releases automotive amplifiers with in-play open-load detection

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe