make reorganized

This commit is contained in:
tkl 2016-08-16 14:28:08 +02:00
parent caa360625b
commit a8a4cb263d
16 changed files with 268 additions and 116 deletions

View File

@ -116,11 +116,12 @@
<configuration configurationName="Test Stm Debug">
<resource resourceType="PROJECT" workspacePath="/kosmos"/>
</configuration>
<configuration configurationName="Test msp Debug"/>
<configuration configurationName="ex_rx msp Debug"/>
<configuration configurationName="Debug">
<resource resourceType="PROJECT" workspacePath="/kosmos"/>
</configuration>
<configuration configurationName="Release"/>
<configuration configurationName="Test msp Debug"/>
<configuration configurationName="ex_rx msp Debug"/>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"/>
<storageModule moduleId="scannerConfiguration">
@ -145,6 +146,7 @@
<buildTargets>
<target name="all" path="software/source/test/firmware/kernel/list" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>all</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
@ -152,6 +154,7 @@
</target>
<target name="clean" path="software/source/test/firmware/kernel/list" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>clean</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
@ -159,7 +162,6 @@
</target>
<target name="distclean" path="software/source" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>distclean</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>false</useDefaultCommand>
@ -214,13 +216,6 @@
<runAllBuilders>true</runAllBuilders>
</target>
<target name="all" path="software/test/firmware/kernel/list" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildTarget>all</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
<runAllBuilders>true</runAllBuilders>
</target>
<target name="all" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>all</buildTarget>
@ -228,20 +223,44 @@
<useDefaultCommand>true</useDefaultCommand>
<runAllBuilders>true</runAllBuilders>
</target>
<target name="clean" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<target name="blinky debug test" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildArguments>TEST_APP=blinky BOARD=stm32f4-discovery DEBUG=y</buildArguments>
<buildTarget>test</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>false</useDefaultCommand>
<runAllBuilders>true</runAllBuilders>
</target>
<target name="blinky debug clean" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments> TEST_APP=blinky BOARD=stm32f4-discovery DEBUG=y</buildArguments>
<buildTarget>clean</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>false</useDefaultCommand>
<runAllBuilders>true</runAllBuilders>
</target>
<target name="blinky debug install" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments> TEST_APP=blinky BOARD=stm32f4-discovery DEBUG=y</buildArguments>
<buildTarget>install</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>false</useDefaultCommand>
<runAllBuilders>true</runAllBuilders>
</target>
<target name="distclean" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>distclean</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
<runAllBuilders>true</runAllBuilders>
</target>
<target name="install" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<target name="kosmos debug deploy" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>install</buildTarget>
<buildArguments>TEST_APP=blinky BOARD=stm32f4-discovery DEBUG=y</buildArguments>
<buildTarget>deploy</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
<useDefaultCommand>false</useDefaultCommand>
<runAllBuilders>true</runAllBuilders>
</target>
<target name="msp430-ccrf example_radio_rx all" path="software/source/test" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
@ -270,6 +289,7 @@
</target>
<target name="all" path="software/source/test/firmware/kernel/ringbuffer" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>all</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
@ -277,6 +297,7 @@
</target>
<target name="clean" path="software/source/test/firmware/kernel/ringbuffer" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>clean</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>

143
Makefile
View File

