Reading and writing to FLASH - H7A3ZI?
Hi Folks,
Is there a simple description on how to read and write to flash using HAL for the STM32H7A3 chip somewhere?
I'm looking at the example in the STM32Cube_FW_H7_V1.11.1 FLASH_erase_program.
My application needs to store ten 8-bit values so I'm not storing much. I figure I can use the last sector of the flash memory.
In the Linker script I changed FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 2040K from 2048K so I can use the last 8K of flash. Question - Do I have to remove 8K blocks? Or can I remove less, like maybe 2K?
In the FLASH_erase_program:
#define FLASH_USER_START_ADDR (FLASH_BASE + (FLASH_SECTOR_SIZE * 4)) /* Start @ of user Flash area in Bank1 */
#define FLASH_USER_END_ADDR (FLASH_BASE + FLASH_BANK_SIZE - 1) /* End @ of user Flash area in Bank1 */
How do I set the Start and End Addresses?
Next question - Should I make FirstSector = 127 since I only need to use the last sector of FLASH for my variables?
FirstSector = GetSector(FLASH_USER_START_ADDR); /* Get the 1st sector to erase */
And should I just set NbOfSectors=1 since I only need 1 sector for the 10 bytes of data?
/* Get the number of sector to erase from 1st sector*/
NbOfSectors = GetSector(FLASH_USER_END_ADDR) - FirstSector + 1;
How do I read the data? I don't understand what's going on in the example. Is this reading the data from the FLASH:
data64 = *(uint64_t*)Address;
I only need to read the data when the equipment is powered on.
Wish this was a little clearer.
Thanks,
Richard
