0

我开始使用 Linux,在我的项目gcc-testing中使用一些 stm32f4 库时遇到了一些麻烦。所需的所有 CMSIS 程序都在 STM32F4_Discovery_FW_V1.1.0 内部,项目安排如下:

~
|__
|  |
|   STM32F4XX
|    |
src   STM32F4_Discovery_FW_V1.1.0
  |
  ggc-testing
    |
    makefile
    main.c
    stm32f4xx_config.h
    stm32_flash.ld
    system_stm32f4xx.c

main.c 和 system_stm32f4xx.c 使用 STM32F4_Discovery_FW_V1.1.0/Libraries/CMSIS/ST/STM32F4xx/Include 中的 stm32f4xx.h 文件我从终端得到的错误是:

制作文件控制台错误

我的制作文件:

PROJ_NAME=main

STM_DIR=~/STM32F4XX/STM32F4-Discovery_FW_V1.1.0
STM_SRC = $(STM_DIR)/Libraries/STM32F4xx_StdPeriph_Driver/src

vpath %.c $(STM_SRC)

SRCS   = main.c
SRCS  += system_stm32f4xx.c
SRCS += $(STM_DIR)/Libraries/CMSIS/ST/STM32F4xx/Source/Templates/TrueSTUDIO/startup_stm32f4xx.s

INC_DIRS  = $(STM_DIR)/Utilities/STM32F4-Discovery
INC_DIRS += $(STM_DIR)/Libraries/CMSIS/Include
INC_DIRS += $(STM_DIR)/Libraries/CMSIS/ST/STM32F4xx/Include
INC_DIRS += $(STM_DIR)/Libraries/STM32F4xx_StdPeriph_Driver/inc
INC_DIRS += .

TOOLS_DIR = /opt/gcc-arm-embedded/gcc-arm-none-eabi-4_7-2013q1/bin

CC      = arm-none-eabi-gcc
OBJCOPY = arm-none-eabi-objcopy
GDB     = arm-none-eabi-gdb

INCLUDE = $(addprefix -I,$(INC_DIRS))
DEFS    = -DUSE_STDPERIPH_DRIVER

CFLAGS  = -ggdb
CFLAGS += -O0 
CFLAGS += -Wall -Wextra -Warray-bounds
CFLAGS += -mlittle-endian -mthumb -mcpu=cortex-m4 -mthumb-interwork
CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16

LFLAGS  = -Tstm32_flash.ld

.PHONY: $(PROJ_NAME)
$(PROJ_NAME): $(PROJ_NAME).elf

$(PROJ_NAME).elf: $(SRCS)
    $(CC) $(INCLUDE) $(DEFS) $(CFLAGS) $(LFLAGS) $^ -o $@ 
    $(OBJCOPY) -O ihex $(PROJ_NAME).elf   $(PROJ_NAME).hex
    $(OBJCOPY) -O binary $(PROJ_NAME).elf $(PROJ_NAME).bin

clean:
    rm -f *.o $(PROJ_NAME).elf $(PROJ_NAME).hex $(PROJ_NAME).bin

# Flash the STM32F4
flash: 
    st-flash write $(PROJ_NAME).bin 0x8000000

.PHONY: debug
debug:
# before you start gdb, you must start st-util
    $(GDB) $(PROJ_NAME).elf

希望enyne可以帮助解决这个问题。

4

1 回答 1

0

在 gnumake生成一个 cmd-line(例如gcc)之后,使用 a~将依赖于make执行一个 shell 并且 shell 扩展一个带有前导 unquoted 的 arg ~。根据您的行$(addprefix,尝试在-Iand之间添加一个空格,$(INC_DIRS)

但是,执行 shell 的开销可能是不可取的,而且额外的 exec 通常很容易避免;对于这种情况,替换~$(HOME)

示例Makefile

SUBDIR := some/incdir
TILDE_SUBDIR := ~/$(SUBDIR)

NOT_DELIM := $(addprefix -I,$(TILDE_SUBDIR))
DELIM_INC := $(addprefix -I ,$(TILDE_SUBDIR))
HOME_SUBDIR := $(HOME)/$(SUBDIR)

PHONY: all

all:
    @echo NOT_DELIM $(NOT_DELIM)
    @echo DELIM_INC $(DELIM_INC)
    @echo HOME_SUBDIR $(HOME_SUBDIR)

输出 :

NOT_DELIM -I~/some/incdir
DELIM_INC -I /home/user1/some/incdir
HOME_SUBDIR /home/user1/some/incdir
于 2020-08-02T14:00:44.580 回答