summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Schodet2016-01-15 15:23:44 +0100
committerNicolas Schodet2019-10-07 00:44:57 +0200
commit09d4a95a8eec1b57bc18264fab2a5c1beb61aabc (patch)
tree70042768e3bcbc194d91d06fb9e8fff273277d6b
parent453f4f6540ed8df612af94c1c73db962bb75fa7b (diff)
ucoo/hal/self_programming: add function to query erase size
-rw-r--r--ucoo/hal/self_programming/self_programming.hh4
-rw-r--r--ucoo/hal/self_programming/self_programming.stm32f1.cc15
-rw-r--r--ucoo/hal/self_programming/self_programming.stm32f4.cc11
3 files changed, 27 insertions, 3 deletions
diff --git a/ucoo/hal/self_programming/self_programming.hh b/ucoo/hal/self_programming/self_programming.hh
index 4e06709..c1aceb1 100644
--- a/ucoo/hal/self_programming/self_programming.hh
+++ b/ucoo/hal/self_programming/self_programming.hh
@@ -31,6 +31,10 @@ namespace ucoo {
int
self_programming_flash_size ();
+/// Return erase size at given address, which must be aligned on erase size.
+int
+self_programming_erase_size (uint32_t addr);
+
/// Erase flash, must be aligned on erase size.
void
self_programming_erase (uint32_t addr, int count);
diff --git a/ucoo/hal/self_programming/self_programming.stm32f1.cc b/ucoo/hal/self_programming/self_programming.stm32f1.cc
index 5d84561..8cbbb24 100644
--- a/ucoo/hal/self_programming/self_programming.stm32f1.cc
+++ b/ucoo/hal/self_programming/self_programming.stm32f1.cc
@@ -35,14 +35,23 @@ self_programming_flash_size ()
return DESIG_FLASH_SIZE * 1024;
}
-void
-self_programming_erase (uint32_t addr, int count)
+int
+self_programming_erase_size (uint32_t addr)
{
- assert (static_cast<int> (addr - FLASH_BASE + count)
+ assert (static_cast<int> (addr - FLASH_BASE)
<= self_programming_flash_size ());
uint32_t idcode = DBGMCU_IDCODE & DBGMCU_IDCODE_DEV_ID_MASK;
int page_size = idcode >= 0x414 ? 2048 : 1024;
assert ((addr & (page_size - 1)) == 0);
+ return page_size;
+}
+
+void
+self_programming_erase (uint32_t addr, int count)
+{
+ assert (static_cast<int> (addr - FLASH_BASE + count)
+ <= self_programming_flash_size ());
+ int page_size = self_programming_erase_size (addr);
assert ((count & (page_size - 1)) == 0);
while (count)
{
diff --git a/ucoo/hal/self_programming/self_programming.stm32f4.cc b/ucoo/hal/self_programming/self_programming.stm32f4.cc
index 912eb15..3956b1e 100644
--- a/ucoo/hal/self_programming/self_programming.stm32f4.cc
+++ b/ucoo/hal/self_programming/self_programming.stm32f4.cc
@@ -52,6 +52,17 @@ self_programming_flash_size ()
return DESIG_FLASH_SIZE * 1024;
}
+int
+self_programming_erase_size (uint32_t addr)
+{
+ for (int sector = 0; sector < lengthof (sector_addr) - 1; sector++)
+ {
+ if (addr == sector_addr[sector])
+ return sector_addr[sector + 1] - addr;
+ }
+ assert_unreachable ();
+}
+
void
self_programming_erase (uint32_t addr, int count)
{