stm32L5 write flash problem
Hi. I am testing flash read and write operations.
In the main function, when I write 1 to address 0x08006000, I can correctly read back 1. However, when using FreeRTOS and performing the same operation within a task, I read back garbled values (such as 191, 111, etc.).
I was wondering if it's a problem with my functions or it's not usable within FreeRTOS.
void main()
{
FLASH_Write(ADDRESS, &data);
printf("ADDRESS:%d\n",FLASH_Read(ADDRESS));
}
void FLASH_Write(uint32_t Address, uint8_t *pData)
{
HAL_FLASH_Unlock();
FLASH_EraseInitTypeDef EraseInitStruct;
EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES;
EraseInitStruct.Page = 12; //address 08006000
EraseInitStruct.Banks = FLASH_BANK_1;
EraseInitStruct.NbPages = 1;
uint32_t PageError;
HAL_StatusTypeDef status = HAL_FLASHEx_Erase(&EraseInitStruct, &PageError);
/* FLASH word program */
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS);
HAL_StatusTypeDef status2 = HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, Address, pData);
/* Lock the Flash to disable the flash control register access */
HAL_FLASH_Lock();
}
uint8_t FLASH_Read(uint32_t Address)
{
return (*(uint8_t *)(Address));
}
