blob: c119655618f6501667adb60c46c5ae7c24e4ea23 [file] [log] [blame]
From 3076652b98d4d33ac50eb546839a47980464c34d Mon Sep 17 00:00:00 2001
From: Brian <brian@localhost>
Date: Wed, 1 Jan 2014 16:21:50 -0800
Subject: [PATCH] fixed the page-by-page erase logic
Previously, it always started at page 0 and erased 1 more page than it
was told to with bootloaders that support the extended erase command.
---
stm32.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/stm32.c b/stm32.c
index f724722..dee7959 100644
--- a/stm32.c
+++ b/stm32.c
@@ -430,14 +430,14 @@ char stm32_erase_memory(const stm32_t *stm, uint8_t spage, uint8_t pages) {
uint8_t pg_byte;
uint8_t cs = 0;
- pg_byte = pages >> 8;
- stm32_send_byte(stm, pg_byte); // Number of pages to be erased, two bytes, MSB first
+ pg_byte = (pages - 1) >> 8;
+ stm32_send_byte(stm, pg_byte); // Number of pages to be erased - 1, two bytes, MSB first
cs ^= pg_byte;
- pg_byte = pages & 0xFF;
+ pg_byte = (pages - 1) & 0xFF;
stm32_send_byte(stm, pg_byte);
cs ^= pg_byte;
- for (pg_num = 0; pg_num <= pages; pg_num++) {
+ for (pg_num = spage; pg_num < spage + pages; pg_num++) {
pg_byte = pg_num >> 8;
cs ^= pg_byte;
stm32_send_byte(stm, pg_byte);
--
1.7.10.4