linux 搭建stm32的makefile 怎么写

linux 搭建stm32的makefile 怎么写,第1张

一 STM 32 GCC 安装

stm32 属于arm cortex-m系列thumb指令集,所以给arm用的arm-none-eabi就可以了,首先是下载

下载地址:

https://launchpad.net/gcc-arm-embedded/+download

下载其中的gcc-arm-none-eabi-version-linux.tar.bz2

解压到你知道的目录会产生

gcc-arm-none-eabi的文件夹

把该编译器添加到你的环境中:

sudo gedit ~/.bashrc

在最后一行添加:

export PATH=$PATH:/your_stm_gcc_dir/gcc-arm-none-eabi-4_8-2013q4/bin

因为我之前有添加过树莓派的编译器了,所以实际上是这样的:

export PATH=$PATH:/your_pi_gcc_dir/tools-master/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin/:/your_stm_gcc_dir/gcc-arm-none-eabi-4_8-2013q4/bin

两个编译器环境中间用冒号隔开

注销后测试:

arm-none-eabi-gcc -v

可以查看到该编译器的版本,就表示可以了.

二 工程环境的建立

新建个工程文件夹,及其目录

mkdir stm_project

cd stm_project

mkdir libs

mkdir src

mkdir inc

下载,安装官方库:

stm32的寄存器不像51 avr等单片机,那么少,自己写写库,背背寄存器就可以了,所以ST公司提供了他们官方的库,为了避免重复造轮子,就直接采用他们的库,库版本为STM32_USB-FS-Device_Lib_V4.0.0,这个库多了usb支持,下载的话到st官网搜索stm32f10x就有了.

下载链接:

stsw-stm32121.zip

解压,把解压好的文件夹复制到刚才新建的libs里面.

在工程根目录下新建Makefile.common文件,这个为通用makefile

# include Makefile

#This file is included in the general Makefile, the libs Makefile and the src Makefile

#Different optimize settings for library and source files can be realized by using arguments

#Compiler optimize settings:

# -O0 no optimize, reduce compilation time and make debugging produce the expected results (default).

# -O1 optimize, reduce code size and execution time, without much increase of compilation time.

# -O2 optimize, reduce code execution time compared to ‘O1’, increase of compilation time.

# -O3 optimize, turns on all optimizations, further increase of compilation time.

# -Os optimize for size, enables all ‘-O2’ optimizations that do not typically increase code size and other code size optimizations.

#Recommended optimize settings for release version: -O3

#Recommended optimize settings for debug version: -O0

#Valid parameters :

# OptLIB=0 -->optimize library files using the -O0 setting

# OptLIB=1 -->optimize library files using the -O1 setting

# OptLIB=2 -->optimize library files using the -O2 setting

# OptLIB=3 -->optimize library files using the -O3 setting

# OptLIB=s -->optimize library files using the -Os setting

# OptSRC=0 -->optimize source files using the -O0 setting

# OptSRC=1 -->optimize source files using the -O1 setting

# OptSRC=2 -->optimize source files using the -O2 setting

# OptSRC=3 -->optimize source files using the -O3 setting

# OptSRC=s -->optimize source files using the -Os setting

# all -->build all

# libs -->build libs only

# src -->build src only

# clean -->clean project

# tshow -->show optimize settings

#Example:

# make OptLIB=3 OptSRC=0 all tshow

TOP=$(shell readlink -f "$(dir $(lastword $(MAKEFILE_LIST)))")

PROGRAM=main

LIBDIR=$(TOP)/libs

#Adust the following line to the library in use

#=========add by embbnux 根据你的库不同,调整这个地方的库目录地址====================#

STMLIB=$(LIBDIR)/STM32_USB-FS-Device_Lib_V4.0.0/Libraries

#=========add by embbnux 根据你的stm32芯片型号容量不同,修改这个地方的TypeOfMCU=======#

#Adjust TypeOfMCU in use, see CMSIS file "stm32f10x.h"#STM32F103RBT (128KB FLASH, 20KB RAM) -->STM32F10X_MD#TypeOfMCU=STM32F10X_MD#STM32F103RET (512KB FLASH, 64KB RAM) -->STM32F10X_HD#STM32F103ZET (512KB FLASH, 64KB RAM) -->STM32F10X_HD

#============================================================================#

