How To Use SPM To load Application from EEPROM

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.
How To Use SPM To load Application from EEPROM
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.
How To Use SPM To load Application from EEPROM schematic
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


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top