Question
STM32WB55, write in the internal flash memory with FreeRTOS
Hi,
I try to save the configuration application in the internal flash memory of my STM32WB55 with this next fonction :
static int write(long offset, const uint8_t *buf, size_t size)
{
size_t i;
uint32_t addr = stm32wb_onchip_flash.addr + offset;
volatile __ALIGN_BEGIN uint64_t write_data __ALIGN_END;
volatile __ALIGN_BEGIN uint64_t read_data __ALIGN_END;
vTaskSuspendAll();
__HAL_FLASH_CLEAR_FLAG(0xFFFFFFFF);
HAL_FLASH_Unlock();
__enable_irq(); //To be sure that HAL_FLASH_Program to not bloc in get tick function
for (i = 0; i < size; i+=8, buf+=8, addr+=8)
{
memcpy(&write_data, buf, 8);
/* write data */
while(LL_FLASH_IsActiveFlag_OperationSuspended());
volatile HAL_StatusTypeDef status = HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD,addr, write_data);
if (status != HAL_OK)
{
volatile uint32_t lastFlashError = HAL_FLASH_GetError();
return -1;
}
read_data = *(uint64_t *)addr;
/* check data */
if (read_data != write_data)
{
__NOP();
return -1;
}
}
// vPortExitCritical();
HAL_FLASH_Lock();
xTaskResumeAll();
return size;
}This function works very well at initialization of the application. But when i call this function from a FreeRTOS task the HAL_FLASH_Program function return to me an error. The error is 0xA0, PGA error, but this function is always called with align adresse.
I already checked the option bytes without sucess... May be somebody have an idea to help me :\
Thank you.