TypeOfMCU=STM32F10X_HD

#============================================================================#

TC=arm-none-eabi

CC=$(TC)-gcc

LD=$(TC)-ld -v

OBJCOPY=$(TC)-objcopy

AR=$(TC)-ar

GDB=$(TC)-gdb

INCLUDE=-I$(TOP)/inc

INCLUDE+=-I$(STMLIB)/CMSIS/Include

INCLUDE+=-I$(STMLIB)/CMSIS/Device/ST/STM32F10x/Include

INCLUDE+=-I$(STMLIB)/CMSIS/Device/ST/STM32F10x/Source/Templates

INCLUDE+=-I$(STMLIB)/STM32F10x_StdPeriph_Driver/inc

INCLUDE+=-I$(STMLIB)/STM32_USB-FS-Device_Driver/inc

COMMONFLAGS=-g -mcpu=cortex-m3 -mthumb

COMMONFLAGSlib=$(COMMONFLAGS)

#Commands for general Makefile and src Makefile

ifeq ($(OptSRC),0)

COMMONFLAGS+=-O0

InfoTextSrc=src (no optimize, -O0)

else ifeq ($(OptSRC),1)

COMMONFLAGS+=-O1

InfoTextSrc=src (optimize time+ size+, -O1)

else ifeq ($(OptSRC),2)

COMMONFLAGS+=-O2

InfoTextSrc=src (optimize time++ size+, -O2)

else ifeq ($(OptSRC),s)

COMMONFLAGS+=-Os

InfoTextSrc=src (optimize size++, -Os)

else

COMMONFLAGS+=-O3

InfoTextSrc=src (full optimize, -O3)

endif

CFLAGS+=$(COMMONFLAGS) -Wall -Werror $(INCLUDE)

CFLAGS+=-D $(TypeOfMCU)

CFLAGS+=-D VECT_TAB_FLASH

#Commands for libs Makefile

ifeq ($(OptLIB),0)

COMMONFLAGSlib+=-O0

InfoTextLib=libs (no optimize, -O0)

else ifeq ($(OptLIB),1)

COMMONFLAGSlib+=-O1

InfoTextLib=libs (optimize time+ size+, -O1)

else ifeq ($(OptLIB),2)

COMMONFLAGSlib+=-O2

InfoTextLib=libs (optimize time++ size+, -O2)

else ifeq ($(OptLIB),s)

COMMONFLAGSlib+=-Os

InfoTextLib=libs (optimize size++, -Os)

else

COMMONFLAGSlib+=-O3

InfoTextLib=libs (full optimize, -O3)

endif

CFLAGSlib+=$(COMMONFLAGSlib) -Wall -Werror $(INCLUDE)

CFLAGSlib+=-D $(TypeOfMCU)

CFLAGSlib+=-D VECT_TAB_FLASH

stm32单片机可以用Keil5、C语言或者汇编语言等语言进行编程。

在STM32F105和STM32F107互连型系列微控制器之前,意法半导体已经推出STM32基本型系列、增强型系列、USB基本型系列、互补型系列;新系列产品沿用增强型系列的72MHz处理频率。内存包括64KB到256KB闪存和20KB到64KB嵌入式SRAM。新系列采用LQFP64、LQFP100和LFBGA100三种封装,不同的封装保持引脚排列一致性,结合STM32平台的设计理念,开发人员通过选择产品可重新优化功能、存储器、性能和引脚数量,以最小的硬件变化来满足个性化的应用需求。意法半导体(STMicroelectronics)整个集团共有员工近50000名,拥有16个先进的研发机构、39个设计和应用中心、15主要制造厂,并在36个国家设有78个销售办事处。

RTC_clearflag():清除RTC标志,(参数可以多个,用“|”相加)。

rtc_flag_sec:秒中断标志。

rtc_clearflag(rtc_flag_sec) //清除RTC中秒中断标志

RTC_GetFlagStatus(): 检查指定RTC标志是否置位

while(RTC_GetFlagStatus(RTC_FLAG_SEC) == RESET) //当RTC秒中断标志没有被置位则一直循环,也就是说等待秒针跳变(这种处理方式比较不安全,一旦RTC不正常机器就死机了)。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/8478574.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-16
下一篇 2023-04-16

发表评论

登录后才能评论

评论列表(0条)

保存