summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl Palsson <karlp@tweak.net.au>2018-08-29 13:52:40 +0000
committerKarl Palsson <karlp@tweak.net.au>2018-08-29 13:52:40 +0000
commit1574ee1b01cd197a8817e3c31f8b20ef05c7984e (patch)
tree59f749d0de93f9db3a53176911c6ffb5f66c2072
downloadstm32f103c8-examples-1574ee1b01cd197a8817e3c31f8b20ef05c7984e.tar
stm32f103c8-examples-1574ee1b01cd197a8817e3c31f8b20ef05c7984e.tar.zst
stm32f103c8-examples-1574ee1b01cd197a8817e3c31f8b20ef05c7984e.zip
Initial clean template.
-rw-r--r--.gitmodules3
-rw-r--r--LICENSE5
-rw-r--r--README.md1
m---------libopencm30
-rw-r--r--my-project/Makefile19
-rw-r--r--my-project/my-project.c6
-rw-r--r--rules.mk166
7 files changed, 200 insertions, 0 deletions
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..6bccd68
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "libopencm3"]
+ path = libopencm3
+ url = https://github.com/libopencm3/libopencm3
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..94e1f5c
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,5 @@
+This template should be considered released into the public domain.
+Where not possible, please consider it available under your choice
+of the MIT, ISC, Apache2 or BSD-2-clause licenses.
+
+This only applies to the template code. libopencm3 itself has it's own license.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..d0acc36
--- /dev/null
+++ b/README.md
@@ -0,0 +1 @@
+Easy clone and go repository for a libopencm3 based project.
diff --git a/libopencm3 b/libopencm3
new file mode 160000
+Subproject e04f10e591e5d7386171c20dcc538475736211c
diff --git a/my-project/Makefile b/my-project/Makefile
new file mode 100644
index 0000000..2d009c3
--- /dev/null
+++ b/my-project/Makefile
@@ -0,0 +1,19 @@
+PROJECT = awesomesauce
+BUILD_DIR = bin
+
+SHARED_DIR = ../my-common-code
+CFILES = my-project.c
+CFILES += api.c
+
+# TODO - you will need to edit these two lines!
+DEVICE=stm32f407vgt6
+OOCD_FILE = board/stm32f4discovery.cfg
+
+# You shouldn't have to edit anything below here.
+VPATH += $(SHARED_DIR)
+INCLUDES += $(patsubst %,-I%, . $(SHARED_DIR))
+OPENCM3_DIR=../libopencm3
+
+include $(OPENCM3_DIR)/mk/genlink-config.mk
+include ../rules.mk
+include $(OPENCM3_DIR)/mk/genlink-rules.mk
diff --git a/my-project/my-project.c b/my-project/my-project.c
new file mode 100644
index 0000000..f550c66
--- /dev/null
+++ b/my-project/my-project.c
@@ -0,0 +1,6 @@
+#include "api.h"
+
+int main(void) {
+ /* add your own code */
+ return my_func(3);
+}
diff --git a/rules.mk b/rules.mk
new file mode 100644
index 0000000..28afc21
--- /dev/null
+++ b/rules.mk
@@ -0,0 +1,166 @@
+# This version of rules.mk expects the following to be defined before
+# inclusion..
+### REQUIRED ###
+# OPENCM3_DIR - duh
+# PROJECT - will be the basename of the output elf, eg usb-gadget0-stm32f4disco
+# CFILES - basenames only, eg main.c blah.c
+# DEVICE - the full device name, eg stm32f405ret6
+# _or_
+# LDSCRIPT - full path, eg ../../examples/stm32/f4/stm32f4-discovery/stm32f4-discovery.ld
+# OPENCM3_LIB - the basename, eg: opencm3_stm32f4
+# OPENCM3_DEFS - the target define eg: -DSTM32F4
+# ARCH_FLAGS - eg, -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16
+# (ie, the full set of cpu arch flags, _none_ are defined in this file)
+#
+### OPTIONAL ###
+# INCLUDES - fully formed -I paths, if you want extra, eg -I../shared
+# BUILD_DIR - defaults to bin, should set this if you are building multiarch
+# OPT - full -O flag, defaults to -Os
+# CSTD - defaults -std=c99
+# CXXSTD - no default.
+# OOCD_INTERFACE - eg stlink-v2
+# OOCD_TARGET - eg stm32f4x
+# both only used if you use the "make flash" target.
+# OOCD_FILE - eg my.openocd.cfg
+# This overrides interface/target above, and is used as just -f FILE
+### TODO/FIXME/notes ###
+# No support for stylecheck.
+# No support for BMP/texane/random flash methods, no plans either
+# No support for magically finding the library.
+# C++ hasn't been actually tested with this..... sorry bout that. ;)
+# Second expansion/secondary not set, add this if you need them.
+
+BUILD_DIR ?= bin
+OPT ?= -Os
+CSTD ?= -std=c99
+
+# Be silent per default, but 'make V=1' will show all compiler calls.
+# If you're insane, V=99 will print out all sorts of things.
+V?=0
+ifeq ($(V),0)
+Q := @
+NULL := 2>/dev/null
+endif
+
+# Tool paths.
+PREFIX ?= arm-none-eabi-
+CC = $(PREFIX)gcc
+LD = $(PREFIX)gcc
+OBJCOPY = $(PREFIX)objcopy
+OBJDUMP = $(PREFIX)objdump
+OOCD ?= openocd
+
+OPENCM3_INC = $(OPENCM3_DIR)/include
+
+# Inclusion of library header files
+INCLUDES += $(patsubst %,-I%, . $(OPENCM3_INC) )
+
+OBJS = $(CFILES:%.c=$(BUILD_DIR)/%.o)
+GENERATED_BINS = $(PROJECT).elf $(PROJECT).bin $(PROJECT).map $(PROJECT).list $(PROJECT).lss
+
+TGT_CPPFLAGS += -MD
+TGT_CPPFLAGS += -Wall -Wundef $(INCLUDES)
+TGT_CPPFLAGS += $(INCLUDES) $(OPENCM3_DEFS)
+
+TGT_CFLAGS += $(OPT) $(CSTD) -ggdb3
+TGT_CFLAGS += $(ARCH_FLAGS)
+TGT_CFLAGS += -fno-common
+TGT_CFLAGS += -ffunction-sections -fdata-sections
+TGT_CFLAGS += -Wextra -Wshadow -Wno-unused-variable -Wimplicit-function-declaration
+TGT_CFLAGS += -Wredundant-decls -Wstrict-prototypes -Wmissing-prototypes
+
+TGT_CXXFLAGS += $(OPT) $(CXXSTD) -ggdb3
+TGT_CXXFLAGS += $(ARCH_FLAGS)
+TGT_CXXFLAGS += -fno-common
+TGT_CXXFLAGS += -ffunction-sections -fdata-sections
+TGT_CXXFLAGS += -Wextra -Wshadow -Wredundant-decls -Weffc++
+
+TGT_LDFLAGS += -T$(LDSCRIPT) -L$(OPENCM3_DIR)/lib -nostartfiles
+TGT_LDFLAGS += $(ARCH_FLAGS)
+TGT_LDFLAGS += -specs=nano.specs
+TGT_LDFLAGS += -Wl,--gc-sections
+# OPTIONAL
+#TGT_LDFLAGS += -Wl,-Map=$(PROJECT).map
+ifeq ($(V),99)
+TGT_LDFLAGS += -Wl,--print-gc-sections
+endif
+
+# Linker script generator fills this in for us.
+ifeq (,$(DEVICE))
+LDLIBS += -l$(OPENCM3_LIB)
+endif
+# nosys is only in newer gcc-arm-embedded...
+#LDLIBS += -specs=nosys.specs
+LDLIBS += -Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group
+
+# Burn in legacy hell fortran modula pascal yacc idontevenwat
+.SUFFIXES:
+.SUFFIXES: .c .h .o .cxx .elf .bin .list .lss
+
+# Bad make, never *ever* try to get a file out of source control by yourself.
+%: %,v
+%: RCS/%,v
+%: RCS/%
+%: s.%
+%: SCCS/s.%
+
+all: $(PROJECT).elf $(PROJECT).bin
+flash: $(PROJECT).flash
+
+# error if not using linker script generator
+ifeq (,$(DEVICE))
+$(LDSCRIPT):
+ifeq (,$(wildcard $(LDSCRIPT)))
+ $(error Unable to find specified linker script: $(LDSCRIPT))
+endif
+else
+# if linker script generator was used, make sure it's cleaned.
+GENERATED_BINS += $(LDSCRIPT)
+endif
+
+# Need a special rule to have a bin dir
+$(BUILD_DIR)/%.o: %.c
+ @printf " CC\t$<\n"
+ @mkdir -p $(dir $@)
+ $(Q)$(CC) $(TGT_CFLAGS) $(CFLAGS) $(TGT_CPPFLAGS) $(CPPFLAGS) -o $@ -c $<
+
+$(BUILD_DIR)/%.o: %.cxx
+ @printf " CXX\t$<\n"
+ @mkdir -p $(dir $@)
+ $(Q)$(CC) $(TGT_CXXFLAGS) $(CXXFLAGS) $(TGT_CPPFLAGS) $(CPPFLAGS) -o $@ -c $<
+
+$(PROJECT).elf: $(OBJS) $(LDSCRIPT) $(LIBDEPS)
+ @printf " LD\t$@\n"
+ $(Q)$(LD) $(TGT_LDFLAGS) $(LDFLAGS) $(OBJS) $(LDLIBS) -o $@
+
+%.bin: %.elf
+ @printf " OBJCOPY\t$@\n"
+ $(Q)$(OBJCOPY) -O binary $< $@
+
+%.lss: %.elf
+ $(OBJDUMP) -h -S $< > $@
+
+%.list: %.elf
+ $(OBJDUMP) -S $< > $@
+
+%.flash: %.elf
+ @printf " FLASH\t$<\n"
+ifeq (,$(OOCD_FILE))
+ $(Q)(echo "halt; program $(realpath $(*).elf) verify reset" | nc -4 localhost 4444 2>/dev/null) || \
+ $(OOCD) -f interface/$(OOCD_INTERFACE).cfg \
+ -f target/$(OOCD_TARGET).cfg \
+ -c "program $(realpath $(*).elf) verify reset exit" \
+ $(NULL)
+else
+ $(Q)(echo "halt; program $(realpath $(*).elf) verify reset" | nc -4 localhost 4444 2>/dev/null) || \
+ $(Q)$(OOCD) -f $(OOCD_FILE) \
+ -c "program $(realpath $(*).elf) verify reset exit" \
+ $(NULL)
+endif
+
+clean:
+ rm -rf $(BUILD_DIR) $(GENERATED_BINS)
+
+.PHONY: all clean flash
+-include $(OBJS:.o=.d)
+