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
|
# populates LIB_CSRC based on the library files used
|
||||||
-include $(DEPENDENCIES)
|
-include $(DEPENDENCIES)
|
||||||
|
|
||||||
# executables
|
# cross-compiler tools
|
||||||
PREFIX ?= arm-none-eabi
|
PREFIX ?= arm-none-eabi
|
||||||
|
# compile using gcc (requires gcc-arm-none-eabi)
|
||||||
CC := $(PREFIX)-gcc
|
CC := $(PREFIX)-gcc
|
||||||
CXX := $(PREFIX)-g++
|
# compile using clang (requires clang gcc-multilib)
|
||||||
LD := $(PREFIX)-gcc
|
CC := clang -target $(PREFIX)
|
||||||
|
# link (requires binutils-arm-none-eabi)
|
||||||
|
LD := $(PREFIX)-ld
|
||||||
|
# create archive (requires binutils-arm-none-eabi)
|
||||||
AR := $(PREFIX)-ar
|
AR := $(PREFIX)-ar
|
||||||
|
# compile assembly (requires binutils-arm-none-eabi)
|
||||||
AS := $(PREFIX)-as
|
AS := $(PREFIX)-as
|
||||||
OBJCOPY := $(PREFIX)-objcopy
|
OBJCOPY := $(PREFIX)-objcopy
|
||||||
OBJDUMP := $(PREFIX)-objdump
|
OBJDUMP := $(PREFIX)-objdump
|
||||||
|
# debugger (requires)
|
||||||
GDB := $(PREFIX)-gdb
|
GDB := $(PREFIX)-gdb
|
||||||
|
|
||||||
# opencm3 libraries
|
# opencm3 libraries
|
||||||
|
@ -82,31 +88,38 @@ endif
|
||||||
DEFS += -DSTM32F1 -D$(BOARD)
|
DEFS += -DSTM32F1 -D$(BOARD)
|
||||||
|
|
||||||
# C flags
|
# C flags
|
||||||
CFLAGS += -Os -g
|
CFLAGS += -Os -g -std=c99 -nostdlib
|
||||||
CFLAGS += -std=c99 -Wpedantic -Wall -Werror -Wundef -Wextra -Wshadow -Wredundant-decls -Wmissing-prototypes -Wstrict-prototypes -Wstrict-overflow=5
|
# TODO try to get rid of system libraries (and use -ffreestanding)
|
||||||
CFLAGS += -fno-common -ffunction-sections -fdata-sections
|
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 += -I. -I$(INCLUDE_DIR) $(patsubst %,-I%,$(LIB))
|
||||||
CFLAGS += $(DEFS)
|
CFLAGS += $(DEFS)
|
||||||
|
|
||||||
# linker flags
|
# linker flags
|
||||||
LDFLAGS += --static -nostartfiles
|
LDFLAGS += -static -nostartfiles -nostdlib
|
||||||
LDFLAGS += -L$(LIB_DIR)
|
# opencm3 libraries
|
||||||
LDFLAGS += -I. $(patsubst %,-I%,$(LIB))
|
LDFLAGS += --library-path $(LIB_DIR)
|
||||||
LDFLAGS += -T$(LDSCRIPT)
|
|
||||||
LDFLAGS += -Wl,-Map=$(*).map
|
|
||||||
LDFLAGS += -Wl,--gc-sections
|
|
||||||
ifeq ($(V),99)
|
|
||||||
LDFLAGS += -Wl,--print-gc-sections
|
|
||||||
endif
|
|
||||||
|
|
||||||
# used libraries
|
|
||||||
LIBNAME = opencm3_stm32f1
|
LIBNAME = opencm3_stm32f1
|
||||||
LDLIBS += -lm -l$(LIBNAME)
|
LDLIBS += --library $(LIBNAME)
|
||||||
LDLIBS += -Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group
|
# 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
|
# device specific flags
|
||||||
FP_FLAGS ?= -msoft-float
|
ARCH_FLAGS = -mthumb -mcpu=cortex-m3
|
||||||
ARCH_FLAGS = -mthumb -mcpu=cortex-m3 $(FP_FLAGS) -mfix-cortex-m3-ldrd
|
|
||||||
|
|
||||||
# SWD adapter used
|
# SWD adapter used
|
||||||
# supported are : st-link v2 (STLINKV2), black magic probe (BMP)
|
# 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)
|
%.elf: $(LDSCRIPT) $(LIB_DIR)/lib$(LIBNAME).a $(OBJ) $(LIB_OBJ)
|
||||||
$(info compiling $(@))
|
$(info compiling $(@))
|
||||||
$(Q)$(LD) $(LDFLAGS) $(ARCH_FLAGS) $(OBJ) $(LIB_OBJ) $(LDLIBS) -o $(@)
|
$(Q)$(LD) $(LDFLAGS) $(OBJ) $(LIB_OBJ) $(LDLIBS) -o $(@)
|
||||||
$(Q)size $(@)
|
$(Q)size $(@)
|
||||||
|
|
||||||
%.o: %.c $(CHDR) $(LIB_CHDR)
|
%.o: %.c $(CHDR) $(LIB_CHDR)
|
||||||
|
|
8
main.c
8
main.c
|
@ -25,7 +25,6 @@
|
||||||
#include <unistd.h> // standard streams
|
#include <unistd.h> // standard streams
|
||||||
#include <string.h> // string utilities
|
#include <string.h> // string utilities
|
||||||
#include <math.h> // mathematical utilities
|
#include <math.h> // mathematical utilities
|
||||||
#include <errno.h> // error number utilities
|
|
||||||
|
|
||||||
/* STM32 (including CM3) libraries */
|
/* STM32 (including CM3) libraries */
|
||||||
#include <libopencm3/stm32/rcc.h> // real-time control clock library
|
#include <libopencm3/stm32/rcc.h> // real-time control clock library
|
||||||
|
@ -40,7 +39,7 @@
|
||||||
#include "global.h" // board definitions
|
#include "global.h" // board definitions
|
||||||
#include "usart.h" // USART utilities
|
#include "usart.h" // USART utilities
|
||||||
#include "usb_cdcacm.h" // USB CDC ACM 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
|
/** @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;
|
return i;
|
||||||
}
|
}
|
||||||
errno = EIO;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,8 +145,8 @@ int main(void)
|
||||||
// setup USART and USB for user communication
|
// setup USART and USB for user communication
|
||||||
usart_setup(); // setup USART (for printing)
|
usart_setup(); // setup USART (for printing)
|
||||||
cdcacm_setup(); // setup USB CDC ACM (for printing)
|
cdcacm_setup(); // setup USB CDC ACM (for printing)
|
||||||
setbuf(stdout, NULL); // set standard out 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
|
//setbuf(stderr, NULL); // set standard error buffer to NULL to immediately print
|
||||||
|
|
||||||
// minimal setup ready
|
// minimal setup ready
|
||||||
printf("welcome to the STM32F1 CuVoodoo example code\n"); // print welcome message
|
printf("welcome to the STM32F1 CuVoodoo example code\n"); // print welcome message
|
||||||
|
|
Loading…
Reference in New Issue