aboutsummaryrefslogtreecommitdiff
path: root/stm-flash.c
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2016-12-20 21:44:13 -0500
committerRob Austein <sra@hactrn.net>2016-12-20 21:44:13 -0500
commitde945510ca6304f3a2cf447567981784e6244dab (patch)
treea9c5bd2b975babddd2fa5d616ef380675391e237 /stm-flash.c
parenteb8c7d7cd26608a0f2825b89a1eca5008d7e3f66 (diff)
parentfe94d97f705846ef809d4109b310c96d0b3bb1ac (diff)
Merge branch 'master' into ksng
Bootloader DFU fixes.
Diffstat (limited to 'stm-flash.c')
-rw-r--r--stm-flash.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/stm-flash.c b/stm-flash.c
index 991379b..fc79ea0 100644
--- a/stm-flash.c
+++ b/stm-flash.c
@@ -72,14 +72,15 @@ uint32_t flash_sector_offsets[FLASH_NUM_SECTORS + 1] = {
int stm_flash_sector_num(const uint32_t offset)
{
- int i = FLASH_NUM_SECTORS;
+ int i;
- while (i-- >= 0) {
- if (offset >= flash_sector_offsets[i] &&
- offset < flash_sector_offsets[i + 1]) {
+ if (offset < flash_sector_offsets[0])
+ return -1;
+
+ for (i = 0; i < FLASH_NUM_SECTORS; ++i)
+ if (offset < flash_sector_offsets[i + 1])
return i;
- }
- }
+
return -1;
}