diff --git a/Rakefile b/Rakefile index cbc0c6f..0000316 100644 --- a/Rakefile +++ b/Rakefile @@ -1,8 +1,8 @@ # encoding: utf-8 # ruby: 2.4.2 =begin -Rakefile to manage compile CuVoodoo STM32F1 firmware. -the firmware is for development board based around a STM32F1xx micro-controller. +Rakefile to manage compiling CuVoodoo STM32F4 firmware. +the firmware is for development boards based around a STM32F4xx micro-controller. the firmware uses the libopencm3 library providing support for this micro-controller. =end require 'rake' @@ -14,15 +14,15 @@ APPLICATION = "application" FIRMWARES = [BOOTLOADER, APPLICATION] # which development board is used -# supported are: SYSTEM_BOARD, MAPLE_MINI, BLUE_PILL, BLACK_PILL, CORE_BOARD, STLINKV2, BLASTER, BUSVOODOO -BOARD = ENV["BOARD"] || "BLUE_PILL" +# supported are: WeAct MiniF4 with STM32F401 +BOARD = ENV["BOARD"] || "MINIF401" # libopencm3 definitions LIBOPENCM3_DIR = "libopencm3" LIBOPENCM3_INC = LIBOPENCM3_DIR+"/include" LIBOPENCM3_LIB = LIBOPENCM3_DIR+"/lib" -# STM32F1 library used for this project provided by libopencm3 -STM32F1_LIB = "opencm3_stm32f1" +# STM32F4 library used for this project provided by libopencm3 +STM32F4_LIB = "opencm3_stm32f4" # source code used by the firmware SRC_DIRS = [".", "lib"] @@ -59,7 +59,7 @@ cflags += SRC_DIRS.collect {|srd_dir| "-I #{srd_dir}"} # include libopencm3 library cflags << "-I #{LIBOPENCM3_INC}" # add defines for micro-controller and board -cflags << "-DSTM32F1 -D#{BOARD}" +cflags << "-DSTM32F4 -D#{BOARD}" # render cflags cflags = cflags.compact*' ' @@ -78,12 +78,12 @@ ldflags_linker << "--print-memory-usage" # add libopencm3 libraries library_paths = [LIBOPENCM3_LIB] # project libraries -ldlibs = [STM32F1_LIB] +ldlibs = [STM32F4_LIB] # general libraries (gcc provides the ARM ABI) ldlibs_linker = ["m", "c", "nosys", "gcc"] -# target micro-controller information (ARM Cortex-M3 supports thumb and thumb2, but does not include a floating point unit) -archflags = "-mthumb -mcpu=cortex-m3 -msoft-float" +# 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" desc "compile firmwares" task :default => FIRMWARES @@ -134,7 +134,7 @@ file LIBOPENCM3_DIR+"/Makefile" do end desc "compile libopencm3" -file "#{LIBOPENCM3_LIB}/lib#{STM32F1_LIB}.a" => LIBOPENCM3_DIR+"/Makefile" do +file "#{LIBOPENCM3_LIB}/lib#{STM32F4_LIB}.a" => LIBOPENCM3_DIR+"/Makefile" do sh "make --directory #{LIBOPENCM3_DIR}" end @@ -143,17 +143,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#{STM32F1_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_LIB}/lib#{STM32F4_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#{STM32F1_LIB}.a"] do |t| +rule '.d' => ['.c', "#{LIBOPENCM3_LIB}/lib#{STM32F4_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#{STM32F1_LIB}.a"] do |t| +rule '.elf' => ['.o', proc{|f| dependencies(f)}, '.ld', "#{LIBOPENCM3_LIB}/lib#{STM32F4_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 @@ -190,22 +190,20 @@ OOCD = ENV["OOCD"] || "openocd" # openOCD adapted name OOCD_INTERFACE = ENV["OOCD_INTERFACE"] || (SWD_ADAPTER=="STLINKV2" ? "stlink" : "") # openOCD target for the micro-controller -OOCD_TARGET = "stm32f1x" +OOCD_TARGET = "stm32f4x" # Black Magic Probe port BMP_PORT = ENV["BMP_PORT"] || "/dev/ttyACM0" -# set CPUTAPID (0x1ba01477 for STM32, 0x2ba01477 for CKS32/APM32) -CPUTAPID = ENV["CPUTAPID"] || "0x1ba01477" desc "flash application using USB DFU" task :flash => APPLICATION+".bin" do |t| sh "dfu-util --device 1209:4356 --download #{t.source}" end -desc "remove STM32F1 protection using SWD" +desc "remove STM32F4 protection using SWD" task :remove_protection do case SWD_ADAPTER when "STLINKV2" - sh "#{OOCD} --file interface/#{OOCD_INTERFACE}.cfg --command 'transport select hla_swd' --command 'set CPUTAPID #{CPUTAPID}' --file target/#{OOCD_TARGET}.cfg --command 'init' --command 'halt' --command 'reset init' --command 'stm32f1x unlock 0' --command 'reset init' --command 'flash protect 0 0 last off' --command 'reset init' --command 'stm32f1x options_write 0 SWWDG NORSTSTNDBY NORSTSTOP' --command 'reset init' --command 'stm32f1x mass_erase 0' --command 'shutdown'" + sh "#{OOCD} --file interface/#{OOCD_INTERFACE}.cfg --command 'transport select hla_swd' --file target/#{OOCD_TARGET}.cfg --command 'init' --command 'halt' --command 'reset init' --command 'stm32f4x unlock 0' --command 'reset init' --command 'flash protect 0 0 last off' --command 'reset init' --command 'stm32f4x options_write 0 SWWDG NORSTSTNDBY NORSTSTOP' --command 'reset init' --command 'stm32f4x mass_erase 0' --command 'shutdown'" when "BMP" sh "#{GDB} --eval-command='target extended-remote #{BMP_PORT}' --eval-command='set confirm off' --eval-command='monitor swdp_scan' --eval-command='attach 1' --eval-command='monitor option erase' --eval-command='monitor erase_mass' --eval-command='kill' --eval-command='quit'" end @@ -215,7 +213,7 @@ desc "flash bootloader using SWD" task :flash_bootloader => BOOTLOADER+".hex" do |t| case SWD_ADAPTER when "STLINKV2" - sh "#{OOCD} --file interface/#{OOCD_INTERFACE}.cfg --command 'transport select hla_swd' --command 'set CPUTAPID #{CPUTAPID}' --file target/#{OOCD_TARGET}.cfg --command 'init' --command 'halt' --command 'reset init' --command 'flash erase_sector 0 0 last' --command 'flash write_image erase #{t.source}' --command 'reset' --command 'shutdown'" + sh "#{OOCD} --file interface/#{OOCD_INTERFACE}.cfg --command 'transport select hla_swd' --file target/#{OOCD_TARGET}.cfg --command 'init' --command 'halt' --command 'reset init' --command 'flash erase_sector 0 0 last' --command 'flash write_image erase #{t.source}' --command 'reset' --command 'shutdown'" when "BMP" sh "#{GDB} --eval-command='target extended-remote #{BMP_PORT}' --eval-command='set confirm off' --eval-command='monitor swdp_scan' --eval-command='attach 1' --eval-command='monitor erase_mass' --eval-command='load' --eval-command='kill' --eval-command='quit' #{t.source}" end @@ -225,7 +223,7 @@ desc "flash application using SWD" task :flash_application => APPLICATION+".hex" do |t| case SWD_ADAPTER when "STLINKV2" - sh "#{OOCD} --file interface/#{OOCD_INTERFACE}.cfg --command 'transport select hla_swd' --command 'set CPUTAPID #{CPUTAPID}' --file target/#{OOCD_TARGET}.cfg --command 'adapter speed 100' --command 'init' --command 'halt' --command 'reset init' --command 'flash write_image erase #{t.source}' --command 'reset' --command 'shutdown'" + sh "#{OOCD} --file interface/#{OOCD_INTERFACE}.cfg --command 'transport select hla_swd' --file target/#{OOCD_TARGET}.cfg --command 'adapter speed 100' --command 'init' --command 'halt' --command 'reset init' --command 'flash write_image erase #{t.source}' --command 'reset' --command 'shutdown'" when "BMP" sh "#{GDB} --eval-command='target extended-remote #{BMP_PORT}' --eval-command='set confirm off' --eval-command='monitor swdp_scan' --eval-command='attach 1' --eval-command='load' --eval-command='kill' --eval-command='quit' #{t.source}" end @@ -237,7 +235,7 @@ task :debug => APPLICATION+".elf" do |t| case SWD_ADAPTER when "STLINKV2" # for GDB to work with openOCD the firmware needs to be reloaded - exec("#{GDB} --eval-command='target remote | #{OOCD} --file interface/#{OOCD_INTERFACE}.cfg --command \"transport select hla_swd\" --command \"set CPUTAPID #{CPUTAPID}\" --file target/#{OOCD_TARGET}.cfg --command \"gdb_port pipe; log_output /dev/null; init\"' #{t.source}") + exec("#{GDB} --eval-command='target remote | #{OOCD} --file interface/#{OOCD_INTERFACE}.cfg --command \"transport select hla_swd\" --file target/#{OOCD_TARGET}.cfg --command \"gdb_port pipe; log_output /dev/null; init\"' #{t.source}") when "BMP" exec("#{GDB} --eval-command='target extended-remote #{BMP_PORT}' --eval-command='monitor version' --eval-command='monitor swdp_scan' --eval-command='attach 1' #{t.source}") end @@ -249,7 +247,7 @@ task :debug_bootloader => BOOTLOADER+".elf" do |t| case SWD_ADAPTER when "STLINKV2" # for GDB to work with openOCD the firmware needs to be reloaded - exec("#{GDB} --eval-command='target remote | #{OOCD} --file interface/#{OOCD_INTERFACE}.cfg --command \"transport select hla_swd\" --command \"set CPUTAPID #{CPUTAPID}\" --file target/#{OOCD_TARGET}.cfg --command \"gdb_port pipe; log_output /dev/null; init\"' --eval-command='monitor reset init' #{t.source}") + exec("#{GDB} --eval-command='target remote | #{OOCD} --file interface/#{OOCD_INTERFACE}.cfg --command \"transport select hla_swd\" --file target/#{OOCD_TARGET}.cfg --command \"gdb_port pipe; log_output /dev/null; init\"' --eval-command='monitor reset init' #{t.source}") when "BMP" exec("#{GDB} --eval-command='target extended-remote #{BMP_PORT}' --eval-command='monitor version' --eval-command='monitor swdp_scan' --eval-command='attach 1' #{t.source}") end