I'm writing some basic bare-metal C code for my stm32f767zi board (using Keil uVision IDE if that matters too) and I would like my vector table (and at some point all the .text stuff too) to have a LMA in flash via the AXIM bus and a VMA in flash via the ITCM bus. Something like the following in the linker script is what I want:
MEMORY
{
FLASH_AXIM (rwx) : ORIGIN = 0x08000000, LENGTH = 0x001FFFFF
FLASH_ITCM (rx) : ORIGIN = 0x00200000, LENGTH = 0x001FFFFF
}
SECTIONS
{
.vector_table : ALIGN(4)
{
KEEP(*(.vectors))
. = ALIGN(4);
} > FLASH_ITCM AT > FLASH_AXIM /* VMA in ITCM flash, LMA in AXIM flash */
...
This linker script causes the program to not work and hang when trying to debug it. When the program is hanging, the debugger shows that (when doing memory reads in Keil uVision memory window) the data at addresses 0x08000000 and 0x00200000 are exactly the same i.e.
Reading memory at address 0x08000000:
0x08000000: 00 F4 01 20 1D 02 20 00 9D .....
Reading memory at address 0x00200000:
0x00200000: 00 F4 01 20 1D 02 20 00 9D .....
Which, to me, reaffirms that the AXIM flash and ITCM flash funnel down to the exact same physical flash and loading the program in flash via the AXIM bus and then reading instructions from flash via the ITCM bus SHOULD work... but it doesn't, at least not with my current setup.
Instead I have to modify the linker script to the following to get the program to run smoothly and be able to start debugging in the reset handler:
MEMORY
{
FLASH_AXIM (rwx) : ORIGIN = 0x08000000, LENGTH = 0x001FFFFF
FLASH_ITCM (rx) : ORIGIN = 0x00200000, LENGTH = 0x001FFFFF
}
SECTIONS
{
.vector_table : ALIGN(4)
{
KEEP(*(.vectors))
. = ALIGN(4);
} > FLASH_AXIM /* VMA and LMA in AXIM flash */
Why does changing the VMA of the .vector_table output section to be the same as the LMA make the difference between my ability to run the program? Also note that if I set the VMA and LMA of the .vector_table output section to be in FLASH_ITCM instead of FLASH_AXIM, I get a Keil uVision flash programming error about mismatched data in flash.
Solved, it was an issue of the LMA of the .text section (following the .vector_table section) not being aligned as the VMA was requested to be aligned. See https://github.com/DISTORTEC/distortos/commit/12765ae58aefad3d51d579a3b90c0abbb7eb75a0 for a more detailed explanation.