Use first flash sectors for user data? - Printable Version
+- Forums (https://www.embitz.org/forum)
+-- Forum: ARM toolchains (https://www.embitz.org/forum/forum-8.html)
+--- Forum: ArmGCC - EmBlocks (https://www.embitz.org/forum/forum-14.html)
+--- Thread: Use first flash sectors for user data? (/thread-781.html)
Use first flash sectors for user data? - mri - 02-17-2017
I'm using a STM32F411VET6, which have 8 flash sectors. The first 4 sectors are 16 kbyte each.
I'd like to use two of these sectors for user parameters, preferably so that when downloading the application when debugging using the STLINK/V2 dongle, those user parameters are not overwritten.
I've done some initial attempts and modified the linker script so that ROM start from sector 2, like this:
/* Memory Spaces Definitions */
ROM (rx) : ORIGIN = 0x08008000, LENGTH = 480K
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 128K
I can see in map-file that code is now placed starting from sector 2.
I also modify STLINK/V2 debug interface setting in EmBitz, "Vector table start" to 0x08008000,
and in system_stm32f4xxx.c I set vector table offset to:
#define VECT_TAB_OFFSET 0x8000
But, it doesn't work. When i start the debugger, it downloads the program, but I am unable to start it.
What am I missing?
Is it possible at all?
I'm using EmBitz 1.11
RE: Use first flash sectors for user data? - mri - 02-17-2017
OK, so the debugger is no completely dead.
The application is loaded starting from sector 2:
Now when looking in Disassembly window, I can see pc is standing in the Reset_Handler.
I can single step there, BUT, it is executing at wrong address.
pc is 0x08001B84 when it should be 0x08009b84 (according to the map-file, Reset_Handler is located at 0x08009b84).
I.e. the 0x00008000 offset is missing.
Why is this happening, when gdb seems to load the program to the correct location?
RE: Use first flash sectors for user data? - mri - 02-18-2017
OK, I figured out a workaround.
I keep the interrupt vectors in the first flash sector, so I don't have to sort out the relocation problems.
Then I use sector 1 and 2 for user parameters, and sector 3 and onwards for .text, .data, .bss etc.
So this is all solved in the linker script:
So I have created a "hole" for sector 1 and 2. I can see that debugger does not touch sector 1 and 2 when loading the program into flash.
Sector 0 now holds the interrupt vectors. Because the interrupt vectors don't fill up the whole 16 kbyte sector, there is room left for adding various code in there, in case I run low on flash memory.
RE: Use first flash sectors for user data? - OliviliK - 02-18-2017
This sounds a good idea - thanks for sharing.