blob: c119655618f6501667adb60c46c5ae7c24e4ea23 [file] [log] [blame]
Brian Silverman11db9dd2014-01-01 16:29:22 -08001From 3076652b98d4d33ac50eb546839a47980464c34d Mon Sep 17 00:00:00 2001
2From: Brian <brian@localhost>
3Date: Wed, 1 Jan 2014 16:21:50 -0800
4Subject: [PATCH] fixed the page-by-page erase logic
5
6Previously, it always started at page 0 and erased 1 more page than it
7was told to with bootloaders that support the extended erase command.
8---
9 stm32.c | 8 ++++----
10 1 file changed, 4 insertions(+), 4 deletions(-)
11
12diff --git a/stm32.c b/stm32.c
13index f724722..dee7959 100644
14--- a/stm32.c
15+++ b/stm32.c
16@@ -430,14 +430,14 @@ char stm32_erase_memory(const stm32_t *stm, uint8_t spage, uint8_t pages) {
17 uint8_t pg_byte;
18 uint8_t cs = 0;
19
20- pg_byte = pages >> 8;
21- stm32_send_byte(stm, pg_byte); // Number of pages to be erased, two bytes, MSB first
22+ pg_byte = (pages - 1) >> 8;
23+ stm32_send_byte(stm, pg_byte); // Number of pages to be erased - 1, two bytes, MSB first
24 cs ^= pg_byte;
25- pg_byte = pages & 0xFF;
26+ pg_byte = (pages - 1) & 0xFF;
27 stm32_send_byte(stm, pg_byte);
28 cs ^= pg_byte;
29
30- for (pg_num = 0; pg_num <= pages; pg_num++) {
31+ for (pg_num = spage; pg_num < spage + pages; pg_num++) {
32 pg_byte = pg_num >> 8;
33 cs ^= pg_byte;
34 stm32_send_byte(stm, pg_byte);
35--
361.7.10.4
37