让我们看一下STM32F103链接器脚本:
/* Entry Point */
ENTRY(Reset_Handler)
/* Highest address of the user mode stack */
_estack = 0x20005000; /* End of 20K RAM */
/* Generate a link error if heap and stack don't fit into RAM */
_Min_Heap_Size = 0; /* Required amount of heap */
_Min_Stack_Size = 0x100; /* Required amount of stack */
/* Specify the memory areas */
MEMORY
{
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 128K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 20K
MEMORY_B1 (rx) : ORIGIN = 0x60000000, LENGTH = 0K
}
/* Define output sections */
SECTIONS
{
/* The startup code goes first into FLASH */
.isr_vector :
{
. = ALIGN(4);
KEEP(*(.isr_vector)) /* Startup code */
. = ALIGN(4);
} >FLASH
/* The program code and other data goes into FLASH */
.text :
{
. = ALIGN(4);
*(.text) /* .text sections (code) */
*(.text*) /* .text* sections (code) */
*(.rodata) /* .rodata sections (constants, strings, etc.) */
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
*(.glue_7) /* Glue arm to thumb code */
*(.glue_7t) /* Glue thumb to arm code */
KEEP (*(.init))
KEEP (*(.fini))
. = ALIGN(4);
_etext = .; /* Define a global symbols at end of code */
} >FLASH
.ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH
.ARM : {
__exidx_start = .;
*(.ARM.exidx*)
__exidx_end = .;
} >FLASH
.ARM.attributes : { *(.ARM.attributes) } > FLASH
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array*))
PROVIDE_HIDDEN (__preinit_array_end = .);
} >FLASH
.init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array*))
PROVIDE_HIDDEN (__init_array_end = .);
} >FLASH
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(.fini_array*))
KEEP (*(SORT(.fini_array.*)))
PROVIDE_HIDDEN (__fini_array_end = .);
} >FLASH
/* Used by the startup to initialize data */
_sidata = .;
/* Initialized data sections goes into RAM, load LMA copy after code */
.data : AT ( _sidata )
{
. = ALIGN(4);
_sdata = .; /* Create a global symbol at data start */
*(.data) /* .data sections */
*(.data*) /* .data* sections */
. = ALIGN(4);
_edata = .; /* Define a global symbol at data end */
} >RAM
/* Uninitialized data section */
. = ALIGN(4);
.bss :
{
/* This is used by the startup in order to initialize the .bss secion */
_sbss = .; /* Define a global symbol at BSS start */
__bss_start__ = _sbss;
*(.bss)
*(.bss*)
*(COMMON)
. = ALIGN(4);
_ebss = .; /* Define a global symbol at BSS end */
__bss_end__ = _ebss;
} >RAM
PROVIDE ( end = _ebss );
PROVIDE ( _end = _ebss );
/* User_heap_stack section, used to check that there is enough RAM left */
._user_heap_stack :
{
. = ALIGN(4);
. = . + _Min_Heap_Size;
. = . + _Min_Stack_Size;
. = ALIGN(4);
} >RAM
/* MEMORY_bank1 section, code must be located here explicitly */
/* Example: extern int foo(void) __attribute__ ((section (".mb1text"))); */
.memory_b1_text :
{
*(.mb1text) /* .mb1text sections (code) */
*(.mb1text*) /* .mb1text* sections (code) */
*(.mb1rodata) /* read-only data (constants) */
*(.mb1rodata*)
} >MEMORY_B1
/* Remove information from the standard libraries */
/DISCARD/ :
{
libc.a ( * )
libm.a ( * )
libgcc.a ( * )
}
}我可以看到ISR向量被放置在闪存中,所以如果程序需要调用存储在某个向量中的地址,它就会从闪存中读取。
第一个问题:,硬件如何不影响从内存读取和闪存之间的区别?为什么我需要特殊的寄存器才能在代码中写入或读取闪存,而不能只显式地写入或读取其地址?
第二个问题是关于从闪存读取比从RAM读取慢多少?如果我知道在我的代码中使用最多的是哪个函数,那么我是否能够将它移动到RAM部分来加速它的执行呢?我相信这个脚本中的MEMORY_B1就是为了这个目的而制作的。
第三个问题:如果MEMORY_B1的长度为0,我们如何在MEMORY_B1中放置任何东西?
和最后一个问题:,如果我在闪存中创建一个额外的部分,那么我可以创建一些虚拟内存的简单模拟吗?我认为这个问题的答案取决于第一个问题。
发布于 2017-01-03 20:37:07
发布于 2017-01-16 15:47:59
1/2.不在STM32F1上。只有在核心速度超过100兆赫时,闪存预取和缓存丢失才会让你付出代价。甚至这个芯片都有缓存和预取。有了这个核心,如果在某些特殊情况下将向量表放入RAM中,可能会获得微不足道的小利润。
但是,可能存在适用于所使用的访问宽度的硬件限制。但是这个闪光不受此影响。
3.是的,你当然可以。你可以在里面放一个文件系统。但是你可以可靠地写闪光灯的温度范围是有限的。而且,由于只有一个闪存库,所有活动都会停止,直到擦除/闪存成功为止。除非代码是从RAM运行的。另外两个注意事项是,flash编程/擦除可能需要毫秒时间,而且您必须考虑到每个kB的页擦除,但所有闪存控制器都必须这样做。
如果你需要额外的RAM,在你的板上放一些SPI FRAM。
https://stackoverflow.com/questions/41447813
复制相似问题