Read While Write Flash Memory on AVR®

In many AVR® devices, the Boot Loader section of program memory supports real Read-While-Write Self-Programming. This feature allows flexible application software updates controlled by the MCU using a Flash-resident Boot Loader program. The Boot Loader program can use any available data interface and associated protocol to read code and write (program) that code into the Flash memory, or read the code from the program memory. The program code within the Boot Loader section has the capability of writing into the entire Flash, including the Boot Loader memory. The Boot Loader can thus even modify itself, and it can also erase itself from the code if the feature is not needed anymore.

Flash Memory

The Flash memory is organized into two main sections: the Application section and the Boot Loader section. The size of the different sections is configured by the BOOTSZ Fuses. These two sections can have different levels of protection since they have different sets of Lock bits.

program.png

Brief AVR Read While Write Memory Summary

Application Section

The Application section is the section of the Flash that is used for storing the application code. The protection level for the Application section can be selected by the application Boot Lock bits (Boot Lock bits 0). The Application section can never store any Boot Loader code since the Store Program Memory (SPM) instruction is disabled when executed from the Application section.

Boot Loader Section (BLS)

While the Application section is used for storing the application code, the Boot Loader software must be located in the BLS since the SPM instruction can initiate a programming when executing from the BLS only. The SPM instruction can access the entire Flash, including the BLS itself. The protection level for the Boot Loader section can be selected by the Boot Loader Lock bits. The example shown is from the AVRmega328PB data sheet.

blsection.png

Read-While-Write (RWW) and No Read-While-Write (NRWW) Flash Sections

In addition to the two sections that are configurable by the BOOTSZ Fuses as described above, the Flash is also divided into two fixed sections, the Read-While-Write (RWW) section and the No Read-While-Write (NRWW) section.

rwwnrww.png

The main difference between the two sections is:

  • When erasing or writing a page located inside the RWW section, the NRWW section can be read during the operation
  • When erasing or writing a page located inside the NRWW section, the CPU is halted during the entire operation

The limit between the RWW and NRWW sections is defined in the device data sheet. These are the settings for the AVRmega328PB.

rwwsection.png

Whether the AVR device supports Read-While-Write or if the AVR device is halted during a Boot Loader software update is dependent on which address is being programmed.

User software can never read any code located inside the RWW section during a Boot Loader software operation. The syntax “Read-While-Write section” refers to which section is being programmed (erased or written), not which section is being read during a Boot Loader software update.

© 2017 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.