IAR 下根据官方库建立 STM32的工程

 

目录

1. IARforSTM32工程v0.0版本。... 1

2. IARforSTM32工程v0.1版本。... 6

2.1今天v0.0版本出现了警告。... 6

2.2下载仿真。... 7

2.3工程介绍... 7

3. Icf文件和eval说明... 8

3.1 icf文件... 8

3.2.eval文件... 9

4. IAR的proprecessor中添加的宏定义STM32F10X_HD和USE_STDPERIPH_DRIVER. 9

                        资源吸取:网上大神、野火《【野火®】零死角玩转STM32—F103霸道》等,感谢!

一. IAR下官方3.5库STM32工程初建立,v0.0版本。

         昨天完成基于STM32的官方库3.5版本建成了IAR工程。其建工程的工程还挺顺利的,除了最后蹦出的10个警告,说声明不匹配。网上搜了下,原来是这样的:

    IAR6.3开始,IAR编译器本身已经集成了core_cm3.h,而STM32官方库提供的core_cm3.h是2009年的已经跟不上IAR编译器的更新了,所以要么将STM32官方库给的core_cm3.h删掉,要么将core_cm3.h重命名为core_cm3.h.old,另外在IAR工程的option中Project -> Options -> General Options -> Library Configuration -> Use CMSIS

具体解释,参见http://www.emcu.it/ARM_Compiler/IAR/IAR_tips_and_tricks.html

另外对于cortex M0或M4,也是如此。

    IAR7.3编译器本身已经集成了这些内核文件的函数声明intrinsics.h,如不按上面操作,IAR编译会报错:declaration is incompatible with "__nounwind __interwork __softfp unsigned long __get_PSP(void)" (declared at line 52 of "D:\Program Files\IAR  E:\project\ARMuDisk\projectperiph\STM32F10x_StdPeriph_Lib_V3.5.0\Libraries\CMSIS\CM3\CoreSupport\core_cm3.h 1084

等core_cm3.c中共10处报错,就是函数声明不匹配不协调。

 

    用其方法解决了问题,V0.0版本建立完毕,如下图所示:

 

1.1定义STM32F10X_HDUSE_STDPERIPH_DRIVER

         如下图,为啥要定义STM32F10X_HD和USE_STDPERIPH_DRIVER?因为一个是芯片类型,一个是头文件,你不定义,编译下,前者报错,后者警告。

        

         所以根据开发板芯片类型和外设使用情况再预编译上写宏定义,相当于#define。

 

         这是相对地址,之所以用$PROJ_DIR$\stm32f10x_flash.icf,是由于我的icf存在于工程文件所在路径。

2. IARforSTM32工程v0.1版本。

         2.1今天v0.0版本出现了警告。

 

         在使用IAR7.1及以上版本时出现诸多警告形如:Warning[25]: Label'Reset_Handler' is defined pubweak in a section implicitly declared root,则将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。

         以下为IAR手册的说明:

         Problem

After upgrading to EWARM 7.10.1 the Warning[25] is issued during assembly of afile that assembled without warning on earlier version of EWARM.

 

Background

The assembler (iasmarm) is (from EWARM 7.10.1) issuing Warning[25] for adeprecated assembler construction.

The deprecated assembler source construction looks like this:

 

      PUBWEAK NMI_Handler

      SECTION .text:CODE:REORDER(1)

  NMI_Handler

Solution

 

To avoid the warning, add ":NOROOT" to the "SECTION"statement:

 

      PUBWEAK NMI_Handler

      SECTION .text:CODE:REORDER:NOROOT(1)

  NMI_Handle

 

于是打开startup_stm32f10x_hd.s,将报警的所有SECTION .text:CODE:REORDER(1)改成                                         SECTION .text:CODE:REORDER:NOROOT(1)

 

         编译没有警告和错误,v0.1版本完成。

         flash、ram用的都是IAR编译器本身集成的。

        

         2.2下载仿真。

         今天用DAP仿真器和JLINK仿真器,这两个仿真器都进行了下载测试,完美。

至于jlink下载设置,默认就行。

 

         2.3工程介绍

         我将其分成两块,一为LIB库,包含CMSIS和STM32LIB;一为User。

 

3. Icf文件和eval说明

 

         3.1 icf文件

         这么多icf要用那个呢,这个官方库里面有说明

- stm32f10x_flash.icf : This file is the IAR Linker configuration file used to

                         place program code (readonly) in internal FLASH and data

                         (readwrite, Stack and Heap)in internal SRAM.

                         You can customize this file to your need.                   

                     

 - stm32f10x_flash_extsram.icf: This file is the IAR Linker configuration file

                                used to place program code (readonly) in internal

                                FLASH and data (readwrite, Stack and Heap)in

                                external SRAM. You can customize this file to your need. 

                                This file is used only with STM32 High-density devices.

 

 - stm32f10x_nor.icf:  This file is the IAR Linker configuration file used to

                       place program code (readonly) in external NOR FLASH and data

                       (readwrite, Stack and Heap)in internal SRAM.

                       You can customize this file to your need.

                       This file is used only with STM32 High-density devices.                                          

 

 - stm32f10x_ram.icf:  This file is the IAR Linker configuration file used to

                       place program code (readonly) and data (readwrite, Stack

                       and Heap)in internal SRAM.

                       You can customize this file to your need.                   

                             

         3.2.eval文件

        eval是啥?eval是官方的评估板(evaluate),就是STM32推出的官方开发板。

         官方库中的Utilities就是针对其官方开发板的,若是使用的是官方的开发板,那也得将Utilities添加到工程中,另外在preprocessor中预编译器中除了添加STM32F10X_HD

USE_STDPERIPH_DRIVER等还要添加对应的eval,

 

4. IAR的proprecessor中添加的宏定义STM32F10X_HD和USE_STDPERIPH_DRIVER

         在IAR的proprecessor中添加下面宏定义

STM32F10X_HD

USE_STDPERIPH_DRIVER

         添加STM32F10X_HD其原因是,在不动官方库的基础上添加对应芯片的型号,这在stm32f10x.h中限制必须宏定义一个型号否则报错——为啥要定义呢?因为这个头文件定义了所有f10x系列的芯片资源,你用不同的芯片是通过宏来获取符合其自身的资源的,相当于操作系统的功能裁剪一样也是通过宏截取的——长江水我只取一瓢饮。

         添加USE_STDPERIPH_DRIVER(第8296行)其原因是,在不动官方库的基础上使用官方外设时,这在stm32f10x.h中第8296行限制必须宏定义是否使用外设,不宏定义的话就不会包含外设头文件stm32f10x_conf.h,那么就说不用官方写的内置外设驱动,说明你很牛叉或者有团队很牛叉觉得官方外设库不好用自己写或者是根据项目要求而写的,否则一般都会用官方外设库的。