Skip to content

Commit

Permalink
HAL_ChibiOS: fixed erasing of G4 dual-bank past 256k flash
Browse files Browse the repository at this point in the history
BKER needs to be set to bank number, lower 7 bits of page number in
PNB
  • Loading branch information
tridge committed May 10, 2024
1 parent 65bf3ad commit 3050a8b
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions libraries/AP_HAL_ChibiOS/hwdef/common/flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -520,10 +520,16 @@ bool stm32_flash_erasepage(uint32_t page)
FLASH->CR |= FLASH_CR_STRT;
#elif defined(STM32G4)
FLASH->CR = FLASH_CR_PER;
// rather oddly, PNB is a 7 bit field that the ref manual says can
// contain 8 bits we assume that for 512k single bank devices
// there is an 8th bit
#ifdef FLASH_CR_BKER_Pos
/*
we assume dual bank mode, we set the bottom 7 bits of the page
into PNB and the 8th bit into BKER
*/
FLASH->CR |= (page&0x7F)<<FLASH_CR_PNB_Pos | (page>>7)<<FLASH_CR_BKER_Pos;
#else
// this is a single bank only varient
FLASH->CR |= page<<FLASH_CR_PNB_Pos;
#endif
FLASH->CR |= FLASH_CR_STRT;
#elif defined(STM32L4PLUS)
FLASH->CR |= FLASH_CR_PER;
Expand Down

0 comments on commit 3050a8b

Please sign in to comment.