在IAR(EWARM)中移植STM32固件库

一、移植环境说明

(1)、win10系统

(2)、IAR(EWARM)7.7

(3)、STM32标准固件库3.5.0 http://www.st.com/content/st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32-standard-peripheral-libraries/stsw-stm32054.html

二、移植步骤

  (1)、首先建立一个C语言的main工程(或空工程),如下图所示:

  (2)、复制STM32固件库到工程目录下,并将固件库文件添加到工程中,添加完文件后的工程目录如下所示:

其中startup文件夹中的汇编文件要根据所使用的器件来选择,Flash<=32K为小容量,64K<=Flash<=128K为中容量,Flash>=256为大容量:

startup_stm32f10x_cl.s 互联型的器件,STM32F105xx,STM32F107xx
startup_stm32f10x_hd.s 大容量的STM32F101xx,STM32F102xx,STM32F103xx
startup_stm32f10x_hd_vl.s 大容量的STM32F100xx
startup_stm32f10x_ld.s 小容量的STM32F101xx,STM32F102xx,STM32F103xx
startup_stm32f10x_ld_vl.s 小容量的STM32F100xx
startup_stm32f10x_md.s 中容量的STM32F101xx,STM32F102xx,STM32F103xx
startup_stm32f10x_md_vl.s 中容量的STM32F100xx
startup_stm32f10x_xl.s FLASH在512K到1024K字节的STM32F101xx,STM32F102xx,STM32F103xx

 (3)、添加头文件的包含:

 

这个时候编译会报错:Fatal Error[Pe035]: #error directive: "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" E:\project\IARProject\BaseVersion\Libraries\CMSIS\DeviceSupport\stm32f10x.h 96

在stm32f10x.h中把#define STM32F10X_MD和#define USE_STDPERIPH_DRIVER两个宏打开再次编译。

这个时候报错:Error[Pe147]: declaration is incompatible with "__nounwind __interwork __softfp unsigned long __get_PSP(void)" (declared at line 58 of "D:\Program Files (x86)\IAR Systems\Embedded  E:\project\IARProject\BaseVersion\Libraries\CMSIS\CoreSupport\core_cm3.h 1084 等一系列错误,这是由于core_cm3.h头文件导致的,需要把固件库中的core_cm3.h去掉(删除或改名),用IAR自带的core_cm3.h文件。并在工程选项的库配置处选择使用CMSIS,如下图:

(4)、从标准模板工程中拷贝stm32f10x_conf.h到工程根目录下,并把根目录添加到头文件搜索路径中,再次编译即可通过;但是会出现警告信息:

Warning[25]: Label 'Reset_Handler' is defined pubweak in a section implicitly declared root E:\project\IARProject\BaseVersion\Libraries\CMSIS\DeviceSupport\startup\startup_stm32f10x_md.s 124 等一系列警告。

需要将startup_stm32f10x_md.s文件中的SECTION.text:CODE:REORDER(1)改为SECTION .text:CODE:REORDER:NOROOT(1)。

详情如下:

7.1版本之前,section默认是noroot,但现在是root。所以可以将SECTION .text:CODE:REORDER(1)改成SECTION .text:CODE:REORDER:NOROOT(1)或SECTION .text:CODE:REORDER:ROOT(1)。注意 NOROOT和 ROOT 的区别,NOROOT表示如果符号没有被关联的时候是被优化掉的,如果想不被优化则使用ROOT。

至此STM32固件库在IAR上的移植已经完成。

原文地址:https://www.cnblogs.com/softhal/p/5645489.html