diff options
author | Damien George <damien@micropython.org> | 2020-06-18 15:12:25 +1000 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2020-06-22 14:18:15 +1000 |
commit | 736daebfc8c7dce2fab10ee311519034d702c8b6 (patch) | |
tree | 39bf229abe60836c743d3a881d1c66fb14340093 | |
parent | 4c8a68df6f25ed98d097b0defd3180739c813654 (diff) |
stm32/flash: Add flash_is_valid_addr, and extend sectors for 2MB F7.
Signed-off-by: Damien George <damien@micropython.org>
-rw-r--r-- | ports/stm32/flash.c | 12 | ||||
-rw-r--r-- | ports/stm32/flash.h | 1 |
2 files changed, 13 insertions, 0 deletions
diff --git a/ports/stm32/flash.c b/ports/stm32/flash.c index 7c7d2f7b6..5f96696a9 100644 --- a/ports/stm32/flash.c +++ b/ports/stm32/flash.c @@ -70,10 +70,15 @@ static const flash_layout_t flash_layout[] = { { 0x08020000, 0x20000, 3 }, }; #else +// This is for dual-bank mode disabled static const flash_layout_t flash_layout[] = { { 0x08000000, 0x08000, 4 }, { 0x08020000, 0x20000, 1 }, + #if FLASH_SECTOR_TOTAL == 8 { 0x08040000, 0x40000, 3 }, + #else + { 0x08040000, 0x40000, 7 }, + #endif }; #endif @@ -139,6 +144,13 @@ static uint32_t get_page(uint32_t addr) { #endif +bool flash_is_valid_addr(uint32_t addr) { + uint8_t last = MP_ARRAY_SIZE(flash_layout) - 1; + uint32_t end_of_flash = flash_layout[last].base_address + + flash_layout[last].sector_count * flash_layout[last].sector_size; + return flash_layout[0].base_address <= addr && addr < end_of_flash; +} + uint32_t flash_get_sector_info(uint32_t addr, uint32_t *start_addr, uint32_t *size) { if (addr >= flash_layout[0].base_address) { uint32_t sector_index = 0; diff --git a/ports/stm32/flash.h b/ports/stm32/flash.h index 048914e50..12cdaca55 100644 --- a/ports/stm32/flash.h +++ b/ports/stm32/flash.h @@ -26,6 +26,7 @@ #ifndef MICROPY_INCLUDED_STM32_FLASH_H #define MICROPY_INCLUDED_STM32_FLASH_H +bool flash_is_valid_addr(uint32_t addr); uint32_t flash_get_sector_info(uint32_t addr, uint32_t *start_addr, uint32_t *size); int flash_erase(uint32_t flash_dest, uint32_t num_word32); int flash_write(uint32_t flash_dest, const uint32_t *src, uint32_t num_word32); |