2020-08-11 05: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.
2020-08-12 02: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.
2020-08-11 05: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.
2020-08-11 09:26 AM
Include your chip part number.
2020-08-11 09: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.
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.
2020-08-11 10:33 PM
To be sure: The code only writes one word = 32 bits. Is this only due to the example?
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.
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)
2020-08-12 02: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.