How to write data into board flash memory?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-08-11 5:12 AM
As I am trying to write the data into board flash memory, Is ther any example code to write the 64bytes of data into board flash memory.
I have tried the below shared code but its not showing the result I want.
flashAddress = 0x08040000
void Write_Flash(uint32_t data)
{
HAL_FLASH_Unlock();
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGSERR );
FLASH_Erase_Sector(FLASH_SECTOR_6, VOLTAGE_RANGE_3);
HAL_FLASH_Program(TYPEPROGRAM_WORD, FlashAddress, data);
HAL_FLASH_Lock();
}
Can you please help me on this.
Solved! Go to Solution.
- Labels:
-
Flash
-
STM32F4 Series
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-08-12 2:46 AM
use this example as reference:
​https://github.com/STMicroelectronics/STM32CubeF4/tree/master/Projects/STM32F429I-Discovery/Applications/EEPROM/EEPROM_Emulation
​
It works for​ me flawlessly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-08-11 5:22 AM
Perhaps look at the HAL examples within the Cube repository for your unspecified STM32 part.
Usually a couple of examples for NUCLEO, DISCO or EVAL boards that will port.
Alternative is to extend what you have, writing subsequent words looping with a pointer, advancing the address.
Might want to handle errors better.
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-08-11 9:26 AM
Include your chip part number.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-08-11 9:45 AM
Do you want to write data in MCU flash memory or another flash memory chip on your board?
the code you mentioned, intended to write data in flash memory embedded in stm32 not external chips.​
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-08-11 10:21 PM
Part no: STM32F492IDISCOVERY
I want to write data into MCU flash memory.
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 2048K
What are the steps to be followed in code for writing into flash? finding example for it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-08-11 10:33 PM
To be sure: The code only writes one word = 32 bits. Is this only due to the example?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-08-11 10:40 PM
Yes, It will write only one word = 32bits, but the code is not writing ino specified address. If it works for one word we can make it for other addresses as well by adding loop. Is that shared code is correct in order to write one word.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-08-11 10:51 PM
What is about this?
/* Fill EraseInit structure*/
EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES;
EraseInitStruct.PageAddress = FLASH_USER_START_ADDR;
EraseInitStruct.NbPages = (FLASH_USER_END_ADDR - FLASH_USER_START_ADDR) / FLASH_PAGE_SIZE;
if (HAL_FLASHEx_Erase(&EraseInitStruct, &PAGEError) != HAL_OK)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-08-12 2:46 AM
use this example as reference:
​https://github.com/STMicroelectronics/STM32CubeF4/tree/master/Projects/STM32F429I-Discovery/Applications/EEPROM/EEPROM_Emulation
​
It works for​ me flawlessly.
