Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
271 views
in Technique[技术] by (71.8m points)

keil - STM32F7 VMA and LMA with AXIM/ITCM flash

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.

question from:https://stackoverflow.com/questions/65838906/stm32f7-vma-and-lma-with-axim-itcm-flash

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...