cancel
Showing results for 
Search instead for 
Did you mean: 

How to use the FLASH area like eeprom ?

MJung.7
Associate

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 

2 REPLIES 2

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?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

> 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".