1
0
mirror of https://github.com/rfivet/stm32bringup.git synced 2024-12-18 06:46:23 -05:00

Standard C output functions as library

This commit is contained in:
Renaud 2020-12-05 18:08:25 +08:00
parent fd13d29f0c
commit 3b3a113e05
2 changed files with 27 additions and 6 deletions

View File

@ -13,6 +13,7 @@ else
endif endif
BINPFX = @$(GCCDIR)/bin/arm-none-eabi- BINPFX = @$(GCCDIR)/bin/arm-none-eabi-
AR = $(BINPFX)ar
CC = $(BINPFX)gcc CC = $(BINPFX)gcc
LD = $(BINPFX)ld LD = $(BINPFX)ld
OBJCOPY = $(BINPFX)objcopy OBJCOPY = $(BINPFX)objcopy
@ -31,14 +32,18 @@ PROJECT = f030f4
#SRCS = startup.c board.c success.c #SRCS = startup.c board.c success.c
#SRCS = startup.c usart1tx.c hello.c #SRCS = startup.c usart1tx.c hello.c
#SRCS = startup.c uplow.1.c uptime.1.c #SRCS = startup.c uplow.1.c uptime.1.c
SRCS = startup.c uplow.2.c uptime.c printf.c putchar.c #SRCS = startup.c uplow.2.c uptime.c printf.c putchar.c
#SRCS = startup.c uplow.2.c uptime.c
SRCS = startup.c uplow.2.c hello.c
OBJS = $(SRCS:.c=.o) OBJS = $(SRCS:.c=.o)
LIBOBJS = printf.o putchar.o puts.o
CPU = -mthumb -mcpu=cortex-m0 CPU = -mthumb -mcpu=cortex-m0
CFLAGS = $(CPU) -g -Wall -Wextra -Os CFLAGS = $(CPU) -g -Wall -Wextra -Os
LD_SCRIPT = $(PROJECT).ld LD_SCRIPT = $(PROJECT).ld
LIBDIR = $(GCCDIR)/lib/gcc/arm-none-eabi/9.3.1/thumb/v6-m/nofp LIBDIR = $(GCCDIR)/lib/gcc/arm-none-eabi/9.3.1/thumb/v6-m/nofp
LIB_PATHS = -L$(LIBDIR) LIB_PATHS = -L. -L$(LIBDIR)
LIBS = -lgcc LIBSTEM = stm32
LIBS = -l$(LIBSTEM) -lgcc
### Build rules ### Build rules
@ -48,11 +53,11 @@ all: $(PROJECT).hex $(PROJECT).bin
clean: clean:
@echo CLEAN @echo CLEAN
@rm -f *.o *.elf *.map *.lst *.bin *.hex @rm -f *.o *.elf *.map *.lst *.bin *.hex *.a
$(PROJECT).elf: $(OBJS) $(PROJECT).elf: $(OBJS) lib$(LIBSTEM).a
@echo $@ @echo $@
$(LD) -T$(LD_SCRIPT) $(LIB_PATHS) -Map=$(PROJECT).map -cref -o $@ $^ $(LIBS) $(LD) -T$(LD_SCRIPT) $(LIB_PATHS) -Map=$(PROJECT).map -cref -o $@ $(OBJS) $(LIBS)
$(SIZE) $@ $(SIZE) $@
$(OBJDUMP) -hS $@ > $(PROJECT).lst $(OBJDUMP) -hS $@ > $(PROJECT).lst
@ -69,3 +74,6 @@ $(PROJECT).elf: $(OBJS)
%.hex: %.elf %.hex: %.elf
@echo $@ @echo $@
$(OBJCOPY) -O ihex $< $@ $(OBJCOPY) -O ihex $< $@
lib$(LIBSTEM).a: $(LIBOBJS)
$(AR) rc $@ $?

13
puts.c Normal file
View File

@ -0,0 +1,13 @@
/* puts.c -- write a string to stdout */
/* Copyright (c) 2020 Renaud Fivet */
#include <stdio.h>
#include "system.h" /* kputc(), kputs() */
int puts( const char *s) {
kputs( s) ;
kputc( '\n') ;
return 0 ;
}
/* end of puts.c */