STM32F1系列.map文件分析

本文详细解析了.map文件的五个关键部分,包括函数调用关系、优化的冗余函数、标签分类、内存映射及组件大小,阐述了其在STM32F1代码优化中的重要作用。

一、概述

我们通过学习STM32F1知道,想要优化代码就必须知道工程的rom和ram的占用情况。所以,我们就要用到.map文件,通过分析.map文件,可以方便查看工程rom和ram的占用情况,包括单个源文件甚至每个函数的rom。

问:那.map到底可以分为几个部分呢?

答:通过仔细阅读.map文件,我们可以大致分为5个部分:

  • 列出不同函数的调用关系

  • 列出被MDK优化的冗余函数

  • 列出局部标签和全局标签

  • 列出映像文件的内存映射

  • 列出映像文件的组件大小

二、.map文件分析

1.基本概念

段(section):描述映像文件的代码和数据块。

RO:Read-Only的缩写,包括RO-data(只读数据)和RO-code(代码)。

RW:Read-Write的缩写,主要是RW-data,Rw-data由程序初始化初始值。

ZI:Zero-initialized的缩写,主要是ZI-data,由编程器初始化为0。

.text:与RO-code同义

.constdata:与RO-data同义

.bss:与ZI-data同义,通常是指存放未初始化的全局变量的区域

.data:与RW-data同义

2.实例分析

第一部分:

这部分代码反映出了各个函数的调用关系,比如箭头就表明了main文件代码段里就调用了led文件代码段里的LED_Init函数。

第二部分:

MDK里面有一个配置选项,假设没勾选可以看出编译器优化了3个冗余函数,大概50个字节。接着我们把选项打开,再全编译一下看看结果。

这时候就很明显可以看出编译器优化了很多没用到的代码了,节省了起码3258个字节的空间。所以个人建议以后大家创建工程的时候还是把选项选上吧。

第三部分:

问:什么是局部标签?什么是全局标签?

答:局部标签就是在函数内部用static声明的变量,还有用static声明的函数,基本上都是属于局部标签;全局标签就是不是用static声明的这种静态的变量和函数,是auto声明的全局变量和C文件函数就属于全局标签。还有就是汇编文件里面的变量如果作用域是本文件的就是局部标签,作用域是全工程的就是全局标签。

其实我觉得我们不用很会区分这些,反正就这两个标号,不在局部里就肯定在全局里,懂得在.map里面找就行了。

这个i.这个前缀就表示是在某个文件里面的某个函数,例如这里的stm32f10x_it文件里面的BusFault_Handler函数;这个SetSysClock要注意一下,为什么前面用i.前缀修饰过的函数,后面又出现一次呢?原来是因为这个函数是用static修饰的一个局部标签函数,用了8个字节的RAM大小,类型属于M3的Thumb指令代码。

第四部分:

这里主要有几个点,首先就是映像的入口地址0x8000131,然后可以知道加载域的起始地址,大小,最后知道执行域ROM和RAM的起始地址和大小。

还有要注意的是,在执行映像之前,必须将已初始化的RW数据从ROM中复制到RAM中的执行地址并创建ZI Section(初始化为0的变量区)。

问:为什么要这么做呢?谁来完成这一步骤呢?

答:因为我们的代码是存在Flash里面的,一上电代码并不会在ROM里面运行,我们得先把ROM里面的代码复制到RAM里面才能运行起来。这一步骤应该是由__main这个函数封装起来执行的。

总体来说,我们编译出来的代码,Code、RO-data和RW-data这几部分都是存在FLASH里面的,然后通过启动文件把RW数据复制到RAM中运行。

第五部分:

最后一部分就比较简单了,无非就是各个映像组件在各个文件中的代码大小,我们比较关心的是实际下载到FLASH中的大小,例如上面的Total ROM Size。

总结:

以上就是我对.map文件的简单分析,可能有些地方讲的不好,请各位大佬指出。谢谢!

