AnsweredAssumed Answered

stm32f0 help with flash, to read and write + hal libraries

Question asked by espinoza.iran on Sep 22, 2015
Latest reply on Sep 29, 2015 by espinoza.iran
Hi all, I wonder if anyone knows how to read and write to the flash stm32f0, using hal libraries ?. What I hold, it is to store some values in real time, and when you restart the device, are present (such as EEPROM of the pics, and I know what are the differences between flash and EEPROM). Basically I read that in order to write, you have to unlock with:

HAL_FLASH_Unlock (void);

Then, you have to delete, either by page, or if all with:

FLASH_EraseInitTypeDef erase_pages;
erase_pages.PageAddress = 0x08000000;
erase_pages.NbPages = 1;
erase_pages.TypeErase = TYPEERASE_PAGES;
uint32_t * Error;

// To write this done BEFORE
HAL_FLASH_Unlock ();
HAL_FLASHEx_Erase (& erase_pages, error);
HAL_FLASH_Lock ();

HAL_FLASH_Unlock ();
  HAL_FLASH_Program (TYPEPROGRAM_HALFWORD, 0x08000000, Data_config [0]);
HAL_FLASH_Lock ();

Data_config [0] = * ((uint16_t *) 0x08000000); // Read flash memory at address 0x08000000

From here, it stays stuck in:

HAL_FLASHEx_Erase (& erase_pages, error);

I know the flash memory starts at: 0x08000000, and only occupy one page to try to record a value, switch off the device, read, and verify that indeed the recorded data is left.

I guess I'm pounding of the code, for that reason, don´t advance, i tell to you that I do not use bootloader.

Greetings, and if someone could give me a guide, they are grateful enough.