6 #include <avr/interrupt.h>
7 #include <avr/pgmspace.h>
9 /*---------------------------------------------------------------------------*/
11 * The following code was taken from the avr-libc manual:
14 flash_write_page(uint32_t page
, uint8_t *buf
)
19 /* Disable interrupts. */
26 boot_page_erase(page
);
27 boot_spm_busy_wait(); /* Wait until the memory is erased. */
29 for(i
= 0; i
< SPM_PAGESIZE
; i
+= 2) {
30 /* Set up little-endian word. */
35 boot_page_fill(page
+ i
, w
);
38 boot_page_write(page
); /* Store buffer in flash page. */
39 boot_spm_busy_wait(); /* Wait until the memory is written. */
41 /* Reenable RWW-section again. We need this if we want to jump back
42 * to the application after bootloading. */
46 /* Re-enable interrupts (if they were ever enabled). */
50 /*---------------------------------------------------------------------------*/