cancel
Showing results for 
Search instead for 
Did you mean: 

Reading and writing to FLASH - H7A3ZI?

RCooke88
Associate III

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

1 ACCEPTED SOLUTION

Accepted Solutions

It reads like other memory so you can use pointers, memcpy() or structures, etc.

You need to write aligned, and multiples of the Flash line width.

You can erase FLASH_SECTOR_SIZE at a minimum. You can write multiple instances of your data/structure, and recover the last one. An exercise referred to as journalling, saves excessive erase/write cycles.

You shrink the size you tell the linker in the .LD (Linker Script) primarily to make it throw an error if you ever hit that limit with your application's code and data. Saves surprises if you use/erase it

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

1 REPLY 1

It reads like other memory so you can use pointers, memcpy() or structures, etc.

You need to write aligned, and multiples of the Flash line width.

You can erase FLASH_SECTOR_SIZE at a minimum. You can write multiple instances of your data/structure, and recover the last one. An exercise referred to as journalling, saves excessive erase/write cycles.

You shrink the size you tell the linker in the .LD (Linker Script) primarily to make it throw an error if you ever hit that limit with your application's code and data. Saves surprises if you use/erase it

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..