How to Use SPM for Flash to Flash Programming

Summary of How to Use SPM for Flash to Flash Programming


The Self Programming Mode (SPM) in AVR microcontrollers lets code running in the Boot Loader Section (BLS) program the device's flash, including the application section and even the BLS itself. This project demonstrates copying code from one flash region to another and executing it, using ATMEGA16, USBASP, AVR Studio 4, and AVR-BURNO-MAT. SPM is accessed via APIs in and requires following specific ordered steps to perform flash-to-flash programming.

Parts used in the Self Programming Mode (SPM) Project:

  • ATMEGA16 microcontroller
  • USBASP programmer
  • AVR Studio 4 (IDE)
  • AVR-BURNO-MAT burner software
  • <avr/boot.h> header file (APIs for SPM)

The Self Programming Mode (SPM) is a feature which enables a microcontroller to program its own flash memory. Using the SPM a microcontroller can program itself with an SPM code. The SPM is commonly used with the microcontroller Boot-Loader codes which help to program the microcontroller serially. In AVR microcontroller the SPM is available only for the code running in the BLS of the flash memory. With the help of the SPM a code in BLS can rewrite the application flash memory entirely or a part of it. It can even rewrite its own code in the BLS section.
How to Use SPM for Flash to Flash Programming
The SPM is a key factor of the Boot-Loader code since the major function of the Boot-Loader is to load an application code into the application flash section. 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 project the operation of the SPM is demonstrated re-writing the code from one region of the flash memory to another region and then tries to execute the same code from that region. 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.
Self-Programming Mode (SPM) is a feature of the AVR microcontroller which enables the microcontroller to program its own flash memory. Only the code running on the BLS can make use of this SPM feature. The microcontroller can be made to start executing from the BLS from there the code can access the application flash area. The BLS can read or write the content of the entire flash including the BLS itself.
How to Use SPM for Flash to Flash Programming schematic
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. In this project code which has been programmed from the beginning of the flash memory is re-programmed into another region of the flash memory as such. The task of programming one region of flash memory with the binary taken from the other region can be done in the following three major steps.
 
For more detail: How to Use SPM for Flash to Flash Programming

Quick Solutions to Questions related to Self Programming Mode (SPM):

  • What is Self Programming Mode SPM?
    SPM is a feature in AVR microcontrollers that enables code running in the Boot Loader Section to program the device's flash memory.
  • Can code outside the BLS use SPM?
    No, only code running in the Boot Loader Section can use SPM according to the article.
  • What microcontroller was used in this project?
    The project used the ATMEGA16 microcontroller.
  • How does the Boot-Loader use SPM?
    The Boot-Loader receives binary code and uses SPM to write the binary into the application flash section.
  • What software tools were used in the project?
    AVR Studio 4 as the IDE and AVR-BURNO-MAT as the burner software were used.
  • What programmer hardware was used?
    The USBASP programmer was used in the project.
  • Can the BLS rewrite its own code?
    Yes, the BLS can read or write the entire flash including the BLS itself.
  • Which header file provides APIs for SPM?
    The header file <avr/boot.h> provides important APIs for SPM.
  • What does the project demonstrate?
    The project demonstrates re-writing code from one flash region to another and attempting to execute it from the new region.

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
Scroll to Top