iamchritian 发表于 2015-12-24 10:08:23

STM32在KEIL下的工程,编译出来的MAP文件,关于RAM内存的分析


<P>主控CPU为STM32F207ZGT6,RAM 空间为128K,下图为MAP文件中,关于内存地址的分配(keil版本为4.72A)
</P>
<P> </P>
<P>APBAHBPrescTable 0x20000000 Data 16 stm32f2xx_rcc.o(.data)
.data 0x20000010 Section 16 stm32f2x7_eth.o(.data)
.data 0x20000020 Section 4 dhcp.o(.data)
xid 0x20000020 Data 4 dhcp.o(.data)
.data 0x20000024 Section 13 mem.o(.data)
ram 0x20000024 Data 4 mem.o(.data)
ram_end 0x20000028 Data 4 mem.o(.data)
lfree 0x2000002c Data 4 mem.o(.data)
mem_sem 0x20000030 Data 1 mem.o(.data)
.data 0x20000034 Section 12 netif.o(.data)
netifnum 0x20000034 Data 1 netif.o(.data)
.data 0x20000040 Section 4 raw.o(.data)
raw_pcbs 0x20000040 Data 4 raw.o(.data)
.data 0x20000044 Section 4 udp.o(.data)
.data 0x20000048 Section 12 ip.o(.data)
ip_id 0x20000048 Data 2 ip.o(.data)
.data 0x20000054 Section 6 ip_frag.o(.data)
reassdatagrams 0x20000054 Data 4 ip_frag.o(.data)
ip_reass_pbufcount 0x20000058 Data 2 ip_frag.o(.data)
.data 0x2000005a Section 1 etharp.o(.data)
etharp_cached_entry 0x2000005a Data 1 etharp.o(.data)
.data 0x2000005c Section 36 main.o(.data)
.data 0x20000080 Section 12 netconf.o(.data)
.data 0x2000008c Section 8 stm32f2xx_it.o(.data)
.data 0x20000094 Section 44 app.o(.data)
time 0x200000a4 Data 4 app.o(.data)
LED_Flag 0x200000a8 Data 1 app.o(.data)
s_sendcount 0x200000ac Data 4 app.o(.data)
s_Net_Time 0x200000b0 Data 4 app.o(.data)
s_h485tonet 0x200000b4 Data 4 app.o(.data)
.data 0x200000c0 Section 14 h485.o(.data)
Counter10ms 0x200000c3 Data 1 h485.o(.data)
dev 0x200000c4 Data 1 h485.o(.data)
.data 0x200000d0 Section 20 updata.o(.data)
.data 0x200000e4 Section 4 systick.o(.data)
Ticks 0x200000e4 Data 4 systick.o(.data)
.data 0x200000e8 Section 8 udp_com.o(.data)
drop_cnt 0x200000e8 Data 4 udp_com.o(.data)
.data 0x200000f0 Section 4 stdout.o(.data)
.bss 0x200000f4 Section 15572 stm32f2x7_eth.o(.bss)
.bss 0x20003dc8 Section 4116 mem.o(.bss)
ram_heap 0x20003dc8 Data 4116 mem.o(.bss)
.bss 0x20004ddc Section 9947 memp.o(.bss)
memp_tab 0x20004ddc Data 24 memp.o(.bss)
memp_memory 0x20004df4 Data 9923 memp.o(.bss)
.bss 0x200074b8 Section 200 etharp.o(.bss)
arp_table 0x200074b8 Data 200 etharp.o(.bss)
.bss 0x20007580 Section 52 netconf.o(.bss)
.bss 0x200075b4 Section 4096 stm32f2xx_it.o(.bss)
.bss 0x200085b4 Section 5904 app.o(.bss)
.bss 0x20009cc4 Section 1024 crc32.o(.bss)
.bss 0x2000a0c4 Section 5476 h485.o(.bss)
.bss 0x2000b628 Section 2048 updata.o(.bss)
read_data_buf 0x2000b628 Data 1024 updata.o(.bss)
<FONT color=blue>write_data_buf 0x2000ba28</FONT> Data 1024 updata.o(.bss)
<FONT color=red>STACK 0x2000be28 Section 16384 startup_stm32f2xx.o(STACK)</FONT></P>上面红色标记 STACK 的起始地址为 0x2000be28
在这里有几个疑问:
1、栈空间是向低字节地址方向生长的,我定义的栈空间为16K Bytes,那么栈空间从 0x2000be28 地址向下生长,怎么会跟全局变量的地址write_data_buf 0x2000ba28 的地址重合呢?
2、还有个疑问,就是堆空间在起始地址在哪里体现?我定义的堆空间大小为512字节?

