HAL_FLASHEx_Erase() fails using FreeRTOS
Hi all,
On an STM32G070, I would like to erase flash sector during execution of freertos but I always have an error HAL_FLASH_ERROR_PGA, and when i use the function HAL_FLASH_Lock() the app crash into HardFault_Handler().
My code
erase_conf.Banks = FLASH_BANK_1;
erase_conf.TypeErase = FLASH_TYPEERASE_PAGES;
erase_conf.Page = cg_flash_get_page(0x08012000);
erase_conf.NbPages = cg_flash_get_page(g_prog_addr[INDEX_TMP_APP] + FLASH_APP_MAX_SIZE - 1) - cg_flash_get_page(g_prog_addr[INDEX_TMP_APP]);
__disable_irq();
HAL_FLASH_Unlock();
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR);
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGSERR);
HAL_FLASHEx_Erase(&erase_conf, &pageError);
state = HAL_FLASH_GetError();
HAL_FLASH_Lock();
//erasure failed (0xFFFFFFFF means that all the pages have been correctly erased)
if(pageError != 0xFFFFFFFF){
cg_error_handler();
}
__enable_irq();
I have tried this code without disabling irq and with susending other task but iwdg task but nothing works.
I also tried this code without freertos and this time it works.
I think there is some kind of conflict beetween freertos and flash erase/write but I don't know where it comes from.
Do you have any ideas?
