Skip to main content
angeliran
Associate III
September 22, 2015
Question

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

Posted on September 22, 2015 at 22:29

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 ();

// WRITE ONLY AFTER AN ERASE PAGE

HAL_FLASH_Unlock ();

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

HAL_FLASH_Lock ();

// READ

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.
    This topic has been closed for replies.

    12 replies

    Tesla DeLorean
    Guru
    September 28, 2015
    Posted on September 28, 2015 at 22:47

    The last doubts Clive, did you know why need to do the hole between iROM1 and iROM2? why not only cut at the end with one iROM?

    Indeed why not? As I explained in the STM32F4[DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flash%20as%20EEPROM%20%20FW%20Code%20Image%20Collision%20%28avoiding%29&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&TopicsView=https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/AllItems.aspx&currentviews=60]thread you inserted yourself into, the reason you'd want a hole in the F2/F4 parts is because of the non-uniform sector arrangement, and the large/slow blocks being at the end, and the small ideal ones near the front. The F0 is different, as I explained.

    The answers aren't always the same, it often depends on the context, and the parts you're using, and what you want to achieve.

    I just try to manage the questions as they are thrown to me, even when people post off-topic in a thread.
    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    angeliran
    angeliranAuthor
    Associate III
    September 29, 2015
    Posted on September 29, 2015 at 23:14

     Ok Clive, the doubt is why we need to make a modification in programming configuration, not by default. So yes, I am grateful that I could finally move forward, as I was stuck. I have readed in the other discusion, your answer to me, thx again.