2019-04-28 07:49 PM
Hi, all
I am developing STM32F030K6 model.
Unlike other MCUs, the STM32 model did not have an eeprom area. Therefore, using the Flash area,
I tried coding and proceeding as shown below,
I just used the WriteFlash() in main func, but it did not work properly.
/////////////////////////////////////////////////////////////////////
FLASH_EraseInitTypeDef g_pEraseInit;
void WriteFlash(uint32_t address, uint32_t data)
{
g_pEraseInit.TypeErase = FLASH_TYPEPROGRAM_WORD;
g_pEraseInit.PageAddress = address;
g_pEraseInit.NbPages = 4;
uint32_t pageError = 0 ;
HAL_FLASH_Unlock();
HAL_FLASHEx_Erase(&g_pEraseInit, &pageError);
HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD ,address, data);
HAL_FLASH_Lock();
}
uint32_t ReadFlash(uint32_t address)
{
uint32_t flash_Data;
flash_Data = *(uint32_t*)address;
return flash_Data;
}
/////////////////////////////////////////////////////
Should I have something to set aside? (ex: configruation bit)
Please ask for various opinions.
best regards
2019-04-28 08:57 PM
Pity you don't provide more complete context.
What address?
Why erase FOUR pages to accommodate FOUR bytes?
>>I just used the WriteFlash() in main func, but it did not work properly.
What does it actually do?
Any of these functions throw an error or status indication?
Does the erase work?
2019-04-28 10:35 PM
> Why erase FOUR pages to accommodate FOUR bytes?
Perhaps this is the crux of the matter - ignorance of the fact that Flash has only page/sector-wide erase, unlike "EEPROM".