Changing flash program start address in order to implement EEPROM emulation on STM32F722VET
I’m working on a project based on a STM32F722VET using the HAL drivers. I have a few sensors that I read and a calibration routine to get the best values out of them. I want to store the calibration coefficients in non-volatile memory so that I don’t have to go through the calibration routine every time I power on the device. I was planning to use the EEPROM emulation code provided by ST, but they don’t have a version for the F7.
I have used the F3 version on a previous F3-based project I was working on and it worked fine. I set the two pages to be the last two pages of flash and had no issues. The F7 breaks up its memory into 8 variable sized memory ‘sectors’ rather than a bunch of equal sized ‘pages’ like the F3. I believe the F4 also uses ‘sectors’ because the EEPROM emulation code for the F4 references ‘sectors’. However, the F4 version is based on SPL, not HAL. I was thinking I could cobble together an F7 version by copying bits and pieces from the F3 and F4 version, but before I start that project, I have another issue.
The F722VET has 512kb of flash broken into 8 sectors as follows:
S0-S3 : 16kb each
S4 : 64kb
S5-S7 : 128kb each
By default, system workbench writes the application memory starting at the beginning of sector 0 (0x08000000). EEPROM emulation requires blocking off two sectors to work, but I don’t want to use the last two because that would be half of my flash, I need that space for the application. I’d like to use the first two sectors since they are small and then use sectors 2-7 for the application. In order for this to work, I have to change where system workbench writes application memory during programming.
I found this related post and tried some of the things mentioned.
Under “STM32F722VETx_FLASH.ld”, I changed:
**********************
MEMORY
{
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 256K
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 512K
}
**********************
to
**********************
MEMORY
{
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 256K
FLASH (rx) : ORIGIN = 0x8008000, LENGTH = 480K
}
**********************
Under “system_stm32f7xx.c”, I changed
#define VECT_TAB_OFFSET 0x00
to
#define VECT_TAB_OFFSET 0x8000
Then I erased the chip, did a clean build, and reprogrammed. Starting a Debug instance worked but if I just hit the “Run” button instead, it does not work. I looked at the memory using STM32 ST-LINK utility and I noticed that Sectors 0 and 1 (0x08000000 - 0x08007FFF) were no longer blank (all FFF...FF). The first bytes up to about 0x08000080 were occupied and then the rest were all 0s. I also noticed that the ASCII code for the first few bytes includes “ELF” which is suspicious. After that, at 0x08008000, the rest of the code begins as expected (with 0x20040000 as the first entry which I believe is what it should be). It’s OK if the first sectors get erased during programming because I don’t need to store calibration coefficients through reprogramming, but of course I do need the program to run without debug mode.
What steps have I missed? I feel like it might be related to the “isr_vector_start” line mentioned in the post I referred to before. But I don’t understand what that is or what it does.
Thank you!