summaryrefslogtreecommitdiff
path: root/controller/fw/Makefile
diff options
context:
space:
mode:
authorjaseg <git-bigdata-wsl-arch@jaseg.de>2020-03-11 13:57:22 +0100
committerjaseg <git-bigdata-wsl-arch@jaseg.de>2020-03-11 13:57:22 +0100
commit0af1a534e2930da77ebbab6481adcd17069581ef (patch)
tree6b8c1399fbf69d75c296f2b5060549e63553fa75 /controller/fw/Makefile
parent0cd07d397fb5a5e7710af66cb1e9e0b61705c94a (diff)
downloadmaster-thesis-0af1a534e2930da77ebbab6481adcd17069581ef.tar.gz
master-thesis-0af1a534e2930da77ebbab6481adcd17069581ef.tar.bz2
master-thesis-0af1a534e2930da77ebbab6481adcd17069581ef.zip
Start with integration of everything
Diffstat (limited to 'controller/fw/Makefile')
-rw-r--r--controller/fw/Makefile94
1 files changed, 58 insertions, 36 deletions
diff --git a/controller/fw/Makefile b/controller/fw/Makefile
index 85ab02f..df39fe4 100644
--- a/controller/fw/Makefile
+++ b/controller/fw/Makefile
@@ -1,12 +1,13 @@
-OPENCM3_DIR ?= libopencm3
-CMSIS_DIR ?= cmsis
+CUBE_DIR ?= STM32CubeF4
+CMSIS_DIR ?= cmsis
MSPDEBUG_DIR ?= mspdebug
LIBSODIUM_DIR ?= libsodium
-TINYAES_DIR ?= tinyaes
-MUSL_DIR ?= musl
+TINYAES_DIR ?= tinyaes
+MUSL_DIR ?= musl
-C_SOURCES := src/main.c src/mspdebug_wrapper.c src/spi_flash.c src/freq_meas.c src/dsss_demod.c
+C_SOURCES := src/main.c src/mspdebug_wrapper.c src/spi_flash.c src/freq_meas.c src/dsss_demod.c src/adc.c \
+ src/protocol.c
C_SOURCES += $(MSPDEBUG_DIR)/drivers/jtaglib.c
CMSIS_SOURCES += $(CMSIS_DIR)/CMSIS/DSP/Source/TransformFunctions/arm_rfft_fast_init_f32.c
@@ -23,6 +24,10 @@ MUSL_SOURCES += $(MUSL_DIR)/src/math/tanhf.c $(MUSL_DIR)/src/math/atanhf.c
MUSL_SOURCES += $(MUSL_DIR)/src/math/expm1f.c $(MUSL_DIR)/src/math/log1pf.c
MUSL_SOURCES += $(MUSL_DIR)/src/math/expf.c $(MUSL_DIR)/src/math/exp2f_data.c
MUSL_SOURCES += $(MUSL_DIR)/src/math/powf.c
+MUSL_SOURCES += $(MUSL_DIR)/src/math/fabsf.c
+MUSL_SOURCES += $(MUSL_DIR)/src/stdlib/abs.c
+MUSL_SOURCES += $(MUSL_DIR)/src/string/memset.c
+MUSL_SOURCES += $(MUSL_DIR)/src/string/memcpy.c
MUSL_SOURCES += $(MUSL_DIR)/src/math/__math_oflowf.c
MUSL_SOURCES += $(MUSL_DIR)/src/math/__math_uflowf.c
MUSL_SOURCES += $(MUSL_DIR)/src/math/__math_xflowf.c
@@ -36,7 +41,6 @@ CXX_SOURCES += src/ldpc_wrapper.cpp
BUILDDIR ?= build
BINARY := safetyreset.elf
LDSCRIPT := stm32f407.ld
-OPENCM3_LIB := opencm3_stm32f4
PREFIX ?= arm-none-eabi-
@@ -47,7 +51,7 @@ FMEAS_FFT_LEN ?= 256
FMEAS_FFT_WINDOW ?= gaussian
FMEAS_FFT_WINDOW_SIGMA ?= 16.0
# TODO: validate
-FMEAS_SAMPLING_RATE ?= 10.0
+FMEAS_SAMPLING_RATE ?= $(shell echo $(FMEAS_ADC_SAMPLING_RATE) / \($(FMEAS_FFT_LEN)/2\) | bc -l)
DSSS_GOLD_CODE_NBITS ?= 5
DSSS_DECIMATION ?= 10
@@ -70,6 +74,8 @@ CXX := $(PREFIX)g++
LD := $(PREFIX)gcc
AR := $(PREFIX)ar
AS := $(PREFIX)as
+SIZE := $(PREFIX)size
+NM := $(PREFIX)nm
OBJCOPY := $(PREFIX)objcopy
OBJDUMP := $(PREFIX)objdump
GDB := $(PREFIX)gdb
@@ -84,25 +90,31 @@ HOST_OBJDUMP ?= $(HOST_PREFIX)objdump
PYTHON3 ?= python3
-OPENCM3_DIR_ABS := $(abspath $(OPENCM3_DIR))
CMSIS_DIR_ABS := $(abspath $(CMSIS_DIR))
MSPDEBUG_DIR_ABS := $(abspath $(MSPDEBUG_DIR))
LIBSODIUM_DIR_ABS := $(abspath $(LIBSODIUM_DIR))
TINYAES_DIR_ABS := $(abspath $(TINYAES_DIR))
MUSL_DIR_ABS := $(abspath $(MUSL_DIR))
-COMMON_CFLAGS += -I$(OPENCM3_DIR_ABS)/include -Imspdebug/util -Imspdebug/drivers -Ilevmarq
+ARCH_FLAGS ?= -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16
+SYSTEM_FLAGS ?= -nostdlib -ffreestanding -nostartfiles
+
+COMMON_CFLAGS += -Imspdebug/util -Imspdebug/drivers -Ilevmarq
COMMON_CFLAGS += -I$(CMSIS_DIR_ABS)/CMSIS/DSP/Include -I$(CMSIS_DIR_ABS)/CMSIS/Core/Include
CFLAGS += -I$(abspath musl_include_shims)
COMMON_CFLAGS += -I$(BUILDDIR) -Isrc -Itinyaes
+CFLAGS += -I$(CUBE_DIR)/Drivers/CMSIS/Device/ST/STM32F4xx/Include
-COMMON_CFLAGS += -Os -std=gnu11 -g -DSTM32F4
-CFLAGS += -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16
+COMMON_CFLAGS += -Os -std=gnu11 -g -DSTM32F407xx -DSTM32F4
+CFLAGS += $(ARCH_FLAGS) $(SYSTEM_FLAGS)
#SIM_CFLAGS += -mthumb -mcpu=cortex-m4 -mfloat-abi=soft
-# Note: libopencm3 requires some standard libc definitions from stdint.h and stdbool.h, so we don't pass -nostdinc here.
-CFLAGS += -nostdlib -ffreestanding
CFLAGS += -fno-common -ffunction-sections -fdata-sections
-COMMON_CFLAGS += -DDSSS_GOLD_CODE_NBITS=$(DSSS_GOLD_CODE_NBITS) -DFMEAS_FFT_LEN=$(FMEAS_FFT_LEN) -DFMEAS_ADC_MAX=$(FMEAS_ADC_MAX)
+COMMON_CFLAGS += -DARM_DSP_CONFIG_TABLES -DARM_FFT_ALLOW_TABLES \
+ -DARM_TABLE_TWIDDLECOEF_F32_128 -DARM_TABLE_BITREVIDX_FLT_128 \
+ -DARM_TABLE_TWIDDLECOEF_F32_128 -DARM_TABLE_TWIDDLECOEF_RFFT_F32_256
+COMMON_CFLAGS += -DDSSS_GOLD_CODE_NBITS=$(DSSS_GOLD_CODE_NBITS)
+COMMON_CFLAGS += -DFMEAS_FFT_LEN=$(FMEAS_FFT_LEN)
+COMMON_CFLAGS += -DFMEAS_ADC_MAX=$(FMEAS_ADC_MAX)
COMMON_CFLAGS += -DFMEAS_ADC_SAMPLING_RATE=$(FMEAS_ADC_SAMPLING_RATE)
COMMON_CFLAGS += -DFMEAS_FFT_WINDOW_SIGMA=$(FMEAS_FFT_WINDOW_SIGMA)
COMMON_CFLAGS += -DDSSS_DECIMATION=$(DSSS_DECIMATION)
@@ -117,35 +129,43 @@ COMMON_CFLAGS += -DPRESIG_STORE_SIZE=$(PRESIG_STORE_SIZE)
CFLAGS += -Dhidden=
SIM_CFLAGS += -lm -DSIMULATION -fsanitize=address
-SIM_CFLAGS += -Wall -Wextra -Wpedantic -Wshadow -Wimplicit-function-declaration -Wundef
+SIM_CFLAGS += -Wall -Wextra -Wpedantic -Wshadow -Wimplicit-function-declaration -Wundef -Wno-unused-parameter
-INT_CFLAGS += -Wall -Wextra -Wpedantic -Wshadow -Wimplicit-function-declaration -Wundef
+INT_CFLAGS += -Wall -Wextra -Wpedantic -Wshadow -Wimplicit-function-declaration -Wundef -Wno-unused-parameter
INT_CFLAGS += -Wredundant-decls -Wmissing-prototypes -Wstrict-prototypes
CXXFLAGS += -Os -g
-CXXFLAGS += -nostdlib -ffreestanding
-CXXFLAGS += -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16
+CXXFLAGS += $(ARCH_FLAGS) $(SYSTEM_FLAGS)
CXXFLAGS += -fno-common -ffunction-sections -fdata-sections
CXXFLAGS += -Wall -Wextra -Wshadow -Wundef -Wredundant-decls
CXXFLAGS += -I.
-COMMON_LDFLAGS += -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -g
-LDFLAGS += --static -nostartfiles
+LDFLAGS += $(ARCH_FLAGS) $(SYSTEM_FLAGS)
LDFLAGS += -Wl,--cre
-#LDFLAGS += -Wl,--gc-sections
-LDFLAGS += -Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group
-LDFLAGS += -L$(OPENCM3_DIR_ABS)/lib -l$(OPENCM3_LIB) $(shell $(CC) -print-libgcc-file-name)
+LDFLAGS += --trace
+
+LIBS += -lgcc
+LDFLAGS += -Wl,--gc-sections -Wl,--trace-symbol=twiddleCoef_4096 -Wl,--trace-symbol=arm_cfft_sR_f32_len4096
-all: $(BUILDDIR)/$(BINARY)
+all: binsize
+
+.PHONY: binsize
+binsize: $(BUILDDIR)/$(BINARY)
+ @echo "▐▬▬▬▌ SyMbOL sIzE HiGhScORe LiSt ▐▬▬▬▌"
+ $(NM) --print-size --size-sort --radix=d $< | tail -n 20
+ @echo
+ @echo "===== Binary size ====="
+ $(SIZE) $<
src/dsss_demod.c: $(BUILDDIR)/generated/dsss_gold_code.h $(BUILDDIR)/generated/dsss_butter_filter.h
$(BUILDDIR)/generated/dsss_gold_code.h: $(BUILDDIR)/generated/gold_code_$(DSSS_GOLD_CODE_NBITS).h
ln -srf $< $@
-.PRECIOUS: $(BUILDDIR)/generated/gold_code_%.c
-$(BUILDDIR)/generated/gold_code_%.c $(BUILDDIR)/generated/gold_code_%.h: | $(BUILDDIR)/generated
- $(PYTHON3) tools/gold_code_header_gen.py -v dsss_gold_code_table -$(patsubst .%,%,$(suffix $@)) $* > $@
+.PRECIOUS: $(BUILDDIR)/generated/gold_code_%.c $(BUILDDIR)/generated/gold_code_%.h
+$(BUILDDIR)/generated/gold_code_%.c $(BUILDDIR)/generated/gold_code_%.h &: | $(BUILDDIR)/generated
+ $(PYTHON3) tools/gold_code_header_gen.py -v dsss_gold_code_table -c $* > $(BUILDDIR)/generated/gold_code_$*.c
+ $(PYTHON3) tools/gold_code_header_gen.py -v dsss_gold_code_table -h $* > $(BUILDDIR)/generated/gold_code_$*.h
.PRECIOUS: $(BUILDDIR)/generated/fmeas_fft_window.c
$(BUILDDIR)/generated/fmeas_fft_window.c: | $(BUILDDIR)/generated
@@ -172,7 +192,8 @@ $(BUILDDIR)/generated: ; mkdir -p $@
OBJS := $(addprefix $(BUILDDIR)/,$(C_SOURCES:.c=.o) $(CXX_SOURCES:.cpp=.o))
ALL_OBJS := $(OBJS)
-ALL_OBJS += $(OPENCM3_DIR)/lib/lib$(OPENCM3_LIB).a
+ALL_OBJS += $(BUILDDIR)/src/startup_stm32f407xx.o
+ALL_OBJS += $(BUILDDIR)/src/system_stm32f4xx.o
ALL_OBJS += $(BUILDDIR)/libsodium/src/libsodium/.libs/libsodium.a
ALL_OBJS += $(BUILDDIR)/tinyaes/aes.o
ALL_OBJS += $(BUILDDIR)/levmarq/levmarq.o
@@ -180,8 +201,9 @@ ALL_OBJS += $(BUILDDIR)/generated/gold_code_$(DSSS_GOLD_CODE_NBITS).o
ALL_OBJS += $(BUILDDIR)/generated/fmeas_fft_window.o
ALL_OBJS += $(BUILDDIR)/generated/dsss_cwt_wavelet.o
+.PRECIOUS: $(BUILDDIR)/$(BINARY)
$(BUILDDIR)/$(BINARY): $(ALL_OBJS)
- $(LD) -T$(LDSCRIPT) $(COMMON_LDFLAGS) $(LDFLAGS) -o $@ -Wl,-Map=$(BUILDDIR)/src/$*.map $^
+ $(LD) -T$(LDSCRIPT) $(LDFLAGS) -o $@ -Wl,-Map=$(BUILDDIR)/src/$*.map $^ $(LIBS)
tools: $(BUILDDIR)/tools/freq_meas_test
$(BUILDDIR)/tools/freq_meas_test: tools/freq_meas_test.c src/freq_meas.c levmarq/levmarq.c $(BUILDDIR)/generated/fmeas_fft_window.c $(CMSIS_SOURCES)
@@ -198,6 +220,10 @@ $(BUILDDIR)/tools/crypto_test: tools/crypto_test.c src/crypto.c tinyaes/aes.c $(
mkdir -p $(@D)
$(HOST_CC) $(COMMON_CFLAGS) $(SIM_CFLAGS) -lsodium -o $@ $^
+$(BUILDDIR)/src/%.o: src/%.s
+ mkdir -p $(@D)
+ $(CC) $(COMMON_CFLAGS) $(CFLAGS) $(INT_CFLAGS) -o $@ -c $<
+
$(BUILDDIR)/src/%.o: src/%.c
mkdir -p $(@D)
$(CC) $(COMMON_CFLAGS) $(CFLAGS) $(INT_CFLAGS) -o $@ -c $<
@@ -214,9 +240,6 @@ $(BUILDDIR)/%.o: %.c
mkdir -p $(@D)
$(CC) $(COMMON_CFLAGS) $(CFLAGS) $(EXT_CFLAGS) -o $@ -c $<
-$(OPENCM3_DIR)/lib/lib$(OPENCM3_LIB).a:
- $(MAKE) -C $(OPENCM3_DIR) -j $(shell nproc)
-
$(BUILDDIR)/libsodium/src/libsodium/.libs/libsodium.a:
mkdir -p $(BUILDDIR)/libsodium
cd $(BUILDDIR)/libsodium && CFLAGS="$(COMMON_CFLAGS) $(CFLAGS) -DDEV_MODE=1" $(LIBSODIUM_DIR_ABS)/configure --host=arm-none-eabi && $(MAKE) -j $(shell nproc)
@@ -225,9 +248,9 @@ $(BUILDDIR)/tinyaes/aes.o:
mkdir -p $(@D)
make -C $(@D) -f $(TINYAES_DIR_ABS)/Makefile VPATH=$(TINYAES_DIR_ABS) CFLAGS="$(COMMON_CFLAGS) $(CFLAGS) -c" CC=$(CC) LD=$(LD) AR=$(AR) aes.o
-$(BUILDDIR)/musl/lib/libc.a:
- mkdir -p $(BUILDDIR)/musl
- cd $(BUILDDIR)/musl && CFLAGS="$(SIM_CFLAGS) $(COMMON_CFLAGS)" CC=$(CC) LD=$(LD) AR=$(AR) $(MUSL_DIR_ABS)/configure && $(MAKE) TARGET=arm-linux-musleabihf GCC_CONFIG="-mcpu=cortex-m4 -mfloat-abi=soft" -j $(shell nproc)
+# $(BUILDDIR)/musl/lib/libc.a:
+# mkdir -p $(BUILDDIR)/musl
+# cd $(BUILDDIR)/musl && CFLAGS="$(SIM_CFLAGS) $(COMMON_CFLAGS)" CC=$(CC) LD=$(LD) AR=$(AR) $(MUSL_DIR_ABS)/configure && $(MAKE) TARGET=arm-linux-musleabihf GCC_CONFIG="-mcpu=cortex-m4 -mfloat-abi=soft" -j $(shell nproc)
build/ldpc_decoder_test.so: src/ldpc_decoder.c
gcc -fPIC -shared -Wall -Wextra -Wpedantic -std=gnu11 -O0 -g -o $@ $^
@@ -240,7 +263,6 @@ clean:
mrproper: clean
rm -rf build
- -$(MAKE) -C $(OPENCM3_DIR) clean
.PHONY: clean mrproper