Summary of How To Use SPM To load Application from EEPROM
This article explains how to implement a Boot-Loader in an ATMEGA16 microcontroller using Self Programming Mode (SPM) to rewrite flash memory from data stored in the internal EEPROM. It details the three-step process of erasing, buffering, and programming the flash, utilizing specific AVR header files for EEPROM and boot operations. The project demonstrates re-flashing code previously saved in the microcontroller's 512-byte EEPROM section.
Parts used in the ATMEGA16 Boot-Loader Project:
- ATMEGA16 Microcontroller
- USBASP Programmer
- AVR STUDIO 4 IDE
- AVR-BURNO-MAT Burner Software
- Header File
- Header File
In any microcontroller the Boot-Loader is the first code which executes before the application code does. The major function of the Boot-Loader is to load the application code into the flash memory of the microcontroller and execute it. In AVR microcontroller the Self Programming Mode (SPM) helps the Boot-Loader to load a particular application from where the application binary is stored.The Boot-Loader may receive the code binary from other memory chips, SD-cards or through the serial port of the microcontroller in case of serial programming.
It is then with the help of the SPM that the microcontroller write the binary code into the application flash section.
In this particular project the operation of a Boot-Loader code using the SPM is demonstrated by re-writing flash memory with the code binary which has already been flashed into the built-in EEPROM of the ATMEGA16. The hardware used in this project includes ATMEGA16 as microcontroller, USBASP as the programmer and the software used are AVR STUDIO 4 as IDE and AVR-BURNO-MAT as the burner software.
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. 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 task of writing the BLS code with SPM has been made simple by the APIs available in the header file <avr/boot.h>. The following are the important APIs available in the header file which helps in the SPM.
Using the above APIs one can write a code for SPM in an AVR microcontroller provided that the code should follow certain steps in the order.
- Step: 1 Erase the flash page which is about to write into
{C· Step: 2 Store the binaries in a temporary buffer before write into a flash page
{C}· Step: 3 Program the filled temporary buffer into the already erased flash page
The above three steps are explained with details in a previous project on AVR SPM. In this particular project the data that is required to fill the temporary page buffer as discussed in the step: 2 is taken from the built-in EEPROM of the AVR microcontroller where a simple code has already been flashed into. The internal EEPROM of the AVR microcontroller has 512 bytes capacity. It can be easily read and write with the help of APIs available in the header file <avr/eeprom.h>. The following are the important APIs available in the header file which helps in accessing the EEPROM memory.
For more detail: How To Use SPM To load Application from EEPROM
-
What is the major function of a Boot-Loader?
The major function is to load application code into the flash memory of the microcontroller and execute it. -
How does the Self Programming Mode help in AVR microcontrollers?
SPM helps the Boot-Loader load a particular application from where the binary is stored and write the code into the application flash section. -
Where can the Boot-Loader receive code binaries from?
It can receive code from other memory chips, SD-cards, or through the serial port of the microcontroller. -
Which header file provides APIs for Self Programming Mode instructions?
The header file avr/boot.h provides the important APIs available to help in SPM. -
What are the three steps required to write code for SPM?
The steps are: Erase the flash page, store binaries in a temporary buffer, and program the filled buffer into the erased flash page. -
What is the capacity of the internal EEPROM in the AVR microcontroller used?
The internal EEPROM has a 512 bytes capacity. -
Which header file is used to access the EEPROM memory?
The header file avr/eeprom.h contains the important APIs to access the EEPROM memory.


