Question
MCU:STM32G0B1 fails flash page erase with HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t *PageError)
Why using:
/* Fill EraseInit structure*/
EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES;
EraseInitStruct.Banks = FLASH_BANK_1;
EraseInitStruct.Page = StartPage;
EraseInitStruct.NbPages = ((EndPage - StartPage)/FLASH_PAGE_SIZE) +1; /* For example 32 */HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t *PageError)causes HAL_Error and calling
uint32_t HAL_FLASH_GetError(void)shows that bits:
HAL_FLASH_ERROR_PGA
HAL_FLASH_ERROR_SIZ
HAL_FLASH_ERROR_PGSare set?
And how to fix it?
EDIT1:
Calculate the number of pages to be erased correctly.
EraseInitStruct.NbPages = (EndPage - StartPage) +1;