Changing flash program start address in order to implement EEPROM emulation on STM32F722VET
Hi,
The problem with your setup is that, when resetting the board, the vector table address is not taking the VECT_TAB_OFFSET value into account: this value is used to relocate the vector table in SystemInit, so after your code has started...
You must keep the vector table in place, at address 0x8008000 (offset 0 in the flash), as it is there that the CPU will read its reset vector (in fact the FLASH is remapped at address 0 at reset time, and that’s there it is read by the CPU during the reset sequence).
So you must at least have the two first words of the vector table (Master SP and reset vector) at address 0; the whole of the vector table may be relocated as you do, as there will be no exception before you execute SystemInit and so relocate it.
For this to work you must keep the original memory definition but add a special section at address 0, containing this minimal vector table and, possibly, initial values for your persistent data; this section must have its size manually set to 32kB so that the rest of your code goes at 0x8008000.
Then, of course, your EEPROM emulation must always reprogram the fisrt 8 bytes of the flash with the reset vector (and hope you never crash between erasing the first sector and reprogramming the reset vector...)
A safer, and simpler, way to go would be to keep sector 0 for the vector table only, use sectors 1 and 2 for EEPROM emulation, then place your application code starting at sector 3. Depending on the size of your application sections you may place some code, read-only data or data initialization values in sector 0 (or sector 0 and 1 using 2 and 3 for EEPROM emulation) so that you don’t waste almost 16kB of the first sector,
Hope this helps,
Bernard (Ac6)