From 45a0f24a3128fd8539e1f1a1a59b578ff4492d33 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 18 Jun 2018 15:42:00 +0700 Subject: [PATCH] enhance msc flash --- src/msc/msc_flash.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/msc/msc_flash.c b/src/msc/msc_flash.c index ac6ce0f..6aa3287 100644 --- a/src/msc/msc_flash.c +++ b/src/msc/msc_flash.c @@ -276,7 +276,8 @@ int32_t tud_msc_write10_cb (uint8_t rhport, uint8_t lun, uint32_t lba, uint32_t uint32_t addr = lba2addr(lba) + offset; - /* 1. queue flash erase pstorage_clear(), return 0 until erasing is done + /* 0. Check if flash is the same as data -> skip if matches + * 1. queue flash erase pstorage_clear(), return 0 until erasing is done * 2. queue flash writing, return 0 until writing is complete * 3. return written bytes. * @@ -287,6 +288,9 @@ int32_t tud_msc_write10_cb (uint8_t rhport, uint8_t lun, uint32_t lba, uint32_t { case WRITE10_IDLE: { + // No need to write if flash's content matches with data + if ( 0 == memcmp(buffer, (void*) addr, bufsize) ) return bufsize; + uint32_t page_addr = align4k(addr); uint32_t off4k = offset4k(addr);