summaryrefslogtreecommitdiff
path: root/ucoo/hal/self_programming/self_programming.stm32f4.cc
diff options
context:
space:
mode:
Diffstat (limited to 'ucoo/hal/self_programming/self_programming.stm32f4.cc')
-rw-r--r--ucoo/hal/self_programming/self_programming.stm32f4.cc12
1 files changed, 10 insertions, 2 deletions
diff --git a/ucoo/hal/self_programming/self_programming.stm32f4.cc b/ucoo/hal/self_programming/self_programming.stm32f4.cc
index 9d8aa56..9d352ac 100644
--- a/ucoo/hal/self_programming/self_programming.stm32f4.cc
+++ b/ucoo/hal/self_programming/self_programming.stm32f4.cc
@@ -46,10 +46,17 @@ static const uint32_t sector_addr[] = {
0x81e0000, 0x8200000,
};
+int
+self_programming_flash_size ()
+{
+ return DESIG_FLASH_SIZE * 1024;
+}
+
void
self_programming_erase (uint32_t addr, int count)
{
- assert (addr - sector_addr[0] + count <= DESIG_FLASH_SIZE * 1024);
+ assert (static_cast<int> (addr - sector_addr[0] + count)
+ <= self_programming_flash_size ());
int sector;
for (sector = 0; count && sector < lengthof (sector_addr); sector++)
{
@@ -72,7 +79,8 @@ self_programming_write (uint32_t addr, const char *buf, int count)
assert (addr % 4 == 0);
assert (reinterpret_cast<int> (buf) % 4 == 0);
assert (count % 4 == 0);
- assert (addr - sector_addr[0] + count <= DESIG_FLASH_SIZE * 1024);
+ assert (static_cast<int> (addr - sector_addr[0] + count)
+ <= self_programming_flash_size ());
flash_unlock ();
for (int i = 0; i < count; i += 4)
flash_program_word (addr + i,