对于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-gcc export AS = arm-none-eabi-as export LD = arm-none-eabi-ld export OBJCOPY = arm-none-eabi-objcopy TOP=$(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)/src export 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 clean all:$(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 }
向上查找makefile并执行的shell脚本,可以用在geany的编译快捷键中
cd $1;while [ ! -e ./Makefile ] ; do cd ..; path=`pwd` ; if [ "$path" = "/" ] ; then break; fi;done;if [ -e ./Makefile ] ;then make $2;fi
更多Ubuntu相关信息见Ubuntu 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=2
本文永久更新链接地址:http://www.linuxidc.com/Linux/2015-08/121322.htm