Skip to content

Commit

Permalink
Improve generator
Browse files Browse the repository at this point in the history
  • Loading branch information
MaJerle committed Jan 8, 2024
1 parent c74dc7a commit 70d41bd
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 113 deletions.
2 changes: 2 additions & 0 deletions cube-ide-cmake-demo-proj/.vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"args": [
"--connect",
"port=swd",
"mode=UR", //Under reset
"--download", "${command:cmake.launchTargetPath}",
"-hardRst", // Hardware reset - if rst pin is connected
"-rst", // Software reset (backup)
Expand All @@ -59,6 +60,7 @@
"args": [
"--connect",
"port=swd",
"mode=UR", //Under reset
"sn=<yourserialnumber>",
"--download", "${command:cmake.launchTargetPath}",
"-hardRst", // Hardware reset - if rst pin is connected
Expand Down
6 changes: 1 addition & 5 deletions cube-ide-cmake-demo-proj/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS ON)

# Core MCU flags, CPU type, instruction set and FPU setup
set(cpu_PARAMS
# Other parameters
# -mthumb
# -mcpu, -mfloat, -mfloat-abi, ...
)
set(cpu_PARAMS)

# Sources
set(sources_SRCS)
Expand Down
27 changes: 7 additions & 20 deletions cube-ide-cmake-demo-proj/cmake_generated/cmake_generated.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,14 @@ cmake_minimum_required(VERSION 3.22)
set(cpu_PARAMS ${cpu_PARAMS}
-mthumb

# Other parameters
# -mcpu, -mfloat, -mfloat-abi, ...
# -mcpu, -mfloat, -mfloat-abi config
-mcpu=cortex-m7
-mfloat-abi=hard
-mfpu=fpv5-d16
)

# Linker script
set(linker_script_SRC ${linker_script_SRC}
${CMAKE_CURRENT_SOURCE_DIR}/STM32H735IGKX_FLASH.ld
)
set(linker_script_SRC ${linker_script_SRC}${CMAKE_CURRENT_SOURCE_DIR}/STM32H735IGKX_FLASH.ld)

# Sources
set(sources_SRCS ${sources_SRCS}
Expand All @@ -42,12 +39,8 @@ set(include_c_DIRS ${include_c_DIRS}
${CMAKE_CURRENT_SOURCE_DIR}/Drivers/CMSIS/Include
${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Inc
)
set(include_cxx_DIRS ${include_cxx_DIRS}

)
set(include_asm_DIRS ${include_asm_DIRS}

)
set(include_cxx_DIRS ${include_cxx_DIRS})
set(include_asm_DIRS ${include_asm_DIRS})

# Symbols definition
set(symbols_c_SYMB ${symbols_c_SYMB}
Expand All @@ -63,22 +56,16 @@ set(symbols_c_SYMB ${symbols_c_SYMB}
"USE_FULL_LL_DRIVER"
"VDD_VALUE=3300"
)
set(symbols_cxx_SYMB ${symbols_cxx_SYMB}

)
set(symbols_cxx_SYMB ${symbols_cxx_SYMB})
set(symbols_asm_SYMB ${symbols_asm_SYMB}
"DEBUG"
)

# Link directories
set(link_DIRS ${link_DIRS}

)
set(link_DIRS ${link_DIRS})

# Link libraries
set(link_LIBS ${link_LIBS}

)
set(link_LIBS ${link_LIBS})

# Compiler options
set(compiler_OPTS ${compiler_OPTS})
Expand Down
2 changes: 2 additions & 0 deletions script-projects/h735g-dk-touchgfx/.vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"args": [
"--connect",
"port=swd",
"mode=UR", //Under reset
"--download", "${command:cmake.launchTargetPath}",
"-hardRst", // Hardware reset - if rst pin is connected
"-rst", // Software reset (backup)
Expand All @@ -59,6 +60,7 @@
"args": [
"--connect",
"port=swd",
"mode=UR", //Under reset
"sn=<yourserialnumber>",
"--download", "${command:cmake.launchTargetPath}",
"-hardRst", // Hardware reset - if rst pin is connected
Expand Down
6 changes: 1 addition & 5 deletions script-projects/h735g-dk-touchgfx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS ON)

# Core MCU flags, CPU type, instruction set and FPU setup
set(cpu_PARAMS
# Other parameters
# -mthumb
# -mcpu, -mfloat, -mfloat-abi, ...
)
set(cpu_PARAMS)

# Sources
set(sources_SRCS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,14 @@ cmake_minimum_required(VERSION 3.22)
set(cpu_PARAMS ${cpu_PARAMS}
-mthumb

# Other parameters
# -mcpu, -mfloat, -mfloat-abi, ...
# -mcpu, -mfloat, -mfloat-abi config
-mcpu=cortex-m7
-mfloat-abi=hard
-mfpu=fpv5-d16
)

# Linker script
set(linker_script_SRC ${linker_script_SRC}
${CMAKE_CURRENT_SOURCE_DIR}/STM32CubeIDE/STM32H735IGKX_FLASH.ld
)
set(linker_script_SRC ${linker_script_SRC}${CMAKE_CURRENT_SOURCE_DIR}/STM32CubeIDE/STM32H735IGKX_FLASH.ld)

# Sources
set(sources_SRCS ${sources_SRCS}
Expand Down Expand Up @@ -158,9 +155,7 @@ set(include_cxx_DIRS ${include_cxx_DIRS}
${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/target
${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/target/generated
)
set(include_asm_DIRS ${include_asm_DIRS}

)
set(include_asm_DIRS ${include_asm_DIRS})

# Symbols definition
set(symbols_c_SYMB ${symbols_c_SYMB}
Expand All @@ -183,9 +178,7 @@ set(link_DIRS ${link_DIRS}
)

# Link libraries
set(link_LIBS ${link_LIBS}
:libtouchgfx-float-abi-hard.a
)
set(link_LIBS ${link_LIBS}:libtouchgfx-float-abi-hard.a)

# Compiler options
set(compiler_OPTS ${compiler_OPTS})
Expand Down
2 changes: 2 additions & 0 deletions script-projects/h735g-dk-usart/.vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"args": [
"--connect",
"port=swd",
"mode=UR", //Under reset
"--download", "${command:cmake.launchTargetPath}",
"-hardRst", // Hardware reset - if rst pin is connected
"-rst", // Software reset (backup)
Expand All @@ -59,6 +60,7 @@
"args": [
"--connect",
"port=swd",
"mode=UR", //Under reset
"sn=<yourserialnumber>",
"--download", "${command:cmake.launchTargetPath}",
"-hardRst", // Hardware reset - if rst pin is connected
Expand Down
6 changes: 1 addition & 5 deletions script-projects/h735g-dk-usart/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS ON)

# Core MCU flags, CPU type, instruction set and FPU setup
set(cpu_PARAMS
# Other parameters
# -mthumb
# -mcpu, -mfloat, -mfloat-abi, ...
)
set(cpu_PARAMS)

# Sources
set(sources_SRCS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,14 @@ cmake_minimum_required(VERSION 3.22)
set(cpu_PARAMS ${cpu_PARAMS}
-mthumb

# Other parameters
# -mcpu, -mfloat, -mfloat-abi, ...
# -mcpu, -mfloat, -mfloat-abi config
-mcpu=cortex-m7
-mfloat-abi=hard
-mfpu=fpv5-d16
)

# Linker script
set(linker_script_SRC ${linker_script_SRC}
${CMAKE_CURRENT_SOURCE_DIR}/STM32H735IGKX_FLASH.ld
)
set(linker_script_SRC ${linker_script_SRC}${CMAKE_CURRENT_SOURCE_DIR}/STM32H735IGKX_FLASH.ld)

# Sources
set(sources_SRCS ${sources_SRCS}
Expand Down Expand Up @@ -68,35 +65,25 @@ set(include_c_DIRS ${include_c_DIRS}
${CMAKE_CURRENT_SOURCE_DIR}/FATFS/Target
${CMAKE_CURRENT_SOURCE_DIR}/Middlewares/Third_Party/FatFs/src
)
set(include_cxx_DIRS ${include_cxx_DIRS}

)
set(include_asm_DIRS ${include_asm_DIRS}

)
set(include_cxx_DIRS ${include_cxx_DIRS})
set(include_asm_DIRS ${include_asm_DIRS})

# Symbols definition
set(symbols_c_SYMB ${symbols_c_SYMB}
"DEBUG"
"STM32H735xx"
"USE_HAL_DRIVER"
)
set(symbols_cxx_SYMB ${symbols_cxx_SYMB}

)
set(symbols_cxx_SYMB ${symbols_cxx_SYMB})
set(symbols_asm_SYMB ${symbols_asm_SYMB}
"DEBUG"
)

# Link directories
set(link_DIRS ${link_DIRS}

)
set(link_DIRS ${link_DIRS})

# Link libraries
set(link_LIBS ${link_LIBS}

)
set(link_LIBS ${link_LIBS})

# Compiler options
set(compiler_OPTS ${compiler_OPTS})
Expand Down
20 changes: 10 additions & 10 deletions stm32-cube-cmake-vscode.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import traceback

NEWLINE_INDENTED = '\n '
NEWLINE = '\n'

#
# Generate parser object
Expand Down Expand Up @@ -536,8 +537,7 @@ def parse_and_generate(projectFolderBasePath, args):
# Check all files in the same directory as .cproject/.project directory
templatefiledata = templatefiledata.replace(
'{{sr:sources_SRCS}}',
NEWLINE_INDENTED.join([gen_relative_path_to_cmake_folder(
projectFolderBasePath, p) for p in source_files_paths])
(NEWLINE_INDENTED + NEWLINE_INDENTED.join([gen_relative_path_to_cmake_folder(projectFolderBasePath, p) for p in source_files_paths]) + NEWLINE) if len(source_files_paths) > 0 else ''
)

#
Expand All @@ -559,8 +559,9 @@ def parse_and_generate(projectFolderBasePath, args):
# Normalize path to remove "Debug" from path
paths.append(os.path.normpath(path))
paths.sort()
templatefiledata = templatefiledata.replace('{{sr:' + varname + '}}', NEWLINE_INDENTED.join(
[gen_relative_path_to_cmake_folder(projectFolderBasePath, p) for p in paths]))
templatefiledata = templatefiledata.replace('{{sr:' + varname + '}}',
(NEWLINE_INDENTED + NEWLINE_INDENTED.join([gen_relative_path_to_cmake_folder(projectFolderBasePath, p) for p in paths]) + NEWLINE) if len(paths) > 0 else '')


#
# Check all symbols (global defines)
Expand All @@ -570,8 +571,8 @@ def parse_and_generate(projectFolderBasePath, args):
for compiler in ['c', 'cxx', 'asm']:
varname = 'symbols_' + compiler + '_SYMB'
data_obj['confs'][conf][compiler]['symbols'].sort()
templatefiledata = templatefiledata.replace('{{sr:' + varname + '}}', NEWLINE_INDENTED.join(
["\"" + f + "\"" for f in data_obj['confs'][conf][compiler]['symbols']]))
templatefiledata = templatefiledata.replace('{{sr:' + varname + '}}',
(NEWLINE_INDENTED + NEWLINE_INDENTED.join(["\"" + f + "\"" for f in data_obj['confs'][conf][compiler]['symbols']]) + NEWLINE) if len(data_obj['confs'][conf][compiler]['symbols']) else '')

#
# Setup linked libraries
Expand All @@ -583,10 +584,9 @@ def parse_and_generate(projectFolderBasePath, args):
# Do some optimizations with path if necessary
pass
libs.sort()
templatefiledata = templatefiledata.replace('{{sr:link_DIRS}}', NEWLINE_INDENTED.join([gen_relative_path_to_cmake_folder(
projectFolderBasePath, os.path.normpath(os.path.join(CProjBasePath, 'Debug', p))) for p in paths]))
templatefiledata = templatefiledata.replace(
'{{sr:link_LIBS}}', NEWLINE_INDENTED.join(libs))
templatefiledata = templatefiledata.replace('{{sr:link_DIRS}}',
(NEWLINE_INDENTED + NEWLINE_INDENTED.join([gen_relative_path_to_cmake_folder(projectFolderBasePath, os.path.normpath(os.path.join(CProjBasePath, 'Debug', p))) for p in paths]) + NEWLINE) if len(paths) > 0 else '')
templatefiledata = templatefiledata.replace('{{sr:link_LIBS}}', NEWLINE_INDENTED.join(libs))

#
# Setup linker script
Expand Down
6 changes: 1 addition & 5 deletions templates/CMakeLists_template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS ON)

# Core MCU flags, CPU type, instruction set and FPU setup
set(cpu_PARAMS
# Other parameters
# -mthumb
# -mcpu, -mfloat, -mfloat-abi, ...
)
set(cpu_PARAMS)

# Sources
set(sources_SRCS)
Expand Down
43 changes: 11 additions & 32 deletions templates/cmake_generated/cmake_generated_template.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,52 +8,31 @@ cmake_minimum_required(VERSION 3.22)
set(cpu_PARAMS ${cpu_PARAMS}
-mthumb

# Other parameters
# -mcpu, -mfloat, -mfloat-abi, ...
# -mcpu, -mfloat, -mfloat-abi config
{{sr:cpu_params}}
)

# Linker script
set(linker_script_SRC ${linker_script_SRC}
{{sr:linker_script_SRC}}
)
set(linker_script_SRC ${linker_script_SRC}{{sr:linker_script_SRC}})

# Sources
set(sources_SRCS ${sources_SRCS}
{{sr:sources_SRCS}}
)
set(sources_SRCS ${sources_SRCS}{{sr:sources_SRCS}})

# Include directories
set(include_c_DIRS ${include_c_DIRS}
{{sr:include_c_DIRS}}
)
set(include_cxx_DIRS ${include_cxx_DIRS}
{{sr:include_cxx_DIRS}}
)
set(include_asm_DIRS ${include_asm_DIRS}
{{sr:include_asm_DIRS}}
)
set(include_c_DIRS ${include_c_DIRS}{{sr:include_c_DIRS}})
set(include_cxx_DIRS ${include_cxx_DIRS}{{sr:include_cxx_DIRS}})
set(include_asm_DIRS ${include_asm_DIRS}{{sr:include_asm_DIRS}})

# Symbols definition
set(symbols_c_SYMB ${symbols_c_SYMB}
{{sr:symbols_c_SYMB}}
)
set(symbols_cxx_SYMB ${symbols_cxx_SYMB}
{{sr:symbols_cxx_SYMB}}
)
set(symbols_asm_SYMB ${symbols_asm_SYMB}
{{sr:symbols_asm_SYMB}}
)
set(symbols_c_SYMB ${symbols_c_SYMB}{{sr:symbols_c_SYMB}})
set(symbols_cxx_SYMB ${symbols_cxx_SYMB}{{sr:symbols_cxx_SYMB}})
set(symbols_asm_SYMB ${symbols_asm_SYMB}{{sr:symbols_asm_SYMB}})

# Link directories
set(link_DIRS ${link_DIRS}
{{sr:link_DIRS}}
)
set(link_DIRS ${link_DIRS}{{sr:link_DIRS}})

# Link libraries
set(link_LIBS ${link_LIBS}
{{sr:link_LIBS}}
)
set(link_LIBS ${link_LIBS}{{sr:link_LIBS}})

# Compiler options
set(compiler_OPTS ${compiler_OPTS})
Expand Down

0 comments on commit 70d41bd

Please sign in to comment.