moyanming2013 发表于 2015-12-24 10:36:13

看这个能了解程序各段的分布情况,栈的具体大小、起始位置要参考启动文件、分散加载文件及你的启动方式(boot0、boot1)。

Mandelbrot_Set 发表于 2015-12-24 11:00:44

0x2000be28
0x2000ba28
只是长得像而已:L:L

iamchritian 发表于 2015-12-24 11:26:25

moyanming2013 发表于 2015-12-24 10:36
看这个能了解程序各段的分布情况,栈的具体大小、起始位置要参考启动文件、分散加载文件及你的启动方式(bo ...

请问一下,栈指针的地址,堆指针的在RAM中的具体位置,编译过后,应该是确定的吧?
那么在内存地址 0x2000 0000--0x2001 FFFF中的哪个地址?

iamchritian 发表于 2015-12-24 11:28:13

Mandelbrot_Set 发表于 2015-12-24 11:00
0x2000be28
0x2000ba28
只是长得像而已

不是太懂
我的理解:
>write_data_buf 0x2000ba28
这是全局变量write_data_buf的指针位置,大小为1024字节
>STACK 0x2000be28
这是栈指针的位置,大小为16384字节

Mandelbrot_Set 发表于 2015-12-24 11:30:56

本帖最后由 Mandelbrot_Set 于 2015-12-24 12:26 编辑

iamchritian 发表于 2015-12-24 11:28
不是太懂
我的理解:
>write_data_buf 0x2000ba28

STACK是段地址吧(其实这个section里只有栈...)

Mandelbrot_Set 发表于 2015-12-24 12:00:39

本帖最后由 Mandelbrot_Set 于 2015-12-24 12:25 编辑

AREA    STACK, NOINIT, READWRITE, ALIGN=3
Stack_Mem      SPACE   Stack_Size
--------------------------------------------------
In a source file, the AREA directive marks the start of a section. This directive names the section and sets its attributes. The attributes are placed after the name, separated by commas.---------------------------------------------------
这儿Stack_Mem    STACK 地址会相同

wolfgang2015 发表于 2015-12-24 13:25:03

栈址里存放的是栈空间的具体指针而已,压栈操作不是把栈的数据都压入栈内。

iamchritian 发表于 2015-12-24 13:32:42

Mandelbrot_Set 发表于 2015-12-24 12:00
AREA    STACK, NOINIT, READWRITE, ALIGN=3
Stack_Mem      SPACE   Stack_Size
---------------------- ...

栈空间的起始地址,虽然每次编译时,不一样,但是,一旦编译之后就应该确定。
1、上述map文件中,RAM地址 0x2000 be28 应该是栈的起始地址;
2、栈空间是 16384 字节;
3、栈是向地址生长,那么栈的结束地址应该是 0x2000 7E28;
问题:在栈空间:0x2000 7E28 -- 0x2000 be28 这两者的RAM空间中,怎么会有   .bss                                     0x200074b8   Section      200etharp.o(.bss)
    arp_table                              0x200074b8   Data         200etharp.o(.bss)
    .bss                                     0x20007580   Section       52netconf.o(.bss)
    .bss                                     0x200075b4   Section   4096stm32f2xx_it.o(.bss)
    .bss                                     0x200085b4   Section   5904app.o(.bss)
    .bss                                     0x20009cc4   Section   1024crc32.o(.bss)
    .bss                                     0x2000a0c4   Section   5476h485.o(.bss)
    .bss                                     0x2000b628   Section   2048updata.o(.bss)
    read_data_buf                            0x2000b628   Data      1024updata.o(.bss)
    write_data_buf                           0x2000ba28   Data      1024updata.o(.bss)

4、全局变量在编译后,就已经确实,在RAM空间的全局区。

Mandelbrot_Set 发表于 2015-12-24 14:00:52

startup.s的作做法大概是
定义1个section,叫STACK.
里面有一个数组(一块ram),叫Stack_Mem.
栈的设置要代码实现.
map文件并不知道它是栈(STACK只是名字而已,跟代码对应)
页: [1] 2
查看完整版本: STM32在KEIL下的工程,编译出来的MAP文件,关于RAM内存的分析