Skip to content

Commit

Permalink
Fix flash_erase bank selection logic
Browse files Browse the repository at this point in the history
Which bank a page lies in depends whether there are 2 banks. If there are 2 banks, the flash page size is cut in half and there are now double the pages. Half the pages in bank1, half in bank2. Therefore, write the BKER bit based on the half_npages.
  • Loading branch information
kywwilson11 committed Oct 15, 2024
1 parent 227206a commit f7bff7b
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions arch/arm/src/stm32/stm32g4xxx_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,19 +187,16 @@ static inline void flash_erase(size_t page)

modifyreg32(STM32_FLASH_CR, 0, FLASH_CR_PAGE_ERASE);

/* DBANK=0, Page range 0 to 128
* DBANK=1, Page range 0 to 255
*/

modifyreg32(STM32_FLASH_CR, FLASH_CR_PNB_MASK,
FLASH_CR_PNB(page));

#if (defined(CONFIG_STM32_STM32G47XX) || \
defined(CONFIG_STM32_STM32G48XX))
uint32_t half_npages = get_flash_npages() / 2

if (getreg32(STM32_FLASH_OPTR) & FLASH_OPTR_DBANK)
{
if (page <= 0x7f)
if (page < half_npages)
{
/* Select bank 1 */

Expand Down

0 comments on commit f7bff7b

Please sign in to comment.