#include <avr/io.h> #include <avr/boot.h>
The macros in this module provide a C language interface to the bootloader support functionality of certain AVR processors. These macros are designed to work with all sizes of flash memory.
#include <inttypes.h> #include <avr/interrupt.h> #include <avr/pgmspace.h> void boot_program_page (uint32_t page, uint8_t *buf) { uint16_t i; uint8_t sreg; // Disable interrupts. sreg = SREG; cli(); eeprom_busy_wait (); boot_page_erase (page); boot_spm_busy_wait (); // Wait until the memory is erased. for (i=0; i<SPM_PAGESIZE; i+=2) { // Set up little-endian word. uint16_t w = *buf++; w += (*buf++) << 8; boot_page_fill (page + i, w); } boot_page_write (page); // Store buffer in flash page. boot_spm_busy_wait(); // Wait until the memory is written. // Reenable RWW-section again. We need this if we want to jump back // to the application after bootloading. boot_rww_enable (); // Re-enable interrupts (if they were ever enabled). SREG = sreg; }
Defines | |
#define | BOOTLOADER_SECTION __attribute__ ((section (".bootloader"))) |
#define | boot_spm_interrupt_enable() (__SPM_REG |= (uint8_t)_BV(SPMIE)) |
#define | boot_spm_interrupt_disable() (__SPM_REG &= (uint8_t)~_BV(SPMIE)) |
#define | boot_is_spm_interrupt() (__SPM_REG & (uint8_t)_BV(SPMIE)) |
#define | boot_rww_busy() (__SPM_REG & (uint8_t)_BV(__COMMON_ASB)) |
#define | boot_spm_busy() (__SPM_REG & (uint8_t)_BV(SPMEN)) |
#define | boot_spm_busy_wait() do{}while(boot_spm_busy()) |
#define | boot_page_fill(address, data) __boot_page_fill_normal(address, data) |
#define | boot_page_erase(address) __boot_page_erase_normal(address) |
#define | boot_page_write(address) __boot_page_write_normal(address) |
#define | boot_rww_enable() __boot_rww_enable() |
#define | boot_lock_bits_set(lock_bits) __boot_lock_bits_set(lock_bits) |
#define | boot_page_fill_safe(address, data) __boot_eeprom_spm_safe (boot_page_fill, address, data) |
#define | boot_page_erase_safe(address, data) __boot_eeprom_spm_safe (boot_page_erase, address, data) |
#define | boot_page_write_safe(address, data) __boot_eeprom_spm_safe (boot_page_wrte, address, data) |
#define | boot_rww_enable_safe(address, data) __boot_eeprom_spm_safe (boot_rww_enable, address, data) |
#define | boot_lock_bits_set_safe(address, data) __boot_eeprom_spm_safe (boot_lock_bits_set, address, data) |
|
Check if the SPM interrupt is enabled. |
|
Set the bootloader lock bits.
boot_lock_bits_set (_BV (BLB12)); And to remove any SPM restrictions, you would do this:
boot_lock_bits_set (0); |
|
Same as boot_lock_bits_set() except waits for eeprom and spm operations to complete before setting the lock bits. |
|
Erase the flash page that contains address.
|
|
Same as boot_page_erase() except it waits for eeprom and spm operations to complete before erasing the page. |
|
Fill the bootloader temporary page buffer for flash address with data word.
|
|
Same as boot_page_fill() except it waits for eeprom and spm operations to complete before filling the page. |
|
Write the bootloader temporary page buffer to flash page that contains address.
|
|
Same as boot_page_write() except it waits for eeprom and spm operations to complete before writing the page. |
|
Check if the RWW section is busy. |
|
Enable the Read-While-Write memory section. |
|
Same as boot_rww_enable() except waits for eeprom and spm operations to complete before enabling the RWW mameory. |
|
Check if the SPM instruction is busy. |
|
Wait while the SPM instruction is busy. |
|
Disable the SPM interrupt. |
|
Enable the SPM interrupt. |
|
Used to declare a function or variable to be placed into a new section called .bootloader. This section and its contents can then be relocated to any address (such as the bootloader NRWW area) at link-time. |