Build started: Project: BC26-Smoker *** Using Compiler 'V5.06 update 6 (build 750)', folder: 'C:\迅雷下载\keil ruanj\ARM\ARMCC\Bin' Build target 'Target 1' compiling stm32f1xx_hal_gpio.c... ..\libarary\inc\stm32f1xx.h(140): error: #35: #error directive: "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" ..\libarary\src\stm32f1xx_hal_gpio.c: 0 warnings, 1 error compiling stm32f1xx_hal_adc.c... ..\libarary\inc\stm32f1xx.h(140): error: #35: #error directive: "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" ..\libarary\src\stm32f1xx_hal_adc.c: 0 warnings, 1 error compiling stm32f1xx_hal_pwr.c... ..\libarary\inc\stm32f1xx.h(140): error: #35: #error directive: "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" ..\libarary\src\stm32f1xx_hal_pwr.c: 0 warnings, 1 error compiling stm32f1xx_hal_tim.c... ..\libarary\inc\stm32f1xx.h(140): error: #35: #error directive: "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" ..\libarary\src\stm32f1xx_hal_tim.c: 0 warnings, 1 error compiling stm32f1xx_hal_exti.c... ..\libarary\inc\stm32f1xx.h(140): error: #35: #error directive: "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" ..\libarary\src\stm32f1xx_hal_exti.c: 0 warnings, 1 error compiling stm32f1xx_hal_flash.c... ..\libarary\inc\stm32f1xx.h(140): error: #35: #error directive: "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" ..\libarary\src\stm32f1xx_hal_flash.c: 0 warnings, 1 error compiling stm32f1xx_hal_dma.c... ..\libarary\inc\stm32f1xx.h(140): error: #35: #error directive: "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" ..\libarary\src\stm32f1xx_hal_dma.c: 0 warnings, 1 error compiling stm32f1xx_hal_rcc.c... ..\libarary\inc\stm32f1xx.h(140): error: #35: #error directive: "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" ..\libarary\src\stm32f1xx_hal_rcc.c: 0 warnings, 1 error compiling stm32f1xx_hal_adc_ex.c... ..\libarary\inc\stm32f1xx.h(140): error: #35: #error directive: "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" ..\libarary\src\stm32f1xx_hal_adc_ex.c: 0 warnings, 1 error compiling misc.c... C:\Users\34317\AppData\Local\Arm\Packs\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(8347): error: #5: cannot open source input file "stm32f10x_conf.h": No such file or directory #include "stm32f10x_conf.h" ..\libarary\src\misc.c: 0 warnings, 1 error compiling stm32f1xx_hal_rcc_ex.c... ..\libarary\inc\stm32f1xx.h(140): error: #35: #error directive: "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" ..\libarary\src\stm32f1xx_hal_rcc_ex.c: 0 warnings, 1 error compiling stm32f1xx_hal_gpio_ex.c... ..\libarary\inc\stm32f1xx.h(140): error: #35: #error directive: "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" ..\libarary\src\stm32f1xx_hal_gpio_ex.c: 0 warnings, 1 error compiling stm32f1xx_hal_cortex.c... ..\libarary\inc\stm32f1xx.h(140): error: #35: #error directive: "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" ..\libarary\src\stm32f1xx_hal_cortex.c: 0 warnings, 1 error compiling stm32f1xx_hal_flash_ex.c... ..\libarary\inc\stm32f1xx.h(140): error: #35: #error directive: "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" ..\libarary\src\stm32f1xx_hal_flash_ex.c: 0 warnings, 1 error compiling stm32f1xx_hal.c... ..\libarary\inc\stm32f1xx.h(140): error: #35: #error directive: "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" ..\libarary\src\stm32f1xx_hal.c: 0 warnings, 1 error compiling stm32f1xx_hal_tim_ex.c... ..\libarary\inc\stm32f1xx.h(140): error: #35: #error directive: "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" ..\libarary\src\stm32f1xx_hal_tim_ex.c: 0 warnings, 1 error compiling stm32f1xx_hal_uart.c... ..\libarary\inc\stm32f1xx.h(140): error: #35: #error directive: "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" ..\libarary\src\stm32f1xx_hal_uart.c: 0 warnings, 1 error compiling stm32f10x_adc.c... C:\Users\34317\AppData\Local\Arm\Packs\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(8347): error: #5: cannot open source input file "stm32f10x_conf.h": No such file or directory #include "stm32f10x_conf.h" ..\libarary\src\stm32f10x_adc.c: 0 warnings, 1 error compiling stm32f10x_bkp.c... C:\Users\34317\AppData\Local\Arm\Packs\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(8347): error: #5: cannot open source input file "stm32f10x_conf.h": No such file or directory #include "stm32f10x_conf.h" ..\libarary\src\stm32f10x_bkp.c: 0 warnings, 1 error compiling stm32f10x_can.c... C:\Users\34317\AppData\Local\Arm\Packs\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(8347): error: #5: cannot open source input file "stm32f10x_conf.h": No such file or directory #include "stm32f10x_conf.h" ..\libarary\src\stm32f10x_can.c: 0 warnings, 1 error compiling stm32f10x_cec.c... C:\Users\34317\AppData\Local\Arm\Packs\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(8347): error: #5: cannot open source input file "stm32f10x_conf.h": No such file or directory #include "stm32f10x_conf.h" ..\libarary\src\stm32f10x_cec.c: 0 warnings, 1 error compiling stm32f10x_crc.c... C:\Users\34317\AppData\Local\Arm\Packs\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(8347): error: #5: cannot open source input file "stm32f10x_conf.h": No such file or directory #include "stm32f10x_conf.h" ..\libarary\src\stm32f10x_crc.c: 0 warnings, 1 error compiling stm32f10x_dac.c... C:\Users\34317\AppData\Local\Arm\Packs\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(8347): error: #5: cannot open source input file "stm32f10x_conf.h": No such file or directory #include "stm32f10x_conf.h" ..\libarary\src\stm32f10x_dac.c: 0 warnings, 1 error compiling stm32f10x_dbgmcu.c... C:\Users\34317\AppData\Local\Arm\Packs\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(8347): error: #5: cannot open source input file "stm32f10x_conf.h": No such file or directory #include "stm32f10x_conf.h" ..\libarary\src\stm32f10x_dbgmcu.c: 0 warnings, 1 error compiling stm32f10x_dma.c... C:\Users\34317\AppData\Local\Arm\Packs\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(8347): error: #5: cannot open source input file "stm32f10x_conf.h": No such file or directory #include "stm32f10x_conf.h" ..\libarary\src\stm32f10x_dma.c: 0 warnings, 1 error compiling stm32f10x_exti.c... C:\Users\34317\AppData\Local\Arm\Packs\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(8347): error: #5: cannot open source input file "stm32f10x_conf.h": No such file or directory #include "stm32f10x_conf.h" ..\libarary\src\stm32f10x_exti.c: 0 warnings, 1 error compiling stm32f10x_flash.c... C:\Users\34317\AppData\Local\Arm\Packs\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(8347): error: #5: cannot open source input file "stm32f10x_conf.h": No such file or directory #include "stm32f10x_conf.h" ..\libarary\src\stm32f10x_flash.c: 0 warnings, 1 error compiling stm32f10x_fsmc.c... C:\Users\34317\AppData\Local\Arm\Packs\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(8347): error: #5: cannot open source input file "stm32f10x_conf.h": No such file or directory #include "stm32f10x_conf.h" ..\libarary\src\stm32f10x_fsmc.c: 0 warnings, 1 error compiling stm32f10x_gpio.c... C:\Users\34317\AppData\Local\Arm\Packs\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(8347): error: #5: cannot open source input file "stm32f10x_conf.h": No such file or directory #include "stm32f10x_conf.h" ..\libarary\src\stm32f10x_gpio.c: 0 warnings, 1 error compiling stm32f10x_i2c.c... C:\Users\34317\AppData\Local\Arm\Packs\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(8347): error: #5: cannot open source input file "stm32f10x_conf.h": No such file or directory #include "stm32f10x_conf.h" ..\libarary\src\stm32f10x_i2c.c: 0 warnings, 1 error compiling stm32f10x_iwdg.c... C:\Users\34317\AppData\Local\Arm\Packs\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(8347): error: #5: cannot open source input file "stm32f10x_conf.h": No such file or directory #include "stm32f10x_conf.h" ..\libarary\src\stm32f10x_iwdg.c: 0 warnings, 1 error compiling stm32f10x_pwr.c... C:\Users\34317\AppData\Local\Arm\Packs\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(8347): error: #5: cannot open source input file "stm32f10x_conf.h": No such file or directory #include "stm32f10x_conf.h" ..\libarary\src\stm32f10x_pwr.c: 0 warnings, 1 error compiling stm32f10x_rcc.c... C:\Users\34317\AppData\Local\Arm\Packs\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(8347): error: #5: cannot open source input file "stm32f10x_conf.h": No such file or directory #include "stm32f10x_conf.h" ..\libarary\src\stm32f10x_rcc.c: 0 warnings, 1 error compiling stm32f10x_rtc.c... C:\Users\34317\AppData\Local\Arm\Packs\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(8347): error: #5: cannot open source input file "stm32f10x_conf.h": No such file or directory #include "stm32f10x_conf.h" ..\libarary\src\stm32f10x_rtc.c: 0 warnings, 1 error compiling stm32f10x_sdio.c... C:\Users\34317\AppData\Local\Arm\Packs\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(8347): error: #5: cannot open source input file "stm32f10x_conf.h": No such file or directory #include "stm32f10x_conf.h" ..\libarary\src\stm32f10x_sdio.c: 0 warnings, 1 error compiling gpio.c... ..\libarary\inc\stm32f1xx.h(140): error: #35: #error directive: "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" ..\system\gpio\gpio.c: 0 warnings, 1 error compiling stm32f10x_spi.c... C:\Users\34317\AppData\Local\Arm\Packs\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(8347): error: #5: cannot open source input file "stm32f10x_conf.h": No such file or directory #include "stm32f10x_conf.h" ..\libarary\src\stm32f10x_spi.c: 0 warnings, 1 error compiling stm32f10x_tim.c... C:\Users\34317\AppData\Local\Arm\Packs\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(8347): error: #5: cannot open source input file "stm32f10x_conf.h": No such file or directory #include "stm32f10x_conf.h" ..\libarary\src\stm32f10x_tim.c: 0 warnings, 1 error compiling tim.c... ..\libarary\inc\stm32f1xx.h(140): error: #35: #error directive: "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" ..\system\timer\tim.c: 0 warnings, 1 error compiling stm32f10x_usart.c... C:\Users\34317\AppData\Local\Arm\Packs\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(8347): error: #5: cannot open source input file "stm32f10x_conf.h": No such file or directory #include "stm32f10x_conf.h" ..\libarary\src\stm32f10x_usart.c: 0 warnings, 1 error compiling usart.c... ..\libarary\inc\stm32f1xx.h(140): error: #35: #error directive: "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" ..\system\usart\usart.c: 0 warnings, 1 error compiling stm32f10x_wwdg.c... C:\Users\34317\AppData\Local\Arm\Packs\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(8347): error: #5: cannot open source input file "stm32f10x_conf.h": No such file or directory #include "stm32f10x_conf.h" ..\libarary\src\stm32f10x_wwdg.c: 0 warnings, 1 error compiling system_stm32f1xx.c... ..\libarary\inc\stm32f1xx.h(140): error: #35: #error directive: "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" ..\system\system_stm32f1xx.c: 0 warnings, 1 error compiling adc.c... ..\libarary\inc\stm32f1xx.h(140): error: #35: #error directive: "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" adc\adc.c: 0 warnings, 1 error compiling BC26.c... ..\libarary\inc\stm32f1xx.h(140): error: #35: #error directive: "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" bc26\BC26.c: 0 warnings, 1 error compiling ds18b20.c... ..\libarary\inc\stm32f1xx.h(140): error: #35: #error directive: "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" ds18b20\ds18b20.c: 0 warnings, 1 error compiling delay.c... C:\Users\34317\AppData\Local\Arm\Packs\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(8347): error: #5: cannot open source input file "stm32f10x_conf.h": No such file or directory #include "stm32f10x_conf.h" ..\system\delay\delay.c: 0 warnings, 1 error compiling lcd1602.c... ..\libarary\inc\stm32f1xx.h(140): error: #35: #error directive: "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" lcd1602\lcd1602.c: 0 warnings, 1 error compiling main.c... ..\libarary\inc\stm32f1xx.h(140): error: #35: #error directive: "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" main\main.c: 0 warnings, 1 error compiling stm32f1xx_hal_msp.c... ..\libarary\inc\stm32f1xx.h(140): error: #35: #error directive: "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" main\stm32f1xx_hal_msp.c: 0 warnings, 1 error compiling stm32f1xx_it.c... ..\libarary\inc\stm32f1xx.h(140): error: #35: #error directive: "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" main\stm32f1xx_it.c: 0 warnings, 1 error ".\Objects\BC26-Smoker.axf" - 51 Error(s), 0 Warning(s). Target not created. Build Time Elapsed: 00:00:02
09-07
评论 5
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值