2017-12-15 07:26 AM
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?thanks,
Adriano
MCU: Cortex L4
Firmware version: STM32Cube_FW_L4_V1.8.1
code:
int erase_partition(const uint8_t *addr)
{
int ret = HAL_OK;
uint32_t PAGEError = 0;
FLASH_EraseInitTypeDef EraseInitStruct;
HAL_FLASH_Lock();
/* 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 */
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR);
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;
}
2017-12-17 05:04 AM
What error are you receiving?
2017-12-17 01:54 PM
What happens if you disable interrupts for the duration of this function? It may be that a task switch occurs and that this is bad. Just guessing based on the behaviour you describe. Does it fail every time?
2017-12-18 06:43 AM
The peripheral uses interrupts so...
You can try changing the task's priority to be the highest priority so that task swaps don't occur. The L4 will automatically reset after some flash operations so beware of that. I follow the method described in
for L4 and haven't had any problems. Also, this has some useful information.2018-02-18 12:34 AM
Hey Adriano,
I'm facing quite the same problem.
I'm running the simple ST FlashErase example on my L4 custom board, and it works great,
but when calling FreeRTOS' osKernelStart() routine and trying to use the example from within a task, it fails and generates the FLASH_FLAG_PGAERR and FLASH_FLAG_PGSERR inside the HAL_FLASHEx_Erase() routine.
I also read about working with this flash driver under FreeRTOS and tried disabling the interrupts before the flash activity and re-enabling them afterwards, but the result was the same.
Have you ever found an answer for this issue?
Thanks in advance,
Yeho.