Rakefile: use derivated device properties
This commit is contained in:
parent
00ef5d9344
commit
a781fc5b3b
32
Rakefile
32
Rakefile
|
@ -16,13 +16,19 @@ FIRMWARES = [BOOTLOADER, APPLICATION]
|
||||||
# which development board is used
|
# which development board is used
|
||||||
# supported are: WeAct MiniF4 with STM32F401
|
# supported are: WeAct MiniF4 with STM32F401
|
||||||
BOARD = ENV["BOARD"] || "MINIF401"
|
BOARD = ENV["BOARD"] || "MINIF401"
|
||||||
|
# get MCU from board
|
||||||
|
DEVICE = case BOARD
|
||||||
|
when "MINIF401"
|
||||||
|
"stm32f401cc"
|
||||||
|
else
|
||||||
|
raise "unknown MCU for board #{BOARD}"
|
||||||
|
end
|
||||||
|
|
||||||
# libopencm3 definitions
|
# libopencm3 definitions
|
||||||
LIBOPENCM3_DIR = "libopencm3"
|
LIBOPENCM3_DIR = "libopencm3"
|
||||||
LIBOPENCM3_INC = LIBOPENCM3_DIR+"/include"
|
LIBOPENCM3_INC = LIBOPENCM3_DIR+"/include"
|
||||||
LIBOPENCM3_LIB = LIBOPENCM3_DIR+"/lib"
|
LIBOPENCM3_LIBS = LIBOPENCM3_DIR+"/lib"
|
||||||
# STM32F4 library used for this project provided by libopencm3
|
LIBOPENCM3_LIB = "opencm3_" + `./#{LIBOPENCM3_DIR}/scripts/genlink.py #{LIBOPENCM3_DIR}/ld/devices.data #{DEVICE} FAMILY`
|
||||||
STM32F4_LIB = "opencm3_stm32f4"
|
|
||||||
|
|
||||||
# source code used by the firmware
|
# source code used by the firmware
|
||||||
SRC_DIRS = [".", "lib"]
|
SRC_DIRS = [".", "lib"]
|
||||||
|
@ -59,7 +65,8 @@ cflags += SRC_DIRS.collect {|srd_dir| "-I #{srd_dir}"}
|
||||||
# include libopencm3 library
|
# include libopencm3 library
|
||||||
cflags << "-I #{LIBOPENCM3_INC}"
|
cflags << "-I #{LIBOPENCM3_INC}"
|
||||||
# add defines for micro-controller and board
|
# add defines for micro-controller and board
|
||||||
cflags << "-DSTM32F4 -D#{BOARD}"
|
cflags << "-D#{BOARD}"
|
||||||
|
cflags << `./#{LIBOPENCM3_DIR}/scripts/genlink.py #{LIBOPENCM3_DIR}/ld/devices.data #{DEVICE} CPPFLAGS`
|
||||||
# render cflags
|
# render cflags
|
||||||
cflags = cflags.compact*' '
|
cflags = cflags.compact*' '
|
||||||
|
|
||||||
|
@ -76,14 +83,17 @@ ldflags_linker = ["--gc-sections"]
|
||||||
# show memory usage
|
# show memory usage
|
||||||
ldflags_linker << "--print-memory-usage"
|
ldflags_linker << "--print-memory-usage"
|
||||||
# add libopencm3 libraries
|
# add libopencm3 libraries
|
||||||
library_paths = [LIBOPENCM3_LIB]
|
library_paths = [LIBOPENCM3_LIBS]
|
||||||
# project libraries
|
# project libraries
|
||||||
ldlibs = [STM32F4_LIB]
|
ldlibs = [LIBOPENCM3_LIB]
|
||||||
# general libraries (gcc provides the ARM ABI)
|
# general libraries (gcc provides the ARM ABI)
|
||||||
ldlibs_linker = ["m", "c", "nosys", "gcc"]
|
ldlibs_linker = ["m", "c", "nosys", "gcc"]
|
||||||
|
|
||||||
# target micro-controller information (ARM Cortex-M4 supports thumb and thumb2, but does not include a floating point unit)
|
# target micro-controller information (ARM Cortex-M4 supports thumb and thumb2, but does not include a floating point unit)
|
||||||
archflags = "-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16"
|
archflags = "-mthumb"
|
||||||
|
archflags += " -mcpu=" + `./#{LIBOPENCM3_DIR}/scripts/genlink.py #{LIBOPENCM3_DIR}/ld/devices.data #{DEVICE} CPU`
|
||||||
|
archflags += " -mfloat-abi=" + `./#{LIBOPENCM3_DIR}/scripts/genlink.py #{LIBOPENCM3_DIR}/ld/devices.data #{DEVICE} FPU`.split("-")[0]
|
||||||
|
archflags += " -mfpu=" + `./#{LIBOPENCM3_DIR}/scripts/genlink.py #{LIBOPENCM3_DIR}/ld/devices.data #{DEVICE} FPU`.split("-")[1..-1]*"-"
|
||||||
|
|
||||||
desc "compile firmwares"
|
desc "compile firmwares"
|
||||||
task :default => FIRMWARES
|
task :default => FIRMWARES
|
||||||
|
@ -134,7 +144,7 @@ file LIBOPENCM3_DIR+"/Makefile" do
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "compile libopencm3"
|
desc "compile libopencm3"
|
||||||
file "#{LIBOPENCM3_LIB}/lib#{STM32F4_LIB}.a" => LIBOPENCM3_DIR+"/Makefile" do
|
file "#{LIBOPENCM3_LIBS}/lib#{LIBOPENCM3_LIB}.a" => LIBOPENCM3_DIR+"/Makefile" do
|
||||||
sh "make --directory #{LIBOPENCM3_DIR}"
|
sh "make --directory #{LIBOPENCM3_DIR}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -143,17 +153,17 @@ task :doc => ["Doxyfile", "README.md"] do |t|
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "compile source into object"
|
desc "compile source into object"
|
||||||
rule '.o' => ['.c', proc{|f| File.file?(f.ext("h")) ? f.ext("h") : []}, proc{|f| dependencies(f).collect{|d| File.file?(d.ext("h")) ? d.ext("h") : []}}, "#{LIBOPENCM3_LIB}/lib#{STM32F4_LIB}.a"] do |t|
|
rule '.o' => ['.c', proc{|f| File.file?(f.ext("h")) ? f.ext("h") : []}, proc{|f| dependencies(f).collect{|d| File.file?(d.ext("h")) ? d.ext("h") : []}}, "#{LIBOPENCM3_LIBS}/lib#{LIBOPENCM3_LIB}.a"] do |t|
|
||||||
sh "#{CC} #{cflags} #{archflags} -o #{t.name} -c #{t.prerequisites[0]}"
|
sh "#{CC} #{cflags} #{archflags} -o #{t.name} -c #{t.prerequisites[0]}"
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "generate dependencies"
|
desc "generate dependencies"
|
||||||
rule '.d' => ['.c', "#{LIBOPENCM3_LIB}/lib#{STM32F4_LIB}.a"] do |t|
|
rule '.d' => ['.c', "#{LIBOPENCM3_LIBS}/lib#{LIBOPENCM3_LIB}.a"] do |t|
|
||||||
sh "#{CC} #{cflags} #{archflags} -MM -MF #{t.name} -c #{t.prerequisites[0]}"
|
sh "#{CC} #{cflags} #{archflags} -MM -MF #{t.name} -c #{t.prerequisites[0]}"
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "link binary"
|
desc "link binary"
|
||||||
rule '.elf' => ['.o', proc{|f| dependencies(f)}, '.ld', "#{LIBOPENCM3_LIB}/lib#{STM32F4_LIB}.a"] do |t|
|
rule '.elf' => ['.o', proc{|f| dependencies(f)}, '.ld', "#{LIBOPENCM3_LIBS}/lib#{LIBOPENCM3_LIB}.a"] do |t|
|
||||||
sh "#{LD} #{archflags} #{ldflags.join(' ')} #{t.prerequisites[0..-3].join(' ')} -T#{t.name.ext('ld')} #{ldflags_linker.collect{|flag| "-Wl,"+flag}.join(' ')} #{library_paths.collect{|path| "-L"+path}.join(' ')} #{ldlibs.collect{|lib| "-l"+lib}.join(' ')} -Wl,--start-group #{ldlibs_linker.collect{|lib| "-l"+lib}.join(' ')} -Wl,--end-group --output #{t.name}"
|
sh "#{LD} #{archflags} #{ldflags.join(' ')} #{t.prerequisites[0..-3].join(' ')} -T#{t.name.ext('ld')} #{ldflags_linker.collect{|flag| "-Wl,"+flag}.join(' ')} #{library_paths.collect{|path| "-L"+path}.join(' ')} #{ldlibs.collect{|lib| "-l"+lib}.join(' ')} -Wl,--start-group #{ldlibs_linker.collect{|lib| "-l"+lib}.join(' ')} -Wl,--end-group --output #{t.name}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue