linux搭建stm32开发环境
下载stm32固件库
创建目录
libs目录放stm32固件库,src放用户源码,inc放用户头文件
# mkdir libs src inc
复制文件
将STM32F10x_StdPeriph_Lib_V3.5.0
复制到libs目录下
创建Makefile.common
在主目录下创建Makefile.common文件,这个是通用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
TOP=$(shell readlink -f "$(dir $(lastword $(MAKEFILE_LIST)))")
PROGRAM=main
LIBDIR=$(TOP)/libs
#Adust the following line to the library in use
STMLIB=$(LIBDIR)/STM32F10x_StdPeriph_Lib_V3.5.0/Libraries
#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/CM3/CoreSupport
INCLUDE+=-I$(STMLIB)/CMSIS/CM3/DeviceSupport/ST/STM32F10x
INCLUDE+=-I$(STMLIB)/STM32F10x_StdPeriph_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
编译固件库
首先编译固件库,将固件库编译成静态库,应用程序可以直接使用
startup.c
文件下载地址:http://download.csdn.net/download/zhangxuechao_/10266433
include ../../../../../Makefile.common
LIBS+=libstm32.a
CFLAGSlib+=-c
all: $(LIBS)
libstm32.a:
@echo -n "Building $@ ..."
cd $(STMLIB)/CMSIS/CM3/DeviceSupport/ST/STM32F10x/ && \
$(CC) $(CFLAGSlib) system_stm32f10x.c
cd $(STMLIB)/CMSIS/CM3/DeviceSupport/ST/STM32F10x/startup/arm && \
$(CC) $(CFLAGSlib) startup.c
cd $(STMLIB)/STM32F10x_StdPeriph_Driver/src && \
$(CC) $(CFLAGSlib) *.c \
-D"assert_param(expr)=((void)0)"
$(AR) cr $(LIBDIR)/$@ \
$(STMLIB)/CMSIS/CM3/DeviceSupport/ST/STM32F10x/system_stm32f10x.o \
$(STMLIB)/CMSIS/CM3/DeviceSupport/ST/STM32F10x/startup/arm/startup.o \
$(STMLIB)/STM32F10x_StdPeriph_Driver/src/*.o
@echo "done."
.PHONY: clean
clean:
rm -f $(STMLIB)/CMSIS/CM3/DeviceSupport/ST/STM32F10x/system_stm32f10x.o
rm -f $(STMLIB)/CMSIS/CM3/DeviceSupport/ST/STM32F10x/startup/arm/startup.o
rm -f $(STMLIB)/STM32F10x_StdPeriph_Driver/src/*.o
rm -f $(LIBDIR)/$(LIBS)
建立ld文件
建立linker.ld文件,根据芯片的内存以及flash容量
linker.ld
文件下载地址:http://download.csdn.net/download/zhangxuechao_/10266451
下面是文件需要修改的地方
MEMORY {
/*Adust LENGTH to RAMsize of target MCU:*/
/*STM32F103RBT --> 20K*/
/*RAM (RWX) : ORIGIN = 0x20000000 , LENGTH = 20K*/
/*STM32F103RET --> 64K*/
/*STM32F103ZET --> 64K*/
RAM (RWX) : ORIGIN = 0x20000000 , LENGTH = 64K
EXTSRAM (RWX) : ORIGIN = 0x68000000 , LENGTH = 0
/*Adust LENGTH to (FLASHsize - FeePROMsize) of target MCU:*/
/*STM32F103RBT --> 126K*/
/*FLASH (RX) : ORIGIN = 0x08000000 , LENGTH = 126K*/
/*STM32F103RET --> 508K*/
/*FLASH (RX) : ORIGIN = 0x08000000 , LENGTH = 508K*/
/*STM32F103ZET --> 508K*/
FLASH (RX) : ORIGIN = 0x08000000 , LENGTH = 508K
/*Adust ORIGIN to (0x08000000 + (FLASHsize-FeePROMsize)) of target MCU*/
/*and adust LENGTH to FeePROMsize allocated:*/
/*STM32F103RBT --> 0x08000000+126K, 2K*/
EEMUL (RWX) : ORIGIN = 0x08000000+126K, LENGTH = 2K
/*STM32F103RET --> 0x08000000+508K, 4K*/
/*EEMUL (RWX) : ORIGIN = 0x08000000+508K, LENGTH = 4K*/
}
编译用户文件
将用户应用程序也编译成静态库
include ../Makefile.common
LIBS+=app.a
CFLAGSlib+=-c
all: $(LIBS)
app.a:
@echo -n "Building $@ ..."
$(CC) $(CFLAGSlib) *.c
$(AR) cr $@ *.o
@echo "done."
.PHONY: clean
clean:
rm -f *.o
rm -f $(LIBS)
建立主Makefile
在主目录下,建立主Makefile文件
将固件库和用户应用程序编译成可执行文件
include Makefile.common
LDFLAGS=$(COMMONFLAGS) -fno-exceptions -ffunction-sections -fdata-sections -L$(LIBDIR) -nostartfiles -Wl,--gc-sections,-Tlinker.ld
LDLIBS+=-lm
LDLIBS+=-lstm32
all: libs src
$(CC) -o $(PROGRAM).elf $(LDFLAGS) \
-Wl,--whole-archive \
src/app.a \
-Wl,--no-whole-archive \
$(LDLIBS)
$(OBJCOPY) -O ihex $(PROGRAM).elf $(PROGRAM).hex
$(OBJCOPY) -O binary $(PROGRAM).elf $(PROGRAM).bin
arm-none-eabi-readelf -a $(PROGRAM).elf > $(PROGRAM).info_elf
arm-none-eabi-size -d -B -t $(PROGRAM).elf > $(PROGRAM).info_size
arm-none-eabi-objdump -S $(PROGRAM).elf > $(PROGRAM).info_code
arm-none-eabi-nm -t d -S --size-sort -s $(PROGRAM).elf > $(PROGRAM).info_symbol
.PHONY: libs src clean
libs:
$(MAKE) -C libs/STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/STM32F10x_StdPeriph_Driver/src
src:
$(MAKE) -C src
clean:
rm -f $(PROGRAM).elf $(PROGRAM).hex $(PROGRAM).bin $(PROGRAM).info_elf $(PROGRAM).info_size
rm -f $(PROGRAM).info_code
rm -f $(PROGRAM).info_symbol
源码路径
:https://github.com/zwx230741/linux_stm32.git
已经在STM32F103ZET6上测试成功
linux搭建stm32开发环境的更多相关文章
- VS Code 搭建stm32开发环境
MCU免费开发环境 一般芯片厂家会提供各种开发IDE方案,通常其中就包括其自家的集成IDE,如: 意法半导体 STM32CubeIDE NXP Codewarrior TI CCS 另外也可以用ecl ...
- Linux下STM32开发环境的搭建
目录 一.概述 1.目的 2.开发环境描述 3.Eclipse构建的STM32集成开发环境结构 4.GDB / GDB Server 调试模型 二.搭建步骤 三.详细的搭建过程 1.安装eclipse ...
- linux搭建C开发环境
目前决大多 数的Linux用户对Linux的了解还处于比较低级的层次,他们可能会几条命令.会配几种服务.会用rpm来安装软件.会操作KDE/Gnome界机等等,但是当他们遇到一些需要编译安装的软件时, ...
- <转>linux 下stm32开发环境安装
传送门: http://www.eefocus.com/marianna/blog/13-10/298454_7e04f.html http://blog.sina.com.cn/s/blog_643 ...
- linux搭建PHP开发环境
因为PHP是一门易于上手的开发语言,所以现在越来越多的初创公司选择PHP作为前期项目的主要开发语言. 工欲善其事,必先利其器! 现在我们就从最基本的环境搭建开始,PHP环境的搭建是非常简单的: 环境: ...
- Linux搭建JavaEE开发环境与Tomcat——(十)
服务器通过ip地址访问是不需要备案的,如果通过域名访问的话才需要备案. 1.安装Mysql 在CentOS7上安装MySQL时,出现了以下的提示: 原因是: CentOS7带有MariaDB而不是my ...
- 在Mac OS X中搭建STM32开发环境(3)
本文原创于http://www.cnblogs.com/humaoxiao,非法转载者请自重! 在上两篇文章中,我们先后编译和安装了ST-Link2和交叉编译工具,在大家确认安装成功以后 ...
- 在Mac OS X中搭建STM32开发环境(2)
本文原创于http://www.cnblogs.com/humaoxiao,非法转载者请自重! 在上一篇文章中,我们在OSX中编译了ST-Link2调试工具,并且简单的对其功能进行了测试 ...
- Linux——搭建PHP开发环境第四步:composer
原文链接:https://my.oschina.net/jiangbianwanghai/blog/473249 1.下载composer.phar [root#localhost opt]# cur ...
随机推荐
- jeecg数据库切换至mysql8.0方式
1.修改pom.xml mysql版本 <mysql.version>8.0.11</mysql.version> 2.修改dbconfig.properties文件 hi ...
- js---用对象来放置变量和方法
在写JS的时候,可以考虑使用对象来放置命名的变量,以及常用的方法. 简单示例: var func = { name:'张三', showName:function(name){ console.log ...
- 爬虫中Selenium和PhantomJS
Selenium Selenium是一个Web的自动化测试工具,最初是为网站自动化测试而开发的,类型像我们玩游戏用的按键精灵,可以按指定的命令自动操作,不同是Selenium 可以直接运行在浏览器上, ...
- mac node配置path
一.查看node安装路径 whitch node 二.打开配置文件 vi ./.bash_profile 三.添加一行PATH(按i进入insert才能编辑) export NODE_HOME=&qu ...
- Nexus上传npm包
1.创建npm仓库 私服仓库npm-hosted 代理仓库npm-proxy npm-group 创建成功 在工程的根目录下创建文件 .npmrc registry=http://xxx:8081/n ...
- 更换yum源为阿里云源
1.复制备份: cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup 2.下载: wget -O ...
- LwIP应用开发笔记之二:LwIP无操作系统UDP服务器
前面我们已经完成了LwIP协议栈基于逻辑的基本移植,在这一节我们将以RAW API来实现UDP服务器. 1.UDP协议简述 UDP协议全称是用户数据报协议,在网络中它与TCP协议一样用于处理数据包, ...
- Vue NGINX Apache 404 问题解决
location ^~/html/dist { #alias /home/server/webapps/vuejs-admin/; index index.html; try_files $uri $ ...
- traefik安装
注意这篇文档有个错误,需要改正一下: 1.nginx1-7.yaml nginx1-8.yaml traefik.yaml 这三个文件里面的80端口需要改成8080端口,否则报错,其他的文件不变. 2 ...
- ajax处理csrf的三种方式
方式一: $.post({ url: '/get_result/', data: { value0: $('#v1').val(), value1: $('#v2').val(), csrfmiddl ...