# Helper macros to convert spaces into question marks and back again e := sp := $(e) $(e) qs = $(subst ?,$(sp),$1) sq = $(subst $(sp),?,$1) # Get name of this Makefile (avoid getting word 0 and a starting space) makefile_name := $(wordlist 1,1000,$(MAKEFILE_LIST)) # Get path of this Makefile makefile_path := $(call qs,$(dir $(call sq,$(abspath $(call sq,$(makefile_name)))))) # Get path where the Application is application_path := $(call qs,$(abspath $(call sq,$(makefile_path)..))) # Change makefile_name to a relative path makefile_name := $(subst $(call sq,$(application_path))/,,$(call sq,$(abspath $(call sq,$(makefile_name))))) # Get relative path to makefile from application_path makefile_path_relative := $(subst $(call sq,$(application_path))/,,$(call sq,$(abspath $(call sq,$(makefile_path))))) # Get path to Middlewares touchgfx_middlewares_path := gcc/Middlewares cubemx_middlewares_path := Middlewares # Get path to Drivers Drivers_path := Drivers # Get path to GPU2D gpu2d_path := Appli/Middlewares/ST/touchgfx_components/gpu2d # Get OS path touchgfx_os_path := $(touchgfx_middlewares_path)/Third_Party/FreeRTOS cubemx_os_path := $(cubemx_middlewares_path)/Third_Party/FreeRTOS # Get identification of this system ifeq ($(OS),Windows_NT) UNAME := MINGW32_NT-6.2 else UNAME := $(shell uname -s) endif board_name := STM32H7S78-DK platform := cortex_m7 cpp_compiler_options_local := c_compiler_options_local := .PHONY: all clean assets flash intflash all: $(filter clean,$(MAKECMDGOALS)) all clean assets: @cd "$(application_path)" && $(MAKE) -r -f $(makefile_name) -s $(MFLAGS) _$@_ flash intflash: all @cd "$(application_path)" && $(MAKE) -r -f $(makefile_name) -s $(MFLAGS) _$@_ # Directories containing application-specific source and header files. # Additional components can be added to this list. make will look for # source files recursively in comp_name/src and setup an include directive # for comp_name/include. components := \ Appli/TouchGFX/gui \ Appli/TouchGFX/generated/gui_generated touchgfx_generator_components := \ Appli/TouchGFX/target \ Appli/TouchGFX/App # Location of folder containing bmp/png files. asset_images_input := Appli/TouchGFX/assets/images # Location of folder to search for ttf font files asset_fonts_input := Appli/TouchGFX/assets/fonts # Location of folder where the texts.xml is placed asset_texts_input := Appli/TouchGFX/assets/texts # Location of folder where the video.avi is placed asset_videos_input := Appli/TouchGFX/assets/videos build_root_path := Appli/TouchGFX/build object_output_path := $(build_root_path)/$(board_name) binary_output_path := $(build_root_path)/bin # Location of output folders where autogenerated code from assets is placed asset_root_path := Appli/TouchGFX/generated asset_images_output := $(asset_root_path)/images asset_fonts_output := $(asset_root_path)/fonts asset_texts_output := $(asset_root_path)/texts asset_videos_output := $(asset_root_path)/videos #include application specific configuration include $(application_path)/Appli/TouchGFX/config/gcc/app.mk # corrects TouchGFX Path touchgfx_path := Appli/${subst ../,,$(touchgfx_path)} os_source_files := \ $(cubemx_os_path)/Source/croutine.c \ $(cubemx_os_path)/Source/event_groups.c \ $(cubemx_os_path)/Source/list.c \ $(cubemx_os_path)/Source/queue.c \ $(cubemx_os_path)/Source/stream_buffer.c \ $(cubemx_os_path)/Source/tasks.c \ $(cubemx_os_path)/Source/timers.c \ $(cubemx_os_path)/Source/CMSIS_RTOS_V2/cmsis_os2.c os_include_paths := \ $(cubemx_os_path)/Source/include \ $(cubemx_os_path)/Source/CMSIS_RTOS_V2 \ $(touchgfx_os_path)/Source/portable/GCC/ARM_CM4F # these paths can be moved to the touchgfx portable dirs in the future os_source_files += \ $(cubemx_os_path)/Source/portable/MemMang/heap_4.c \ $(cubemx_os_path)/Source/portable/Common/mpu_wrappers.c \ $(touchgfx_os_path)/Source/portable/GCC/ARM_CM4F/port.c ifeq ($(UNAME), Linux) imageconvert_executable := $(touchgfx_path)/framework/tools/imageconvert/build/linux/imageconvert.out fontconvert_executable := $(touchgfx_path)/framework/tools/fontconvert/build/linux/fontconvert.out else ifeq ($(UNAME), Darwin) # Pas de binaire macOS pour imageconvert/fontconvert (Windows/Linux only) : on passe par le # Wine embarque dans TouchGFX.app (TouchGFX Designer pour macOS est une appli Wineskin). imageconvert_executable := gcc/macos_wine_wrappers/imageconvert.sh fontconvert_executable := gcc/macos_wine_wrappers/fontconvert.sh else imageconvert_executable := $(touchgfx_path)/framework/tools/imageconvert/build/win/imageconvert.out fontconvert_executable := $(touchgfx_path)/framework/tools/fontconvert/build/win/fontconvert.out stldr := MX66UW1G45G_STM32H7S78-DK.stldr include $(application_path)/gcc/include/cube_programmer.mk endif target_executable := target.elf target_hex := target.hex assembler := arm-none-eabi-gcc c_compiler := arm-none-eabi-gcc cpp_compiler := arm-none-eabi-g++ linker := arm-none-eabi-g++ objcopy := arm-none-eabi-objcopy archiver := arm-none-eabi-ar strip := arm-none-eabi-strip assembler_options += \ -Wall \ -fno-exceptions \ -g3 \ -mthumb \ -MMD \ -MP \ -c \ -x assembler-with-cpp c_compiler_options += \ --specs=nano.specs \ -MMD \ -MP \ -Os \ -Wall \ -fdata-sections \ -ffunction-sections \ -fno-exceptions \ -fstack-usage \ -g3 \ -mthumb \ -std=gnu11 cpp_compiler_options += \ --specs=nano.specs \ -Os \ -fdata-sections \ -fno-exceptions \ -fno-rtti \ -g3 \ -MMD \ -MP \ -Wall \ -femit-class-debug-always \ -ffunction-sections \ -fno-use-cxa-atexit \ -fstack-usage \ -mthumb \ -std=gnu++14 linker_options += \ --specs=nosys.specs \ --specs=nano.specs \ -Os \ -Wl,--gc-sections -static \ -Wl,--print-memory-usage \ -Wl,--start-group -lc -lm -lstdc++ -lsupc++ -Wl,--end-group \ -fno-exceptions \ -fno-rtti \ -g3 \ -mthumb # Additional toolchain configuration for Cortex-M7 targets. float_options := -mfpu=fpv5-d16 -mfloat-abi=hard assembler_options += $(float_options) -mcpu=cortex-m7 -DCORE_CM7 c_compiler_options += $(float_options) -mcpu=cortex-m7 -DCORE_CM7 cpp_compiler_options += $(float_options) -mcpu=cortex-m7 -DCORE_CM7 linker_options += $(float_options) -mcpu=cortex-m7 c_compiler_options += -DSTM32H7S7xx -DUSE_HAL_DRIVER cpp_compiler_options += -DSTM32H7S7xx -DUSE_HAL_DRIVER # include everything + specific vendor folders framework_includes := $(touchgfx_path)/framework/include # this needs to change when assset include folder changes. all_components := $(components) \ $(asset_fonts_output) \ $(asset_images_output) \ $(asset_texts_output) \ $(asset_videos_output) include_paths := $(library_includes) \ $(foreach comp, $(all_components), $(comp)/include) \ $(foreach comp, $(touchgfx_generator_components), $(comp)/generated) \ $(framework_includes) \ $(cubemx_middlewares_path) \ $(touchgfx_middlewares_path) \ $(touchgfx_generator_components) source_paths = $(foreach comp, $(all_components), $(comp)/src) \ $(touchgfx_generator_components) # Finds files that matches the specified pattern. The directory list # is searched recursively. It is safe to invoke this function with an # empty list of directories. # # Param $(1): List of directories to search # Param $(2): The file pattern to search for define find $(foreach dir,$(1),$(foreach d,$(wildcard $(dir)/*),\ $(call find,$(d),$(2))) $(wildcard $(dir)/$(strip $(2)))) endef unexport find fontconvert_ttf_lower_files := $(call find, $(asset_fonts_input), *.ttf) fontconvert_ttf_upper_files := $(call find, $(asset_fonts_input), *.TTF) fontconvert_otf_lower_files := $(call find, $(asset_fonts_input), *.otf) fontconvert_otf_upper_files := $(call find, $(asset_fonts_input), *.OTF) fontconvert_bdf_lower_files := $(call find, $(asset_fonts_input), *.bdf) fontconvert_bdf_upper_files := $(call find, $(asset_fonts_input), *.BDF) fontconvert_font_files := \ $(fontconvert_ttf_lower_files) \ $(fontconvert_ttf_upper_files) \ $(fontconvert_otf_lower_files) \ $(fontconvert_otf_upper_files) \ $(fontconvert_bdf_lower_files) \ $(fontconvert_bdf_upper_files) source_files := $(call find, $(source_paths),*.cpp) video_files := $(call find, $(assets_videos_input),*.avi) # Drivers/STM32H7RSxx_HAL_Driver board_c_files += \ $(Drivers_path)/STM32H7RSxx_HAL_Driver/Src/stm32h7rsxx_hal.c \ $(Drivers_path)/STM32H7RSxx_HAL_Driver/Src/stm32h7rsxx_hal_cortex.c \ $(Drivers_path)/STM32H7RSxx_HAL_Driver/Src/stm32h7rsxx_hal_crc.c \ $(Drivers_path)/STM32H7RSxx_HAL_Driver/Src/stm32h7rsxx_hal_crc_ex.c \ $(Drivers_path)/STM32H7RSxx_HAL_Driver/Src/stm32h7rsxx_hal_dma.c \ $(Drivers_path)/STM32H7RSxx_HAL_Driver/Src/stm32h7rsxx_hal_dma_ex.c \ $(Drivers_path)/STM32H7RSxx_HAL_Driver/Src/stm32h7rsxx_hal_dma2d.c \ $(Drivers_path)/STM32H7RSxx_HAL_Driver/Src/stm32h7rsxx_hal_exti.c \ $(Drivers_path)/STM32H7RSxx_HAL_Driver/Src/stm32h7rsxx_hal_flash.c \ $(Drivers_path)/STM32H7RSxx_HAL_Driver/Src/stm32h7rsxx_hal_flash_ex.c \ $(Drivers_path)/STM32H7RSxx_HAL_Driver/Src/stm32h7rsxx_hal_gpio.c \ $(Drivers_path)/STM32H7RSxx_HAL_Driver/Src/stm32h7rsxx_hal_gpu2d.c \ $(Drivers_path)/STM32H7RSxx_HAL_Driver/Src/stm32h7rsxx_hal_i2c.c \ $(Drivers_path)/STM32H7RSxx_HAL_Driver/Src/stm32h7rsxx_hal_i2c_ex.c \ $(Drivers_path)/STM32H7RSxx_HAL_Driver/Src/stm32h7rsxx_hal_icache.c \ $(Drivers_path)/STM32H7RSxx_HAL_Driver/Src/stm32h7rsxx_hal_jpeg.c \ $(Drivers_path)/STM32H7RSxx_HAL_Driver/Src/stm32h7rsxx_hal_ltdc.c \ $(Drivers_path)/STM32H7RSxx_HAL_Driver/Src/stm32h7rsxx_hal_ltdc_ex.c \ $(Drivers_path)/STM32H7RSxx_HAL_Driver/Src/stm32h7rsxx_hal_pwr.c \ $(Drivers_path)/STM32H7RSxx_HAL_Driver/Src/stm32h7rsxx_hal_pwr_ex.c \ $(Drivers_path)/STM32H7RSxx_HAL_Driver/Src/stm32h7rsxx_hal_rcc.c \ $(Drivers_path)/STM32H7RSxx_HAL_Driver/Src/stm32h7rsxx_hal_rcc_ex.c \ $(Drivers_path)/STM32H7RSxx_HAL_Driver/Src/stm32h7rsxx_hal_smbus.c \ $(Drivers_path)/STM32H7RSxx_HAL_Driver/Src/stm32h7rsxx_hal_smbus_ex.c \ $(Drivers_path)/STM32H7RSxx_HAL_Driver/Src/stm32h7rsxx_hal_tim.c \ $(Drivers_path)/STM32H7RSxx_HAL_Driver/Src/stm32h7rsxx_hal_tim_ex.c \ $(Drivers_path)/STM32H7RSxx_HAL_Driver/Src/stm32h7rsxx_hal_xspi.c board_c_files += \ Appli/Core/Src/main.c \ Appli/Core/Src/freertos.c \ Appli/Core/Src/stm32h7rsxx_it.c \ Appli/Core/Src/stm32h7rsxx_hal_msp.c \ Appli/Core/Src/stm32h7rsxx_hal_timebase_tim.c \ Appli/Core/Src/system_stm32h7rsxx.c \ Appli/Core/Src/audio_effects.c \ Appli/Core/Src/audio_analysis.c \ Appli/Core/Src/audio_looper.c \ Appli/Core/Src/fx_octaver.c \ Appli/Core/Src/fx_equalizer.c \ Appli/Core/Src/fx_overdrive.c \ Appli/Core/Src/fx_saturation.c \ Appli/Core/Src/fx_echo.c \ Appli/Core/Src/fx_reverb.c # CMSIS-DSP (vendored from the STM32H7RS firmware package, source-only : no # precompiled .a for this device). Only the RFFT float32 chain needed by # audio_analysis.c is included, not the whole library. The MVE/Helium code # paths in arm_cfft_f32.c/arm_cfft_init_f32.c are guarded behind # ARM_MATH_MVEF, which is never defined here, so they compile out on this # Cortex-M7 (no Helium) target. board_c_files += \ $(Drivers_path)/CMSIS/DSP/Source/TransformFunctions/arm_rfft_fast_f32.c \ $(Drivers_path)/CMSIS/DSP/Source/TransformFunctions/arm_rfft_fast_init_f32.c \ $(Drivers_path)/CMSIS/DSP/Source/TransformFunctions/arm_cfft_f32.c \ $(Drivers_path)/CMSIS/DSP/Source/TransformFunctions/arm_cfft_init_f32.c \ $(Drivers_path)/CMSIS/DSP/Source/TransformFunctions/arm_cfft_radix8_f32.c \ $(Drivers_path)/CMSIS/DSP/Source/TransformFunctions/arm_bitreversal2.c \ $(Drivers_path)/CMSIS/DSP/Source/CommonTables/arm_common_tables.c \ $(Drivers_path)/CMSIS/DSP/Source/CommonTables/arm_const_structs.c # Drivers board_include_paths := \ $(Drivers_path)/CMSIS/Include \ $(Drivers_path)/CMSIS/Device/ST/STM32H7RSxx/Include \ $(Drivers_path)/STM32H7RSxx_HAL_Driver/Inc \ $(Drivers_path)/CMSIS/RTOS2/Include \ $(Drivers_path)/STM32H7RSxx_BSP/STM32H7S78-DK \ $(Drivers_path)/STM32H7RSxx_BSP/Components/wm8904 \ $(Drivers_path)/CMSIS/DSP/Include \ $(Drivers_path)/CMSIS/DSP/PrivateInclude \ Appli/Core/Inc \ $(gpu2d_path)/TouchGFXNema/include \ $(gpu2d_path)/NemaGFX/include board_c_files += \ $(Drivers_path)/STM32H7RSxx_BSP/STM32H7S78-DK/stm32h7s78_discovery_audio.c \ $(Drivers_path)/STM32H7RSxx_BSP/STM32H7S78-DK/stm32h7s78_discovery_bus.c \ $(Drivers_path)/STM32H7RSxx_BSP/STM32H7S78-DK/stm32h7s78_discovery.c \ $(Drivers_path)/STM32H7RSxx_BSP/Components/wm8904/wm8904.c \ $(Drivers_path)/STM32H7RSxx_BSP/Components/wm8904/wm8904_reg.c \ $(Drivers_path)/STM32H7RSxx_HAL_Driver/Src/stm32h7rsxx_hal_mdf.c \ $(Drivers_path)/STM32H7RSxx_HAL_Driver/Src/stm32h7rsxx_hal_i2s.c asm_source_files := \ gcc/startup_stm32h7s7l8hxh_appli.s include_paths += platform/os $(board_include_paths) $(os_include_paths) video_object_files := $(call find, $(asset_videos_output),*.o) c_source_files := $(makefile_path_relative)/sysmem.c $(makefile_path_relative)/syscalls.c $(call find, $(source_paths),*.c) $(os_source_files) $(board_c_files) source_files += $(board_cpp_files) object_files := $(source_files) $(c_source_files) # start converting paths object_files := $(object_files:$(touchgfx_path)/%.cpp=$(object_output_path)/touchgfx/%.o) object_files := $(object_files:%.cpp=$(object_output_path)/%.o) object_files := $(object_files:$(touchgfx_middlewares_path)/%.c=$(object_output_path)/$(touchgfx_middlewares_path)/%.o) object_files := $(object_files:$(cubemx_middlewares_path)/%.c=$(object_output_path)/$(cubemx_middlewares_path)/%.o) object_files := $(object_files:$(Drivers_path)/%.c=$(object_output_path)/Drivers/%.o) object_files := $(object_files:%.c=$(object_output_path)/%.o) # remove templates files object_files := $(filter-out %template.o,$(object_files)) dependency_files := $(object_files:%.o=%.d) object_asm_files := $(asm_source_files:%.s=$(object_output_path)/%.o) object_asm_files := $(patsubst $(object_output_path)/%,$(object_output_path)/%,$(object_asm_files)) textconvert_script_path := $(touchgfx_path)/framework/tools/textconvert textconvert_executable := $(call find, $(textconvert_script_path), *.rb) videoconvert_script_path := $(touchgfx_path)/framework/tools/videoconvert text_database := $(asset_texts_input)/texts.xml libraries := touchgfx-float-abi-hard library_include_paths := $(touchgfx_path)/lib/core/$(platform)/gcc \ libraries += touchgfxnema-float-abi-hard \ nemagfx-float-abi-hard library_include_paths += $(gpu2d_path)/TouchGFXNema/lib/cortex_m7/gcc \ $(gpu2d_path)/NemaGFX/lib/core/cortex_m7/gcc .PHONY: _all_ _clean_ _assets_ _flash_ _intflash_ generate_assets build_executable # Force linking each time .PHONY: $(binary_output_path)/$(target_executable) _all_: generate_assets # if ExtFlashSection or FontFlashSection is detected inside the executable, enable external flash flash_section_count := 0 elf_filename := "$(application_path)/$(binary_output_path)/$(target_executable)" ifeq ($(shell test -e $(elf_filename) && echo -n has_elf_file),has_elf_file) flash_section_count := $(shell readelf -S $(elf_filename) | grep FlashSection | wc -l) endif ifeq ($(shell test $(flash_section_count) -gt 0; echo $$?),0) _flash_: _extflash_ else _flash_: _intflash_ endif include $(application_path)/gcc/include/flash_sections_int_ext.mk generate_assets: _assets_ @$(MAKE) -f $(makefile_name) -r -s $(MFLAGS) build_executable build_executable: $(binary_output_path)/$(target_executable) $(binary_output_path)/$(target_executable): $(object_files) $(object_asm_files) @echo Video Objects: $(video_object_files) @echo Linking $(@) @mkdir -p $(@D) @$(linker) \ $(linker_options) -T $(makefile_path_relative)/../Appli/stm32h7rsxx_RAMxspi1_ROMxspi2.ld -Wl,-Map=$(@D)/application.map $(linker_options_local) \ $(patsubst %,-L%,$(library_include_paths)) \ $(object_files) $(object_asm_files) -o $@ \ -Wl,--start-group $(patsubst %,-l%,$(libraries)) -Wl,--end-group @echo "Producing additional output formats..." @echo " target.hex - Combined internal+external hex" @$(objcopy) -O ihex $@ $(@D)/target.hex @echo " intflash.elf - Internal flash, elf debug" @$(objcopy) --remove-section=ExtFlashSection --remove-section=FontFlashSection --remove-section=TextFlashSection $@ $(@D)/intflash.elf 2>/dev/null @echo " intflash.hex - Internal flash, hex" @$(objcopy) -O ihex --remove-section=ExtFlashSection --remove-section=FontFlashSection --remove-section=TextFlashSection $@ $(@D)/intflash.hex # re-enable if extflash binaries are required in your workflow # @echo " extflash.bin - External flash, binary" # @$(objcopy) -O binary --only-section=*FlashSection $@ $(@D)/extflash.bin $(object_output_path)/touchgfx/%.o: $(touchgfx_path)/%.cpp Appli/TouchGFX/config/gcc/app.mk @echo Compiling $< @mkdir -p $(@D) @$(cpp_compiler) \ -MMD -MP $(cpp_compiler_options) $(cpp_compiler_options_local) $(user_cflags) \ $(patsubst %,-I%,$(include_paths)) \ -c $< -o $@ $(object_output_path)/%.o: %.cpp Appli/TouchGFX/config/gcc/app.mk @echo Compiling $< @mkdir -p $(@D) @$(cpp_compiler) \ -MMD -MP $(cpp_compiler_options) $(cpp_compiler_options_local) $(user_cflags) \ $(patsubst %,-I%,$(include_paths)) \ -c $< -o $@ $(object_output_path)/touchgfx/%.o: $(touchgfx_path)/%.c Appli/TouchGFX/config/gcc/app.mk @echo Compiling $< @mkdir -p $(@D) @$(c_compiler) \ -MMD -MP $(c_compiler_options) $(c_compiler_options_local) $(user_cflags) \ $(patsubst %,-I%,$(include_paths)) \ -c $< -o $@ $(object_output_path)/%.o: %.c Appli/TouchGFX/config/gcc/app.mk @echo Compiling $< @mkdir -p $(@D) @$(c_compiler) \ -MMD -MP $(c_compiler_options) $(c_compiler_options_local) $(user_cflags) \ $(patsubst %,-I%,$(include_paths)) \ -c $< -o $@ $(object_output_path)/%.o: %.s Appli/TouchGFX/config/gcc/app.mk @echo Compiling ASM $< @mkdir -p $(@D) @$(assembler) \ $(assembler_options) \ $(patsubst %,-I %,$(os_include_paths)) \ -c $< -o $@ ifeq ($(MAKECMDGOALS),build_executable) $(firstword $(dependency_files)): Appli/TouchGFX/config/gcc/app.mk @rm -rf $(object_output_path) -include $(dependency_files) endif _assets_: images texts Videos .PHONY: images texts Videos images: @$(imageconvert_executable) -r $(asset_images_input) -w $(asset_images_output) Videos: @ruby $(videoconvert_script_path)/videoconvert.rb $(asset_videos_input) $(asset_videos_output) texts: @ruby $(textconvert_script_path)/main.rb $(text_database) $(fontconvert_executable) $(asset_fonts_output) $(asset_texts_output) $(asset_fonts_input) Appli/TouchGFX _clean_: @echo Cleaning @rm -rf $(build_root_path) # Do not remove gui_generated @rm -rf $(asset_images_output) @rm -rf $(asset_fonts_output) @rm -rf $(asset_texts_output) @rm -rf $(asset_videos_output) # Create directory to avoid error if it does not exist @mkdir -p $(asset_root_path) # Remove assets folder if it is empty (i.e. no gui_generated folder) @rmdir $(asset_root_path) 2>/dev/null || true