首页 > 代码库 > 用arm-none-eabi-gcc编译STM32F10x

用arm-none-eabi-gcc编译STM32F10x

对于ubuntu 14.04(我的是14.10),官方仓库里就有适用的交叉编译器

apt-get install gcc-arm-none-eabi

对于较低的版本,可以使用https://launchpad.net/gcc-arm-embedded/提供的二进制压缩包,

以及https://launchpad.net/~terry.guo/+archive/ubuntu/gcc-arm-embedded提供的软件源

add-apt-repository ppa:terry.guo/gcc-arm-embedded
apt-get update
apt-get install gcc-arm-none-eabi

 

以下是项目的makefile,CMSIS中核心支持使用2.00版本,硬件支持使用3.5版本,外设驱动为3.5版

makefile使用find找到所有.c和.s文件,根据自动依赖进行编译。编译出来的文件,根据stm32_f103ze_gcc.ld生成.bin和.hex文件

TARGET=stm32########################################################################export CC             = arm-none-eabi-gccexport AS             = arm-none-eabi-asexport LD             = arm-none-eabi-ldexport OBJCOPY            = arm-none-eabi-objcopyTOP=$(shell pwd)INC_FLAGS=    -I $(TOP)/lib/CMSIS_200/CM3/CoreSupport/                     -I $(TOP)/lib/CMSIS_200/CM3/DeviceSupport/ST/STM32F10x             -I $(TOP)/lib/STM32F10x_StdPeriph_Driver/inc                -I $(TOP)/srcexport CFLAGS= -W -Wall -g -mcpu=cortex-m3 -mthumb -D STM32F10X_HD -D USE_STDPERIPH_DRIVER $(INC_FLAGS) ASFLAGS= -W -Wall -g -Wall -mcpu=cortex-m3 -mthumb########################################################################C_SRC=$(shell find ./ -name *.c)C_OBJ=$(C_SRC:%.c=%.o)C_DEP=$(C_SRC:%.c=%.cdep)ASM_SRC=$(shell find ./ -name *.s)ASM_OBJ=$(ASM_SRC:%.s=%.o)ASM_DEP=$(ASM_SRC:%.s=%.adep)########################################################################.PHONY: all cleanall:$(C_DEP) $(ASM_DEP) $(C_OBJ) $(ASM_OBJ)    $(LD) $(C_OBJ) $(ASM_OBJ) -T stm32_f103ze_gcc.ld -o $(TARGET).elf         $(OBJCOPY) $(TARGET).elf  $(TARGET).bin -Obinary     $(OBJCOPY) $(TARGET).elf  $(TARGET).hex -Oihex###################################%.cdep:%.c    $(CC) -MM $< > $@ $(CFLAGS)sinclude $(C_DEP)$(C_OBJ):%.o:%.c    $(CC) -c $< -o $@ $(CFLAGS)####################################%.adep:%.s    $(CC) -MM $< > $@ $(ASFLAGS)sinclude $(ASM_DEP)$(ASM_OBJ):%.o:%.s    $(AS) -c $@ -o $@ $(ASFLAGS)####################################    clean:    @for i in $(shell find ./ -name *.o);do if [ -e $${i} ];then rm $${i};fi;done    @for i in $(shell find ./ -name *.cdep);do if [ -e $${i} ];then rm $${i};fi;done    @for i in $(shell find ./ -name *.adep);do if [ -e $${i} ];then rm $${i};fi;done
stm32_f103ze_gcc.ld的内容
_estack = 0x20000400;MEMORY{    FLASH_ON_CHIP   (rx)    : ORIGIN = 0x08000000, LENGTH = 512K    SRAM_ON_CHIP    (rwx)   : ORIGIN = 0x20000000, LENGTH = 64K}SECTIONS{    .text : {        KEEP(*(.isr_vector))        *(.text*)        *(.rodata*)        _etext = .;    } > FLASH_ON_CHIP    _sidata = .;/*    .data : AT(ADDR(.text) + SIZEOF(.text)) {*/    .data : AT(_sidata) {        _sdata = .;        *(vtable)        *(.data*)        _edata = .;    } > SRAM_ON_CHIP    .bss : {        _sbss = .;        *(.bss*)        *(COMMON)        _ebss = .;    } > SRAM_ON_CHIP}

 

用arm-none-eabi-gcc编译STM32F10x