use clang to compile
This commit is contained in:
parent
0e09038871
commit
545b0be96e
55
Makefile
55
Makefile
|
@ -45,15 +45,21 @@ LIB_OBJ = $(patsubst %.c,%.o,$(LIB_CSRC))
|
|||
# populates LIB_CSRC based on the library files used
|
||||
-include $(DEPENDENCIES)
|
||||
|
||||
# executables
|
||||
# cross-compiler tools
|
||||
PREFIX ?= arm-none-eabi
|
||||
# compile using gcc (requires gcc-arm-none-eabi)
|
||||
CC := $(PREFIX)-gcc
|
||||
CXX := $(PREFIX)-g++
|
||||
LD := $(PREFIX)-gcc
|
||||
# compile using clang (requires clang gcc-multilib)
|
||||
CC := clang -target $(PREFIX)
|
||||
# link (requires binutils-arm-none-eabi)
|
||||
LD := $(PREFIX)-ld
|
||||
# create archive (requires binutils-arm-none-eabi)
|
||||
AR := $(PREFIX)-ar
|
||||
# compile assembly (requires binutils-arm-none-eabi)
|
||||
AS := $(PREFIX)-as
|
||||
OBJCOPY := $(PREFIX)-objcopy
|
||||
OBJDUMP := $(PREFIX)-objdump
|
||||
# debugger (requires)
|
||||
GDB := $(PREFIX)-gdb
|
||||
|
||||
# opencm3 libraries
|
||||
|
@ -82,31 +88,38 @@ endif
|
|||
DEFS += -DSTM32F1 -D$(BOARD)
|
||||
|
||||
# C flags
|
||||
CFLAGS += -Os -g
|
||||
CFLAGS += -std=c99 -Wpedantic -Wall -Werror -Wundef -Wextra -Wshadow -Wredundant-decls -Wmissing-prototypes -Wstrict-prototypes -Wstrict-overflow=5
|
||||
CFLAGS += -Os -g -std=c99 -nostdlib
|
||||
# TODO try to get rid of system libraries (and use -ffreestanding)
|
||||
CFLAGS += -fno-common -ffunction-sections -fdata-sections
|
||||
CFLAGS += -Wpedantic -Wall -Werror -Wundef -Wextra -Wshadow -Wredundant-decls -Wmissing-prototypes -Wstrict-prototypes -Wstrict-overflow=5
|
||||
CFLAGS += -I. -I$(INCLUDE_DIR) $(patsubst %,-I%,$(LIB))
|
||||
CFLAGS += $(DEFS)
|
||||
|
||||
# linker flags
|
||||
LDFLAGS += --static -nostartfiles
|
||||
LDFLAGS += -L$(LIB_DIR)
|
||||
LDFLAGS += -I. $(patsubst %,-I%,$(LIB))
|
||||
LDFLAGS += -T$(LDSCRIPT)
|
||||
LDFLAGS += -Wl,-Map=$(*).map
|
||||
LDFLAGS += -Wl,--gc-sections
|
||||
ifeq ($(V),99)
|
||||
LDFLAGS += -Wl,--print-gc-sections
|
||||
endif
|
||||
|
||||
# used libraries
|
||||
LDFLAGS += -static -nostartfiles -nostdlib
|
||||
# opencm3 libraries
|
||||
LDFLAGS += --library-path $(LIB_DIR)
|
||||
LIBNAME = opencm3_stm32f1
|
||||
LDLIBS += -lm -l$(LIBNAME)
|
||||
LDLIBS += -Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group
|
||||
LDLIBS += --library $(LIBNAME)
|
||||
# TODO use newlib (providing libc, libm, and libg/libnosys) and get rib of the libgcc
|
||||
# curiously newlib seems to require libgcc (In function `_vfprintf_r': undefined reference to `__aeabi_dcmplt')
|
||||
# also even with libcc aliases are missing (In function `cdcacm_data_rx_cb': undefined reference to `__aeabi_memset')
|
||||
#LDFLAGS += --library-path /usr/lib/arm-none-eabi/newlib/armv7-m/
|
||||
# provides libgcc
|
||||
# TODO retrieve path automatically (arm-none-eabi-gcc does it on its own)
|
||||
LDFLAGS += --library-path /usr/lib/gcc/arm-none-eabi/*/armv7-m/
|
||||
# provides libc, libm, libnosys
|
||||
# TODO retrieve path automatically (arm-none-eabi-gcc does it on its own)
|
||||
LDFLAGS += --library-path /usr/arm-none-eabi/lib/armv7-m/
|
||||
# own libraries
|
||||
LDFLAGS += --dynamic-linker . $(patsubst %,--dynamic-linker %,$(LIB))
|
||||
# libc and other system libraries
|
||||
LDLIBS += --library c --library gcc --library nosys --library m
|
||||
# linker script for micro-controller
|
||||
LDFLAGS += -T $(LDSCRIPT)
|
||||
|
||||
# device specific flags
|
||||
FP_FLAGS ?= -msoft-float
|
||||
ARCH_FLAGS = -mthumb -mcpu=cortex-m3 $(FP_FLAGS) -mfix-cortex-m3-ldrd
|
||||
ARCH_FLAGS = -mthumb -mcpu=cortex-m3
|
||||
|
||||
# SWD adapter used
|
||||
# supported are : st-link v2 (STLINKV2), black magic probe (BMP)
|
||||
|
@ -146,7 +159,7 @@ list: $(BINARY).list
|
|||
|
||||
%.elf: $(LDSCRIPT) $(LIB_DIR)/lib$(LIBNAME).a $(OBJ) $(LIB_OBJ)
|
||||
$(info compiling $(@))
|
||||
$(Q)$(LD) $(LDFLAGS) $(ARCH_FLAGS) $(OBJ) $(LIB_OBJ) $(LDLIBS) -o $(@)
|
||||
$(Q)$(LD) $(LDFLAGS) $(OBJ) $(LIB_OBJ) $(LDLIBS) -o $(@)
|
||||
$(Q)size $(@)
|
||||
|
||||
%.o: %.c $(CHDR) $(LIB_CHDR)
|
||||
|
|
8
main.c
8
main.c
|
@ -25,7 +25,6 @@
|
|||
#include <unistd.h> // standard streams
|
||||
#include <string.h> // string utilities
|
||||
#include <math.h> // mathematical utilities
|
||||
#include <errno.h> // error number utilities
|
||||
|
||||
/* STM32 (including CM3) libraries */
|
||||
#include <libopencm3/stm32/rcc.h> // real-time control clock library
|
||||
|
@ -40,7 +39,7 @@
|
|||
#include "global.h" // board definitions
|
||||
#include "usart.h" // USART utilities
|
||||
#include "usb_cdcacm.h" // USB CDC ACM utilities
|
||||
#include "usart_soft.h" // software USART utilities
|
||||
#include "uart_soft.h" // software USART utilities
|
||||
|
||||
/** @defgroup main_flags flag set in interrupts to be processed in main task
|
||||
* @{
|
||||
|
@ -74,7 +73,6 @@ int _write(int file, char *ptr, int len)
|
|||
}
|
||||
return i;
|
||||
}
|
||||
errno = EIO;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -147,8 +145,8 @@ int main(void)
|
|||
// setup USART and USB for user communication
|
||||
usart_setup(); // setup USART (for printing)
|
||||
cdcacm_setup(); // setup USB CDC ACM (for printing)
|
||||
setbuf(stdout, NULL); // set standard out buffer to NULL to immediately print
|
||||
setbuf(stderr, NULL); // set standard error buffer to NULL to immediately print
|
||||
//setbuf(stdout, NULL); // set standard out buffer to NULL to immediately print
|
||||
//setbuf(stderr, NULL); // set standard error buffer to NULL to immediately print
|
||||
|
||||
// minimal setup ready
|
||||
printf("welcome to the STM32F1 CuVoodoo example code\n"); // print welcome message
|
||||
|
|
Loading…
Reference in New Issue