AnsweredAssumed Answered

HAL_FLASHEx_Erase() fails using FreeRTOS

Question asked by Adriano Melis on Dec 15, 2017
Latest reply on Feb 18, 2018 by Yeho S

Hi all,

I am developing a bootloader + update system which needs FLASH pages manipulation (unlock/erase/program) from a FreeRTOS task.


The same unlock/erase code works fine if called before the os scheduler is launched, but fails when called from a task. What I am missing?





MCU: Cortex L4

Firmware version: STM32Cube_FW_L4_V1.8.1



int erase_partition(const uint8_t *addr)


    int ret = HAL_OK;

    uint32_t PAGEError = 0;

    FLASH_EraseInitTypeDef EraseInitStruct;



    /* Unlock the Flash to enable the flash control register access *************/

    ret = HAL_FLASH_Unlock();

    if (ret != HAL_OK) {


        return ret;



    /* Clear OPTVERR bit set on virgin samples */


    EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES;

    EraseInitStruct.Banks = FLASH_BANK_1;

    EraseInitStruct.Page = get_page((uint32_t)addr);

    EraseInitStruct.NbPages = APP_NUMPAGES;


    ret = HAL_FLASHEx_Erase(&EraseInitStruct, &PAGEError);

    if (ret != HAL_OK) {

        ret = HAL_FLASH_GetError();

        return ret;


    return HAL_OK;