From b561d90ecd4ab0ac96c760bcf9df119973cd8611 Mon Sep 17 00:00:00 2001 From: George Talusan Date: Sat, 27 Feb 2016 11:41:39 -0500 Subject: [PATCH] be quicker about determining erased byte pattern when flashing --- src/stlink-common.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/stlink-common.c b/src/stlink-common.c index 90d71f31e..86b48737e 100644 --- a/src/stlink-common.c +++ b/src/stlink-common.c @@ -1972,11 +1972,11 @@ int stlink_fwrite_flash(stlink_t *sl, const char* path, stm32_addr_t addr) { ELOG("map_file() == -1\n"); return -1; } - for(index = 0; index < mf.len; index ++) { - if (mf.base[index] == erased_pattern) - num_empty ++; - else - num_empty = 0; + for(index = mf.len - 1; index >= 0; index --) { + if (mf.base[index] != erased_pattern) { + break; + } + num_empty ++; } /* Round down to words */ num_empty -= (num_empty & 3);