@ -1,97 +1,67 @@
###############################################################################
# ARM Section
CROSS_COMPILE ?= arm-none-eabi-
GEN_FLAGS := \
-mcpu=cortex-m4 \
-mthumb \
-mfloat-abi=hard \
-mfpu=fpv4-sp-d16 \
-Og \
-fmessage-length=0 \
-fsigned-char \
-ffunction-sections \
-fdata-sections \
-ffreestanding \
-fno-move-loop-invariants \
-Werror \
-Wunused \
-Wuninitialized \
-Wall \
-Wextra \
-Wmissing-declarations \
-Wconversion \
-Wpointer-arith \
-Wpadded \
-Wshadow \
-Wlogical-op \
-Waggregate-return \
-Wfloat-equal \
-g3
# -flto ## behind -ffreestanding
include config/make/rules.mk
OS_NAME := kosmos
C_FLAGS = \
-DDEBUG \
-DUSE_FULL_ASSERT \
-DTRACE \
-DOS_USE_TRACE_SEMIHOSTING_DEBUG \
-DSTM32F407xx \
-DUSE_HAL_DRIVER \
-DHSE_VALUE=8000000 \
$(addprefix -I, $(INCLUDES)) \
-std=gnu11 \
-Wmissing-prototypes \
-Wstrict-prototypes \
-Wbad-function-cast \
-Wno-bad-function-cast \
-Wno-conversion \
-Wno-sign-conversion \
-Wno-unused-parameter \
-Wno-sign-compare \
-Wno-missing-prototypes \
-Wno-missing-declarations
# version numbering deployed by ci deploy script - no necessary for local build
ifdef SW_KERNEL
VERSION := -$(SW_KERNEL).$(SW_MAJOR).$(SW_MINOR)
else
VERSION :=
endif
L_FLAGS := \
-T mem.ld \
-T libs.ld \
-T sections.ld \
-nostartfiles \
-Xlinker --gc-sections \
-L"config/linker" \
-Wl,-Map,"template.map" \
--specs=nano.specs \
MAIN_FILE = $(EXE_DIR)/lib$(OS_NAME)-$(ARCH)-$(BOARD)$(VERSION)$(DBG_EXT)$(LIB_EXT)
DEPLOY_PACKET = lib$(OS_NAME)-$(ARCH)-$(BOARD)$(VERSION)$(DBG_EXT).tar.xz
INCLUDES += \
/opt/arm-2011.09/arm-none-eabi/include \
/opt/arm-2011.09/lib/gcc/arm-none-eabi/4.6.1/include \
source/firmware
###############################################################################
# TOOLS Section
CC = $(CROSS_COMPILE)gcc
CXX = $(CROSS_COMPILE)g++
OBJCOPY = $(CROSS_COMPILE)objcopy
TEST_FILE = $(EXE_DIR)/$(TEST_APP)$(ELF_EXT)
BIN_FILE = $(EXE_DIR)/$(TEST_APP)$(BIN_EXT)
HEX_FILE = $(EXE_DIR)/$(TEST_APP)$(HEX_EXT)
SIZE_FILE = $(SIZE_DIR)/$(TEST_APP)$(SIZE_EXT)
MAP_FILE = $(MAP_DIR)/$(TEST_APP)$(MAP_EXT)
OBJ_DIR = release/object/debug
EXE_DIR = release/execute/debug
#include subfolders
include source/firmware/firmware.mk
include source/test/src/src.mk
ifdef TEST_APP
include source/test/test.mk
C_FLAGS += -DTEST_APP
endif
###############################################################################
C_SOURCES := $(foreach folder, $(SRC_DIR), $(wildcard $(folder)/*.c))
C_OBJECTS := $(C_SOURCES:%.c=$(OBJ_DIR)/%.o)
MAIN_FILE := $(EXE_DIR)/template.elf
BIN_FILE := $(EXE_DIR)/template.bin
OOCD_CFG_FILE := $(EXE_DIR)/openocd.cfg
C_DEPS := $(SOURCES:%.c=$(OBJ_DIR)/%.d)
all: $(MAIN_FILE)
deploy: all
@$(MKDIR) $(EXE_DIR)/include
$(ROOT_DIR)/source/scripts/board_interface.py -b "$(ROOT_DIR)/source/firmware/arch/$(CPU)/board/$(BOARD)/include/$(BOARD).h" -o "$(EXE_DIR)/include/board_devices.h"
$(ROOT_DIR)/source/scripts/stack_interface.py -i "$(ROOT_DIR)/source/firmware/arch/$(CPU)/include/$(CPU)_stack.h" -o "$(EXE_DIR)/include/stack.h"
cp $(ROOT_DIR)/source/firmware/kernel/interface/*.* $(EXE_DIR)/include/
tar cvJf $(DEPLOY_PACKET) -C $(EXE_DIR) .
$(MAIN_FILE): $(C_OBJECTS)
@$(MKDIR) $(EXE_DIR)
$(AR) $(AR_FLAGS) $(MAIN_FILE) $(C_OBJECTS)
all: $(C_OBJECTS)
@mkdir -p $(EXE_DIR)
$(CXX) $(GEN_FLAGS) $(L_FLAGS)-o "$(MAIN_FILE)" $(C_OBJECTS)
$(OBJCOPY) $(MAIN_FILE) -O binary $(BIN_FILE)
$(OBJ_DIR)/%.o: %.c
@mkdir -p $(OBJ_DIR)
@$(foreach folder, $(SRC_DIR), $(shell mkdir -p $(OBJ_DIR)/$(folder)))
$(CC) $(GEN_FLAGS) $(C_FLAGS) -MMD -MP -MF"$(subst .o,.d,$@)" -MT"$@" -c -o "$@" "$<"
$(call makedep,$<,$@,$(subst .o,.d,$@),$(GEN_FLAGS) $(C_FLAGS))
$(CC) $(GEN_FLAGS) $(C_FLAGS) -c -o "$@" "$<"
test: $(C_OBJECTS)
@$(MKDIR) $(EXE_DIR)
@$(MKDIR) $(MAP_DIR)
@$(MKDIR) $(SIZE_DIR)
$(CXX) $(GEN_FLAGS) $(L_FLAGS) -Wl,-Map,"$(MAP_FILE)" -o "$(TEST_FILE)" $(C_OBJECTS)
$(OBJCOPY) $(TEST_FILE) -O binary $(BIN_FILE)
$(OBJCOPY) $(TEST_FILE) -O ihex $(HEX_FILE)
$(NM) --size-sort --print-size $(TEST_FILE) > $(SIZE_FILE)
@echo
@$(SIZE) --format=berkeley -x $(TEST_FILE)
@echo
clean:
$(foreach folder, $(SRC_DIR), $(shell rm -f $(OBJ_DIR)/$(folder)/*.o))
@ -101,6 +71,17 @@ clean:
$(MAIN_FILE) \
$(BIN_FILE)
distclean:
-rm -rf $(ROOT_DIR)/release
install: all
echo "telnet_port 4444\ninit\nreset halt\nflash write_image erase $(BIN_FILE) 0x08000000 bin\nreset run\n shutdown\n" > $(OOCD_CFG_FILE)
openocd -f /usr/share/openocd/scripts/board/stm32f4discovery.cfg -f $(OOCD_CFG_FILE)
$(PRE_PROGRAM)
$(PROGRAM)
ifneq "$(MAKECMDGOALS)" "clean"
-include $(C_DEPS)
else
ifneq "$(MAKECMDGOALS)" "distclean"
-include $(C_DEPS)
endif
endif

44
config/make/rules.mk Normal file
View File

@ -0,0 +1,44 @@
.PHONY: clean distclean doc test
ROOT_DIR := $(shell pwd | sed "s/\/source//g")
include $(ROOT_DIR)/config/make/tools.mk
ifeq ($(BOARD), stm32f4-discovery)
include $(ROOT_DIR)/config/make/stm32f4xx.mk
endif
OS_LIB = kosmos-$(ARCH)-$(BOARD)$(DBG_EXT)
LIBS += $(OS_LIB)
INCLUDES += \
$(SRC_DIR)/firmware
ifeq ($(DEBUG),y)
DBG_DIR = debug
else
DBG_DIR = release
endif
OBJ_DIR := $(ROOT_DIR)/release/object/$(ARCH)/$(DBG_DIR)
EXE_DIR := $(ROOT_DIR)/release/execute/$(ARCH)/$(DBG_DIR)
MAP_DIR := $(ROOT_DIR)/release/map/$(ARCH)/$(DBG_DIR)
SIZE_DIR := $(ROOT_DIR)/release/size/$(ARCH)/$(DBG_DIR)
TEST_OBJ_DIR := $(ROOT_DIR)/test/object
TEST_EXE_DIR := $(ROOT_DIR)/test/execute/
ELF_EXT = .elf
BIN_EXT = .bin
HEX_EXT = .hex
LIB_EXT = .a
SIZE_EXT = .size
TEST_EXT =
MAP_EXT = .map
define makedep
$(CC) -MM \
-MF $3 \
-MP \
-MT $2 \
$4 \
$1
endef

87
config/make/stm32f4xx.mk Normal file
View File

@ -0,0 +1,87 @@
ARCH ?= arm
CPU ?= stm32f4xx
ifeq ($(CPU),stm32f4xx)
C_FLAGS += -DARCH_STM32F4XX
endif
ifeq ($(BOARD), stm32f4-discovery)
C_FLAGS += -DBOARD_STM32F4_DISCOVERY
endif
CROSS_COMPILE ?= arm-none-eabi-
INCLUDES += \
/opt/arm-2011.09/arm-none-eabi/include \
/opt/arm-2011.09/lib/gcc/arm-none-eabi/4.6.1/include
ifeq ($(DEBUG),y)
OPTIM = g
GEN_FLAGS += -g3
DBG_EXT = -dbg
else
OPTIM = s
DBG_EXT =
endif
GEN_FLAGS := \
-mcpu=cortex-m4 \
-mthumb \
-mfloat-abi=hard \
-mfpu=fpv4-sp-d16 \
-O$(OPTIM) \
-fmessage-length=0 \
-fsigned-char \
-ffunction-sections \
-fdata-sections \
-ffreestanding \
-fno-move-loop-invariants \
-Werror \
-Wunused \
-Wuninitialized \
-Wall \
-Wextra \
-Wmissing-declarations \
-Wconversion \
-Wpointer-arith \
-Wpadded \
-Wshadow \
-Wlogical-op \
-Waggregate-return \
-Wfloat-equal
C_FLAGS += \
-DDEBUG \
-DUSE_FULL_ASSERT \
-DTRACE \
-DOS_USE_TRACE_SEMIHOSTING_DEBUG \
-DSTM32F407xx \
-DUSE_HAL_DRIVER \
-DHSE_VALUE=8000000 \
$(addprefix -I, $(INCLUDES)) \
-std=gnu11 \
-Wmissing-prototypes \
-Wstrict-prototypes \
-Wbad-function-cast \
-Wno-bad-function-cast \
-Wno-conversion \
-Wno-sign-conversion \
-Wno-unused-parameter \
-Wno-sign-compare \
-Wno-missing-prototypes \
-Wno-missing-declarations
L_FLAGS := \
-T mem.ld \
-T libs.ld \
-T sections.ld \
-nostartfiles \
-Xlinker --gc-sections \
-L"config/linker" \
--specs=nano.specs
AS_FLAGS := -mapcs-32 -g
AR_FLAGS := rcs
OOCD_IMAGE=$(BIN_FILE)
OOCD_CFG_FILE=$(EXE_DIR)/openocd.cfg
PRE_PROGRAM = echo "telnet_port 4444\ninit\nreset halt\nflash write_image erase $(OOCD_IMAGE) 0x08000000 bin\nreset run\n shutdown\n" > $(OOCD_CFG_FILE)
PROGRAM = openocd -f /usr/share/openocd/scripts/board/stm32f4discovery.cfg -f $(OOCD_CFG_FILE)

13
config/make/tools.mk Normal file
View File

@ -0,0 +1,13 @@
CC = $(CROSS_COMPILE)gcc
CXX = $(CROSS_COMPILE)g++
AR = $(CROSS_COMPILE)ar
SIZE = $(CROSS_COMPILE)size
NM = $(CROSS_COMPILE)nm
RANLIB = $(CROSS_COMPILE)ranlib
OBJCOPY=$(CROSS_COMPILE)objcopy
SED = sed
RM = rm -f
MV = mv
CP = cp
MKDIR = mkdir -p
CPPCHECK = cppcheck

View File

@ -1 +1,3 @@
ifeq ($(CPU), stm32f4xx)
include source/firmware/arch/stm32f4xx/stm32f4xx.mk
endif

View File

@ -1,2 +1,4 @@
INCLUDES += source/firmware
include source/firmware/arch/arch.mk
include source/firmware/kernel/kernel.mk

View File

@ -8,8 +8,8 @@
#ifndef CTX_H_
#define CTX_H_
//#ifdef ARCH_STM32F4XX
#ifdef ARCH_STM32F4XX
#include "stm32f4xx_ctx.h"
//#endif
#endif
#endif /* CTX_H_ */

View File

@ -8,7 +8,8 @@
#ifndef IRQ_H_
#define IRQ_H_
//#ifdef ARCH_STM32F4XX
#ifdef ARCH_STM32F4XX
#include "stm32f4xx_irq.h"
//#endif
#endif
#endif /* IRQ_H_ */

View File

@ -8,8 +8,8 @@
#ifndef LOW_POWER_H_
#define LOW_POWER_H_
//#ifdef ARCH_STM32F4XX
#ifdef ARCH_STM32F4XX
#include "stm32f4xx_low_power.h"
//#endif
#endif
#endif /* LOW_POWER_H_ */

View File

@ -8,9 +8,9 @@
#ifndef SCHEDULE_H_
#define SCHEDULE_H_
//#ifdef ARCH_STM32F4XX
#ifdef ARCH_STM32F4XX
#include "stm32f4xx_ctx.h"
//#endif
#endif
#define schedule() arch_schedule()

View File

@ -8,8 +8,8 @@
#ifndef STACK_H_
#define STACK_H_
//#ifdef ARCH_STM32F4XX
#ifdef ARCH_STM32F4XX
#include "stm32f4xx_stack.h"
//#endif
#endif
#endif /* STACK_H_ */

View File

@ -0,0 +1 @@
SRC_DIR += source/test/blinky

View File

@ -1,2 +0,0 @@
SRC_DIR += source/test/src
INCLUDES += source/test/src/include

View File

@ -1,7 +1,9 @@
#ifeq ($(TEST_APP), shell)
#include source/test/shell/shell.mk
#endif
#ifeq ($(TEST_APP), pwm)
#include source/test/pwm/pwm.mk
#endif
include source/src/src.mk
ifeq ($(TEST_APP), shell)
include source/test/shell/shell.mk
endif
ifeq ($(TEST_APP), pwm)
include source/test/pwm/pwm.mk
endif
ifeq ($(TEST_APP), blinky)
include source/test/blinky/blinky.mk
endif