简体   繁体   English

裸机STM32

[英]Bare metal STM32

I have a project by use STM32F103C8T6.我有一个使用 STM32F103C8T6 的项目。 It has tree:它有树:

 __main.c
|__main.h
|__led.c
|__led.h
|__stm32f1xx_startup.c
|__Makefile

I'm using arm-none-eabi-gcc to compile this project.我正在使用 arm-none-eabi-gcc 来编译这个项目。 Makefile as below: Makefile如下:

CC = arm-none-eabi-gcc
MARCH = cortex-m3
CFLAGS = -c -mcpu=$(MARCH) -mthumb -std=gnu11 -Wall -O0
RM = rm -rf
OBJS = $(patsubst %.c,%.o,$(wildcard *.c))
INCS = $(wildcard *.h)
all: $(OBJS)
    $(CC) $(CFLAGS) $< -o $@
%.o: %.c %.h
    $(CC) $(CFLAGS) $< -o $@

.PHONY: clean
clean:
    $(RM) *.o all

When I run make command by Terminal of VS Code,it's not generate execute file and has a warning like this:当我通过 VS Code 的终端运行make命令时,它不会生成执行文件并有如下警告:

minh@Minh:~/Workspaces/Stm32/BeraMetal$ make
arm-none-eabi-gcc -c -mcpu=cortex-m3 -mthumb -std=gnu11 -Wall -O0 main.c -o main.o
arm-none-eabi-gcc -c -mcpu=cortex-m3 -mthumb -std=gnu11 -Wall -O0   -c -o stm32f1xx_startup.o stm32f1xx_startup.c
arm-none-eabi-gcc -c -mcpu=cortex-m3 -mthumb -std=gnu11 -Wall -O0 led.c -o led.o
arm-none-eabi-gcc -c -mcpu=cortex-m3 -mthumb -std=gnu11 -Wall -O0 main.o -o all
arm-none-eabi-gcc: warning: main.o: linker input file unused because linking not done

Please tell me how I can fix it?请告诉我如何修复它? Thank advance.先谢过。

You use the same flags for both compilation into object files, as when you attempt to link the object files together.编译成目标文件时使用相同的标志,就像尝试将目标文件链接在一起一样。

The problem is that the linking command will then use the -c flags, which is used to build object files.问题是链接命令将使用-c标志,该标志用于构建目标文件。

You need to separate compilation and linker flags.您需要将编译和链接器标志分开。 Or at least not specify -c in CFLAGS .或者至少不要在CFLAGS指定-c

how I can fix it?我该如何解决?

Don't pass -c to linking stage.不要将-c传递到链接阶段。 Also, you have to pass all objects to the linker.此外,您必须将所有对象传递给链接器。

CFLAGS = -mcpu=$(MARCH) -mthumb -std=gnu11 -Wall -O0
all: $(OBJS)
    $(CC) $(CFLAGS) $^ -o $@
%.o: %.c %.h
    $(CC) $(CFLAGS) -c $< -o $@

Consider using something newer than grandpa Make - CMake Scons Meson .考虑使用比爷爷 Make- CMake Scons Meson更新的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM