diff --git a/Rakefile b/Rakefile index 0000316..8b6b436 100644 --- a/Rakefile +++ b/Rakefile @@ -16,13 +16,19 @@ FIRMWARES = [BOOTLOADER, APPLICATION] # which development board is used # supported are: WeAct MiniF4 with STM32F401 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_DIR = "libopencm3" LIBOPENCM3_INC = LIBOPENCM3_DIR+"/include" -LIBOPENCM3_LIB = LIBOPENCM3_DIR+"/lib" -# STM32F4 library used for this project provided by libopencm3 -STM32F4_LIB = "opencm3_stm32f4" +LIBOPENCM3_LIBS = LIBOPENCM3_DIR+"/lib" +LIBOPENCM3_LIB = "opencm3_" + `./#{LIBOPENCM3_DIR}/scripts/genlink.py #{LIBOPENCM3_DIR}/ld/devices.data #{DEVICE} FAMILY` # source code used by the firmware SRC_DIRS = [".", "lib"] @@ -59,7 +65,8 @@ cflags += SRC_DIRS.collect {|srd_dir| "-I #{srd_dir}"} # include libopencm3 library cflags << "-I #{LIBOPENCM3_INC}" # 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 cflags = cflags.compact*' ' @@ -76,14 +83,17 @@ ldflags_linker = ["--gc-sections"] # show memory usage ldflags_linker << "--print-memory-usage" # add libopencm3 libraries -library_paths = [LIBOPENCM3_LIB] +library_paths = [LIBOPENCM3_LIBS] # project libraries -ldlibs = [STM32F4_LIB] +ldlibs = [LIBOPENCM3_LIB] # general libraries (gcc provides the ARM ABI) 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) -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" task :default => FIRMWARES @@ -134,7 +144,7 @@ file LIBOPENCM3_DIR+"/Makefile" do end 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}" end @@ -143,17 +153,17 @@ task :doc => ["Doxyfile", "README.md"] do |t| end 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]}" end 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]}" end 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}" end