diff --git a/atusb/fw/flash.c b/atusb/fw/flash.c index 1ed8b37..3aeea71 100644 --- a/atusb/fw/flash.c +++ b/atusb/fw/flash.c @@ -57,7 +57,15 @@ void flash_write(const uint8_t *buf, uint16_t size) boot_spm_busy_wait(); } } +} + +void flash_end_write(void) +{ + if (payload & (SPM_PAGESIZE-1)) { + boot_page_write(payload & ~(SPM_PAGESIZE-1)); + boot_spm_busy_wait(); + } boot_rww_enable(); } diff --git a/atusb/fw/usb/dfu.c b/atusb/fw/usb/dfu.c index 234dbb1..18eb98c 100644 --- a/atusb/fw/usb/dfu.c +++ b/atusb/fw/usb/dfu.c @@ -192,6 +192,7 @@ static int my_setup(const struct setup_request *setup) } if (!setup->wLength) { debug("DONE\n"); + flash_end_write(); dfu.state = dfuIDLE; did_download = 1; return 1; diff --git a/atusb/fw/usb/dfu.h b/atusb/fw/usb/dfu.h index a7469ea..152e297 100644 --- a/atusb/fw/usb/dfu.h +++ b/atusb/fw/usb/dfu.h @@ -84,6 +84,7 @@ extern struct dfu dfu; void flash_start(void); int flash_can_write(uint16_t size); void flash_write(const uint8_t *buf, uint16_t size); +void flash_end_write(void); uint16_t flash_read(uint8_t *buf, uint16_t size);