diff options
Diffstat (limited to 'Bootloaders/HID')
-rw-r--r-- | Bootloaders/HID/BootloaderHID.c | 14 | ||||
-rw-r--r-- | Bootloaders/HID/BootloaderHID.h | 1 |
2 files changed, 11 insertions, 4 deletions
diff --git a/Bootloaders/HID/BootloaderHID.c b/Bootloaders/HID/BootloaderHID.c index fa1dd5873..58c9b3b6f 100644 --- a/Bootloaders/HID/BootloaderHID.c +++ b/Bootloaders/HID/BootloaderHID.c @@ -164,8 +164,11 @@ void EVENT_USB_Device_ControlRequest(void) else if (PageAddress < BOOT_START_ADDR) { /* Erase the given FLASH page, ready to be programmed */ - boot_page_erase(PageAddress); - boot_spm_busy_wait(); + ATOMIC_BLOCK(ATOMIC_RESTORESTATE) + { + boot_page_erase(PageAddress); + boot_spm_busy_wait(); + } /* Write each of the FLASH page's bytes in sequence */ for (uint8_t PageWord = 0; PageWord < (SPM_PAGESIZE / 2); PageWord++) @@ -182,8 +185,11 @@ void EVENT_USB_Device_ControlRequest(void) } /* Write the filled FLASH page to memory */ - boot_page_write(PageAddress); - boot_spm_busy_wait(); + ATOMIC_BLOCK(ATOMIC_RESTORESTATE) + { + boot_page_write(PageAddress); + boot_spm_busy_wait(); + } /* Re-enable RWW section */ boot_rww_enable(); diff --git a/Bootloaders/HID/BootloaderHID.h b/Bootloaders/HID/BootloaderHID.h index 62ee07de3..d94ba76d1 100644 --- a/Bootloaders/HID/BootloaderHID.h +++ b/Bootloaders/HID/BootloaderHID.h @@ -42,6 +42,7 @@ #include <avr/boot.h> #include <avr/power.h> #include <avr/interrupt.h> + #include <util/atomic.h> #include <stdbool.h> #include "Descriptors.h" |