diff --git a/libraries/AP_HAL_ChibiOS/hwdef/common/flash.c b/libraries/AP_HAL_ChibiOS/hwdef/common/flash.c index 3f81cc9ce1..769eea6799 100644 --- a/libraries/AP_HAL_ChibiOS/hwdef/common/flash.c +++ b/libraries/AP_HAL_ChibiOS/hwdef/common/flash.c @@ -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)<>7)<CR |= page<CR |= FLASH_CR_STRT; #elif defined(STM32L4PLUS) FLASH->CR |= FLASH_CR_PER;