From c265151d2b24c011fde22d92154ddcb4aa42d318 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Fri, 11 Mar 2011 17:40:51 -0300 Subject: [PATCH] atusb/fw: introduced function flash_end_write to properly finish flashing - dfu.h (flash_end_write), flash.c (flash_end_write): write any incomplete buffer - flash.c (flash_write, flash_end_write): call boot_rww_enable only at the very end, it won't erase our buffer in mid-page - usb/dfu.c (my_setup): call flash_end_write at the end of a download --- atusb/fw/flash.c | 8 ++++++++ atusb/fw/usb/dfu.c | 1 + atusb/fw/usb/dfu.h | 1 + 3 files changed, 10 insertions(+) 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);