diff --git a/.cproject b/.cproject
index cb8ac51..7fd91ec 100755
--- a/.cproject
+++ b/.cproject
@@ -116,11 +116,12 @@
-
-
+
+
+
@@ -145,6 +146,7 @@
make
+
all
true
true
@@ -152,6 +154,7 @@
make
+
clean
true
true
@@ -159,7 +162,6 @@
make
-
distclean
true
false
@@ -214,13 +216,6 @@
true
- make
- all
- true
- true
- true
-
-
make
all
@@ -228,20 +223,44 @@
true
true
-
+
make
-
+ TEST_APP=blinky BOARD=stm32f4-discovery DEBUG=y
+ test
+ true
+ false
+ true
+
+
+ make
+ TEST_APP=blinky BOARD=stm32f4-discovery DEBUG=y
clean
true
+ false
+ true
+
+
+ make
+ TEST_APP=blinky BOARD=stm32f4-discovery DEBUG=y
+ install
+ true
+ false
+ true
+
+
+ make
+
+ distclean
+ true
true
true
-
+
make
-
- install
+ TEST_APP=blinky BOARD=stm32f4-discovery DEBUG=y
+ deploy
true
- true
+ false
true
@@ -270,6 +289,7 @@
make
+
all
true
true
@@ -277,6 +297,7 @@
make
+
clean
true
true
diff --git a/Makefile b/Makefile
index 663a1b2..2c31dd1 100644
--- a/Makefile
+++ b/Makefile
@@ -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
\ No newline at end of file
diff --git a/config/make/rules.mk b/config/make/rules.mk
new file mode 100644
index 0000000..21a08ca
--- /dev/null
+++ b/config/make/rules.mk
@@ -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
diff --git a/config/make/stm32f4xx.mk b/config/make/stm32f4xx.mk
new file mode 100644
index 0000000..db22f3f
--- /dev/null
+++ b/config/make/stm32f4xx.mk
@@ -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)
\ No newline at end of file
diff --git a/config/make/tools.mk b/config/make/tools.mk
new file mode 100644
index 0000000..6c58b2c
--- /dev/null
+++ b/config/make/tools.mk
@@ -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
\ No newline at end of file
diff --git a/source/firmware/arch/arch.mk b/source/firmware/arch/arch.mk
index bb1de28..2f25f9d 100755
--- a/source/firmware/arch/arch.mk
+++ b/source/firmware/arch/arch.mk
@@ -1 +1,3 @@
+ifeq ($(CPU), stm32f4xx)
include source/firmware/arch/stm32f4xx/stm32f4xx.mk
+endif
diff --git a/source/firmware/firmware.mk b/source/firmware/firmware.mk
index 87f80a4..7a7a78e 100755
--- a/source/firmware/firmware.mk
+++ b/source/firmware/firmware.mk
@@ -1,2 +1,4 @@
+INCLUDES += source/firmware
+
include source/firmware/arch/arch.mk
include source/firmware/kernel/kernel.mk
diff --git a/source/firmware/kernel/include/ctx.h b/source/firmware/kernel/include/ctx.h
index 9f490ec..4b7db1e 100755
--- a/source/firmware/kernel/include/ctx.h
+++ b/source/firmware/kernel/include/ctx.h
@@ -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_ */
diff --git a/source/firmware/kernel/include/irq.h b/source/firmware/kernel/include/irq.h
index 0ccfca3..7371658 100644
--- a/source/firmware/kernel/include/irq.h
+++ b/source/firmware/kernel/include/irq.h
@@ -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_ */
diff --git a/source/firmware/kernel/include/low_power.h b/source/firmware/kernel/include/low_power.h
index efd4751..6b67a06 100755
--- a/source/firmware/kernel/include/low_power.h
+++ b/source/firmware/kernel/include/low_power.h
@@ -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_ */
diff --git a/source/firmware/kernel/include/schedule.h b/source/firmware/kernel/include/schedule.h
index d9c5447..d7dff82 100755
--- a/source/firmware/kernel/include/schedule.h
+++ b/source/firmware/kernel/include/schedule.h
@@ -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()
diff --git a/source/firmware/kernel/include/stack.h b/source/firmware/kernel/include/stack.h
index 2128186..de9a52c 100644
--- a/source/firmware/kernel/include/stack.h
+++ b/source/firmware/kernel/include/stack.h
@@ -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_ */
diff --git a/source/test/blinky/blinky.mk b/source/test/blinky/blinky.mk
new file mode 100644
index 0000000..5a75724
--- /dev/null
+++ b/source/test/blinky/blinky.mk
@@ -0,0 +1 @@
+SRC_DIR += source/test/blinky
diff --git a/source/test/src/main.c b/source/test/blinky/main.c
similarity index 100%
rename from source/test/src/main.c
rename to source/test/blinky/main.c
diff --git a/source/test/src/src.mk b/source/test/src/src.mk
deleted file mode 100644
index 3d82591..0000000
--- a/source/test/src/src.mk
+++ /dev/null
@@ -1,2 +0,0 @@
-SRC_DIR += source/test/src
-INCLUDES += source/test/src/include
diff --git a/source/test/test.mk b/source/test/test.mk
index 2766794..3c53ed5 100644
--- a/source/test/test.mk
+++ b/source/test/test.mk
@@ -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