8000 stm32/flash: Fix sector and bank calculation for H5 and H7 MCUs. · pimoroni/micropython@7ecff51 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7ecff51

Browse files
committed
stm32/flash: Fix sector and bank calculation for H5 and H7 MCUs.
Flash sectors should start counting at 0 for each bank. This commit makes sure that is the case on all H5 and H7 MCUs, by using `get_page()` instead of `flash_get_sector_info()`. Signed-off-by: Damien George <damien@micropython.org>
1 parent 5cb93f6 commit 7ecff51

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

ports/stm32/flash.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,18 @@ static const flash_layout_t flash_layout[] = {
163163
#error Unsupported processor
164164
#endif
165165

166-
#if defined(STM32H723xx) || defined(STM32H750xx)
166+
#if defined(STM32H7) && !defined(DUAL_BANK)
167167

168168
// get the bank of a given flash address
169169
static uint32_t get_bank(uint32_t addr) {
170170
return FLASH_BANK_1;
171171
}
172172

173+
// get the page of a given flash address
174+
static uint32_t get_page(uint32_t addr) {
175+
return (addr - FLASH_LAYOUT_START_ADDR) / FLASH_LAYOUT_SECTOR_SIZE;
176+
}
177+
173178
#elif (defined(STM32L4) && defined(SYSCFG_MEMRMP_FB_MODE)) || defined(STM32H5) || defined(STM32H7)
174179

175180
// get the bank of a given flash address
@@ -195,7 +200,6 @@ static uint32_t get_bank(uint32_t addr) {
195200
}
196201
}
197202

198-
#if (defined(STM32L4) && defined(SYSCFG_MEMRMP_FB_MODE))
199203
// get the page of a given flash address
200204
static uint32_t get_page(uint32_t addr) {
201205
if (addr < (FLASH_LAYOUT_START_ADDR + FLASH_BANK_SIZE)) {
@@ -206,7 +210,6 @@ static uint32_t get_page(uint32_t addr) {
206210
return (addr - (FLASH_LAYOUT_START_ADDR + FLASH_BANK_SIZE)) / FLASH_LAYOUT_SECTOR_SIZE;
207211
}
208212
}
209-
#endif
210213

211214
#elif (defined(STM32L4) && !defined(SYSCFG_MEMRMP_FB_MODE)) || defined(STM32WB) || defined(STM32WL)
212215

@@ -352,10 +355,7 @@ int flash_erase(uint32_t flash_dest) {
352355
EraseInitStruct.Sector = flash_get_sector_info(flash_dest, NULL, NULL);
353356
#elif defined(STM32H5) || defined(STM32H7)
354357
EraseInitStruct.Banks = get_bank(flash_dest);
355-
EraseInitStruct.Sector = flash_get_sector_info(flash_dest, NULL, NULL);
356-
#if defined(STM32H5)
357-
EraseInitStruct.Sector &= 0x7f; // second bank should start counting at 0
358-
#endif
358+
EraseInitStruct.Sector = get_page(flash_dest);
359359
#else
360360
#error Unsupported processor
361361
#endif

0 commit comments

Comments
 (0)
0