diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 4e2ac07..e7b5c40 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -5,55 +5,13 @@ "type": "shell", "label": "Run converter", "command": "python", - "args": ["converter.py", + "args": ["converter.py", "-f", "--path", //Repository projects "cube-ide-cmake-demo-proj", "script-projects/h735g-dk-usart/", "script-projects/h735g-dk-touchgfx/", - "script-projects/h735g-dk-touchgfx/", - - //Other dvp projects - "../lwesp/examples/stm32/mqtt_client_api_rtos_stm32f429zi_nucleo/", - "../lwesp/examples/stm32/netconn_client_rtos_stm32l496g_discovery/", - "../lwgsm/examples/stm32/mqtt_client_api_rtos_stm32f429zi_nucleo/", - "../lwgsm/examples/stm32/netconn_client_rtos_stm32f429zi_nucleo/", - "../lwgsm/examples/stm32/sms_send_receive_rtos_stm32f429zi_nucleo/", - "../lwgsm/examples/stm32/sms_send_receive_thread_rtos_stm32f429zi_nucleo/", - "../lwmem/examples/stm32/lwmem_rtos_stm32l496_discovery/", - "../lwmem/examples/stm32/lwmem_stm32l496_discovery/", - "../lwow/examples/stm32/ow_ds18b20_multi_rtos_stm32f429zi_nucleo/", - "../lwow/examples/stm32/ow_ds18b20_rtos_stm32f401re_nucleo/", - "../lwow/examples/stm32/ow_ds18b20_rtos_stm32f429zi_nucleo/", - "../lwow/examples/stm32/ow_ds18b20_rtos_stm32l496g_discovery/", - "../lwow/examples/stm32/ow_ds18b20_stm32l496g_discovery/", - "../lwprintf/examples/stm32/lwprintf_stm32l432kc_nucleo/", - - "../stm32-usart-dma-rx-tx/projects/usart_rx_idle_line_irq_F1/", - "../stm32-usart-dma-rx-tx/projects/usart_rx_idle_line_irq_F4/", - "../stm32-usart-dma-rx-tx/projects/usart_rx_idle_line_irq_G0/", - "../stm32-usart-dma-rx-tx/projects/usart_rx_idle_line_irq_L4/", - "../stm32-usart-dma-rx-tx/projects/usart_rx_idle_line_irq_ringbuff_G0/", - "../stm32-usart-dma-rx-tx/projects/usart_rx_idle_line_irq_ringbuff_tx_G0/", - "../stm32-usart-dma-rx-tx/projects/usart_rx_idle_line_irq_ringbuff_tx_H7/", - "../stm32-usart-dma-rx-tx/projects/usart_rx_idle_line_irq_ringbuff_tx_loopback_G4/", - "../stm32-usart-dma-rx-tx/projects/usart_rx_idle_line_irq_ringbuff_tx_loopback_U5/", - "../stm32-usart-dma-rx-tx/projects/usart_rx_idle_line_irq_rtos_F4/", - "../stm32-usart-dma-rx-tx/projects/usart_rx_idle_line_irq_rtos_G4/", - "../stm32-usart-dma-rx-tx/projects/usart_rx_idle_line_irq_rtos_L4/", - "../stm32-usart-dma-rx-tx/projects/usart_rx_idle_line_irq_rtos_L4_multi_instance/", - "../stm32-usart-dma-rx-tx/projects/usart_rx_idle_line_irq_stop_mode_G4/", - "../stm32-usart-dma-rx-tx/projects/usart_rx_polling_F4/", - "../stm32-usart-dma-rx-tx/projects/usart_rx_polling_rtos_F4/", - "../stm32-usart-dma-rx-tx/projects/usart_tx_debug_rtos_F4/", - - "../CanOpenSTM32/stm32h7xx_fdcan/", - "../CanOpenSTM32/stm32h7xx_fdcan_rtos/", - - "../stm32-ws2811-ws2812-ws2812b-ws281x-tim-pwm-dma-timer/projects/stm32g0b1_nucleo/", - - //"d:/_WORK/projects/smart-house/modules/unit_control_h735/" ], "options": { "cwd": "${workspaceFolder}" @@ -61,4 +19,4 @@ "problemMatcher": [] }, ] -}// \ No newline at end of file +} \ No newline at end of file diff --git a/converter.py b/converter.py index 4e8878c..89a2ff5 100644 --- a/converter.py +++ b/converter.py @@ -7,18 +7,33 @@ import argparse import pathlib import shutil +import traceback NEWLINE_INDENTED = '\n ' + +def get_parser(): + parser = argparse.ArgumentParser( + description='Generate CMakeLists.txt from STM32CubeIDE project path') + parser.add_argument('--path', nargs='+', type=pathlib.Path, + required=True, help='STM32CubeIDE root project folder location') + parser.add_argument('-f', action='store_true', + help='Forces script to rebuild all files (including user)') + + return parser + # # Copy tree of data # -def copytree(src, dst, symlinks=False, ignore=None): + + +def copytree(src, dst, symlinks=False, ignore=None, dirs_exist_ok=True): for item in os.listdir(src): s = os.path.join(src, item) d = os.path.join(dst, item) if os.path.isdir(s): - shutil.copytree(s, d, symlinks, ignore) + shutil.copytree(s, d, symlinks, ignore, + dirs_exist_ok=dirs_exist_ok) else: shutil.copy2(s, d) @@ -27,596 +42,683 @@ def copytree(src, dst, symlinks=False, ignore=None): # # Useful for fast search in the tree, usually by ID # + + def normalize_xml_tree(treeRoot): - normalized = [{"tag": treeRoot.tag, "attr": treeRoot.attrib, "obj": treeRoot}] - for entry in treeRoot: - normalized = normalized + normalize_xml_tree(entry) - return normalized + normalized = [{"tag": treeRoot.tag, + "attr": treeRoot.attrib, "obj": treeRoot}] + for entry in treeRoot: + normalized = normalized + normalize_xml_tree(entry) + return normalized # # Creates path relative to CMakeLists.txt base path # And adds (optionally) CMake prefix # -def gen_relative_path_to_cmake_folder(cmakefolder, path, add_prefix = True, replace_ds = True): - try: - path = os.path.relpath(path, cmakefolder) - if add_prefix: - path = '${PROJ_PATH}/' + path - except ValueError: - print("Value Error triggered") - print("CmakeFolder:", cmakefolder) - print("Input path: ", path) - path = path.replace(cmakefolder, '') - if replace_ds: - path = path.replace('\\', '/') - return path + + +def gen_relative_path_to_cmake_folder(cmakefolder, path, add_prefix=True, replace_ds=True): + try: + path = os.path.relpath(path, cmakefolder) + if add_prefix: + path = '${CMAKE_CURRENT_SOURCE_DIR}/' + path + except ValueError: + print("Value Error triggered") + print("CmakeFolder:", cmakefolder) + print("Input path: ", path) + path = path.replace(cmakefolder, '') + if replace_ds: + path = path.replace('\\', '/') + return path # # Main function to parse and generate CMakeLists.txt file # -def parse_and_generate(projectFolderBasePath): - print("--------") - print("Configuring project with base path:", projectFolderBasePath) - - # Source files to process - proj_files = [ - os.path.join(projectFolderBasePath, "STM32CubeIDE/.project"), - os.path.join(projectFolderBasePath, ".project") - ] - cproj_files = [ - os.path.join(projectFolderBasePath, "STM32CubeIDE/.cproject"), - os.path.join(projectFolderBasePath, ".cproject") - ] - - # Glob for all source and header files - data_obj = { - 'project_name': '', - 'configurations': { - 'debug': { - 'target_mcu': '', - 'source_folders': [], - 'fpu': '', - 'float_abi': '', - 'c': { - 'symbols': [], - 'include_paths': [], - 'libraries': [], - 'library_directories': [], - 'debug_level': '', - 'optimization_level': '', - 'other_flags': [], - 'linker_script': '', - }, - 'cxx': { - 'symbols': [], - 'include_paths': [], - 'libraries': [], - 'library_directories': [], - 'debug_level': '', - 'optimization_level': '', - 'other_flags': [], - 'linker_script': '', - }, - 'asm': { - 'symbols': [], - 'include_paths': [], - 'libraries': [], - 'library_directories': [], - 'debug_level': '', - 'optimization_level': '', - 'other_flags': [], - 'linker_script': '', - }, - 'libraries': [], - 'library_directories': [], - 'source_folders': [], - }, - 'release': { - 'target_mcu': '', - 'source_folders': [], - 'fpu': '', - 'float_abi': '', - 'c': { - 'symbols': [], - 'include_paths': [], - 'libraries': [], - 'library_directories': [], - 'debug_level': '', - 'optimization_level': '', - 'other_flags': [], - 'linker_script': '', - }, - 'cxx': { - 'symbols': [], - 'include_paths': [], - 'libraries': [], - 'library_directories': [], - 'debug_level': '', - 'optimization_level': '', - 'other_flags': [], - 'linker_script': '', + + +def parse_and_generate(projectFolderBasePath, args): + print("--------") + print("Configuring project with base path:", projectFolderBasePath) + + # Source files to process + proj_files = [ + os.path.join(projectFolderBasePath, "STM32CubeIDE/.project"), + os.path.join(projectFolderBasePath, ".project") + ] + cproj_files = [ + os.path.join(projectFolderBasePath, "STM32CubeIDE/.cproject"), + os.path.join(projectFolderBasePath, ".cproject") + ] + + # Glob for all source and header files + data_obj = { + 'project_name': '', + 'confs': { + 'debug': { + 'target_mcu': '', + 'source_folders': [], + 'fpu': '', + 'float_abi': '', + 'c': { + 'symbols': [], + 'incl_paths': [], + 'libs': [], + 'libs_dirs': [], + 'ddbg_lvl': '', + 'optim_lvl': '', + 'other_flags': [], + 'linker_script': '', + }, + 'cxx': { + 'symbols': [], + 'incl_paths': [], + 'libs': [], + 'libs_dirs': [], + 'ddbg_lvl': '', + 'optim_lvl': '', + 'other_flags': [], + 'linker_script': '', + }, + 'asm': { + 'symbols': [], + 'incl_paths': [], + 'libs': [], + 'libs_dirs': [], + 'ddbg_lvl': '', + 'optim_lvl': '', + 'other_flags': [], + 'linker_script': '', + }, + 'libs': [], + 'libs_dirs': [], + 'source_folders': [], }, - 'asm': { - 'symbols': [], - 'include_paths': [], - 'libraries': [], - 'library_directories': [], - 'debug_level': '', - 'optimization_level': '', - 'other_flags': [], - 'linker_script': '', + 'release': { + 'target_mcu': '', + 'source_folders': [], + 'fpu': '', + 'float_abi': '', + 'c': { + 'symbols': [], + 'incl_paths': [], + 'libs': [], + 'libs_dirs': [], + 'ddbg_lvl': '', + 'optim_lvl': '', + 'other_flags': [], + 'linker_script': '', + }, + 'cxx': { + 'symbols': [], + 'incl_paths': [], + 'libs': [], + 'libs_dirs': [], + 'ddbg_lvl': '', + 'optim_lvl': '', + 'other_flags': [], + 'linker_script': '', + }, + 'asm': { + 'symbols': [], + 'incl_paths': [], + 'libs': [], + 'libs_dirs': [], + 'ddbg_lvl': '', + 'optim_lvl': '', + 'other_flags': [], + 'linker_script': '', + }, + 'libs': [], + 'libs_dirs': [], + 'source_folders': [], }, - 'libraries': [], - 'library_directories': [], - 'source_folders': [], - }, - }, - 'linked_files': {}, - 'all_source_files_in_path': [] - } - - # Parse XML files - cproj_parsed = False - proj_parsed = False - for f in cproj_files: - try: - fTreeCproj = ET.parse(f) - - # Set base folder of .cproject and .project - CProjBasePath = os.path.dirname(f) - - # Get path difference between where CMakelists.txt file will be placed (project directory) - # versus where originally .cproject/.project file is located - CProjBasePath_ProjectBasePath_diff = CProjBasePath.replace(os.path.join(projectFolderBasePath, ''), '') - cproj_parsed = True - break - except: - pass - for f in proj_files: - try: - fTreeProj = ET.parse(f) - proj_parsed = True - break - except: - pass - if not cproj_parsed or not proj_parsed: - print(".cproject or .project not found or could not be parsed. Exiting the parse process") - print("--------") - return - print(".cproject or .project files parsed") - - # Print values to user - print("Project top folder path: ", projectFolderBasePath) - print("Project .cproject and .project basepath: ", CProjBasePath) - print("Project base vs .c/.cproj difference path:", CProjBasePath_ProjectBasePath_diff) - - # - # We can normalize tree to one array once we are inside one configuration. - # Every feature has a "superClass" tag, that can be used for identification purpose - # - print("Processing .cproject file") - fTreeRootCproj = fTreeCproj.getroot() - fTreeCprojNormalized = normalize_xml_tree(fTreeRootCproj) - for tEntry in fTreeCprojNormalized: - # - # We want to parse debug configuration only for the moment - # - if tEntry['tag'] == 'cconfiguration' and 'id' in tEntry['attr'] and 'com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.debug' in tEntry['attr']['id']: - conf_key = 'debug' - - # Get all entries, normalized for specific configuration mode - all_sub_entries = normalize_xml_tree(tEntry['obj']) - for entry in all_sub_entries: - if 'superClass' in entry['attr']: - # Get target MCU - if entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_mcu' and 'value' in entry['attr']: - data_obj['configurations'][conf_key]['target_mcu'] = entry['attr']['value'] - - # FPU settings - if entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.option.floatabi' and 'value' in entry['attr']: - data_obj['configurations'][conf_key]['float_abi'] = entry['attr']['value'].replace('com.st.stm32cube.ide.mcu.gnu.managedbuild.option.floatabi.value.', '') - if entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.option.fpu' and 'value' in entry['attr']: - data_obj['configurations'][conf_key]['fpu'] = entry['attr']['value'].replace('com.st.stm32cube.ide.mcu.gnu.managedbuild.option.fpu.value.', '') - - # - # MCU GCC Assembler options - # - if entry['tag'] == 'tool' and entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler': - continue - if entry['tag'] == 'option' and entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler.compiler': - continue - if entry['tag'] == 'option' and entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler.option.definedsymbols': - # List all symbols for compiler - for listOptionValue in entry["obj"]: - data_obj['configurations'][conf_key]['asm']['symbols'].append(listOptionValue.attrib['value']) - continue - if entry['tag'] == 'option' and entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler.option.includepaths': - # List all include paths for compiler - for listOptionValue in entry["obj"]: - data_obj['configurations'][conf_key]['asm']['include_paths'].append(listOptionValue.attrib['value']) - continue - if entry['tag'] == 'option' and entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler.option.debuglevel' and 'value' in entry['attr']: - data_obj['configurations'][conf_key]['asm']['debug_level'] = entry['attr']['value'].replace('com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler.option.debuglevel.value.', '') - continue - if entry['tag'] == 'option' and entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler.option.optimization.level' and 'value' in entry['attr']: - data_obj['configurations'][conf_key]['asm']['optimization_level'] = entry['attr']['value'].replace('com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler.option.optimization.level.value.', '') - continue - if entry['tag'] == 'option' and entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler.option.otherflags': - for listOptionValue in entry["obj"]: - data_obj['configurations'][conf_key]['asm']['other_flags'].append(listOptionValue.attrib['value']) - continue - - # - # MCU C Compiler options - # - if entry['tag'] == 'tool' and entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler': - continue - if entry['tag'] == 'option' and entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.definedsymbols': - # List all symbols for compiler - for listOptionValue in entry["obj"]: - data_obj['configurations'][conf_key]['c']['symbols'].append(listOptionValue.attrib['value']) - continue - if entry['tag'] == 'option' and entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.includepaths': - # List all include paths for compiler - for listOptionValue in entry["obj"]: - data_obj['configurations'][conf_key]['c']['include_paths'].append(listOptionValue.attrib['value']) - continue - if entry['tag'] == 'option' and entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.debuglevel': - data_obj['configurations'][conf_key]['c']['debug_level'] = entry['attr']['value'].replace('com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.debuglevel.value.', '') - continue - if entry['tag'] == 'option' and entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.optimization.level' and 'value' in entry['attr']: - data_obj['configurations'][conf_key]['c']['optimization_level'] = entry['attr']['value'].replace('com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.optimization.level.value.', '') - continue - if entry['tag'] == 'option' and entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.otherflags' and 'value' in entry['attr']: - for listOptionValue in entry["obj"]: - data_obj['configurations'][conf_key]['c']['other_flags'].append(listOptionValue.attrib['value']) - continue - - # - # MCU CXX Compiler options - # - if entry['tag'] == 'tool' and entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler': - continue - if entry['tag'] == 'option' and entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler.option.definedsymbols': - # List all symbols for compiler - for listOptionValue in entry["obj"]: - data_obj['configurations'][conf_key]['cxx']['symbols'].append(listOptionValue.attrib['value']) - continue - if entry['tag'] == 'option' and entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler.option.includepaths': - # List all include paths for compiler - for listOptionValue in entry["obj"]: - data_obj['configurations'][conf_key]['cxx']['include_paths'].append(listOptionValue.attrib['value']) - continue - if entry['tag'] == 'tool' and entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.linker': - continue - if entry['tag'] == 'option' and entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler.option.debuglevel' and 'value' in entry['attr']: - data_obj['configurations'][conf_key]['cxx']['debug_level'] = entry['attr']['value'].replace('com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler.option.debuglevel.value.', '') - continue - if entry['tag'] == 'option' and entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler.option.optimization.level' and 'value' in entry['attr']: - data_obj['configurations'][conf_key]['cxx']['optimization_level'] = entry['attr']['value'].replace('com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler.option.optimization.level.value.', '') - continue - if entry['tag'] == 'option' and entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler.option.otherflags': - for listOptionValue in entry["obj"]: - data_obj['configurations'][conf_key]['cxx']['other_flags'].append(listOptionValue.attrib['value']) - continue - - # - # MCU GCC Linker - # - if entry['tag'] == 'option' and entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.script' and 'value' in entry['attr']: - data_obj['configurations'][conf_key]['c']['linker_script'] = entry['attr']['value'] - continue - if entry['tag'] == 'option' and entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.libraries': - # List all external libraries for CXX compiler - for listOptionValue in entry["obj"]: - data_obj['configurations'][conf_key]['c']['libraries'].append(listOptionValue.attrib['value']) - data_obj['configurations'][conf_key]['libraries'].append(listOptionValue.attrib['value']) - continue - if entry['tag'] == 'option' and entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.directories': - # List all external library directories - for listOptionValue in entry["obj"]: - data_obj['configurations'][conf_key]['c']['library_directories'].append(listOptionValue.attrib['value']) - data_obj['configurations'][conf_key]['library_directories'].append(listOptionValue.attrib['value']) - continue - - # - # MCU GXX Linker - # - if entry['tag'] == 'option' and entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.linker.option.script' and 'value' in entry['attr']: - data_obj['configurations'][conf_key]['cxx']['linker_script'] = entry['attr']['value'] - continue - if entry['tag'] == 'option' and entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.linker.option.libraries': - # List all external libraries for CXX compiler - for listOptionValue in entry["obj"]: - data_obj['configurations'][conf_key]['cxx']['libraries'].append(listOptionValue.attrib['value']) - data_obj['configurations'][conf_key]['libraries'].append(listOptionValue.attrib['value']) - continue - if entry['tag'] == 'option' and entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.linker.option.directories': - # List all external library directories - for listOptionValue in entry["obj"]: - data_obj['configurations'][conf_key]['cxx']['library_directories'].append(listOptionValue.attrib['value']) - data_obj['configurations'][conf_key]['library_directories'].append(listOptionValue.attrib['value']) - continue - - # Check for source folders - # Very experimental -> needs stronger checks - elif entry['tag'] == "sourceEntries": - for folderEntry in entry['obj']: - if 'name' in folderEntry.attrib and folderEntry.attrib['name'] != '': - name = folderEntry.attrib['name'] - files = [] - files = files + glob.glob(os.path.join(CProjBasePath, name, '**/*.c'), recursive = True) - files = files + glob.glob(os.path.join(CProjBasePath, name, '**/*.cpp'), recursive = True) - files = files + glob.glob(os.path.join(CProjBasePath, name, '**/*.s'), recursive = True) - data_obj['configurations'][conf_key]['source_folders'].append({'name': name, 'files': files}) - - # Stop executing after first "debug" config - break - - # - # Handle .project file - # - print("Processing .project file") - fTreeRootProj = fTreeProj.getroot() - fTreeRootProjNormalized = normalize_xml_tree(fTreeRootProj) - for treeEntry in fTreeRootProjNormalized: - # Check project description - if treeEntry['tag'] == 'projectDescription': - for descEntry in treeEntry['obj']: - if descEntry.tag == 'name': - data_obj['project_name'] = descEntry.text - - # Check for linked resources - if treeEntry['tag'] == 'linkedResources': - # List all links in the chain - for linkEntry in treeEntry['obj']: - path = '' - virtual_folder = '' - for linkEntryTag in linkEntry: - if linkEntryTag.tag == 'locationURI': - path = linkEntryTag.text.replace('$%7B', '').replace('%7D', '').replace('$%7', '') - prog = re.compile('PARENT-([0-9]+)-PROJECT_LOC') - result = prog.search(path) - if result: - # Add "folder-up" prefix number of times, linked to matched number - # Then replace "PARENT-xxx-PROJECT_LOC/" with white-space - path = ('../' * int(result.group(1))) + path.replace(result.group(0) + '/', '') - - # Create full path - path = os.path.normpath(os.path.join(CProjBasePath, path)) - elif linkEntryTag.tag == 'name': - # Get virtual folder to group files together - virtual_folder = os.path.dirname(linkEntryTag.text).replace('/', '_').replace('\\', '_').replace('-', '_').lower() - if path != '': - if virtual_folder not in data_obj['linked_files']: - data_obj['linked_files'][virtual_folder] = [] - data_obj['linked_files'][virtual_folder].append(path) - - # - # Group linked files and source folders together to one merge - # - # From now on, work only with linked files across application - # - for conf in ['debug']: - for sourceGroup in data_obj['configurations'][conf]['source_folders']: - files = sourceGroup['files'] - for f in files: - folder_name = os.path.dirname(f.replace(os.path.join(CProjBasePath, ''), '')).replace('/', '_').replace('\\', '_').replace('-', '_').lower() - if folder_name not in data_obj['linked_files']: - data_obj['linked_files'][folder_name] = [] - if f not in data_obj['linked_files'][folder_name]: - data_obj['linked_files'][folder_name].append(f) - - # - # Glob for files in the same directory as .project and .cproject - # These are automatically added to the project, even if not specifically mentioned in project config - # - files_scan = [] - files_scan = files_scan + glob.glob(os.path.join(CProjBasePath, "**/*.c"), recursive = True) - files_scan = files_scan + glob.glob(os.path.join(CProjBasePath, "**/*.cpp"), recursive = True) - files_scan = files_scan + glob.glob(os.path.join(CProjBasePath, "**/*.s"), recursive = True) - files_scan = [os.path.join(CProjBasePath, f) for f in files_scan] - - # Remove files from build directory - for f in files_scan: - # Remove build folder - if os.path.join(projectFolderBasePath, 'build') in f: - continue - # Get folder name between .cproject location and actual file location (create virtual folder for variable) - folder_name = os.path.dirname(f.replace(os.path.join(CProjBasePath, ''), '')).replace('/', '_').replace('\\', '_').replace('-', '_').lower() - if folder_name not in data_obj['linked_files']: - data_obj['linked_files'][folder_name] = [] - if f not in data_obj['linked_files'][folder_name]: - data_obj['linked_files'][folder_name].append(f) - - ## - # TODO: Ignore any .c file from "/build/" directory - # This is ninja build system - # - - # Read template file - print("Opening templates/CMakeLists_template.txt file") - templatefiledata = '' - with open("templates/CMakeLists_template.txt", "r") as file: - templatefiledata = file.read() - - # Set project name - project_name = data_obj['project_name'] - if len(project_name) == 0: - project_name = 'unknown' - templatefiledata = templatefiledata.replace('{{sr:project_name}}', project_name) - - # Set MCU specifics - for conf in ['debug']: - cpu_params = [] - - # Set Cortex - target_mcu = data_obj['configurations'][conf]['target_mcu'][0:7].upper() - if len(target_mcu) < 7: - print("Target_MCU len is less than 7 characters. Not enough to determine STM32 Cortex-M CPU") - continue - target_mcu = target_mcu[0:7].upper() - if target_mcu in ['STM32F0']: - target_cpu = '-mcpu=cortex-m0' - elif target_mcu in ['STM32L0', 'STM32G0', 'STM32C0']: - target_cpu = '-mcpu=cortex-m0plus' - elif target_mcu in ['STM32F1', 'STM32F2', 'STM32L1']: - target_cpu = '-mcpu=cortex-m3' - elif target_mcu in ['STM32F3', 'STM32F4', 'STM32L4', 'STM32G4', 'STM32WB', 'STM32WL']: - target_cpu = '-mcpu=cortex-m4' - elif target_mcu in ['STM32L5', 'STM32U5', 'STM32H5']: - target_cpu = '-mcpu=cortex-m33' - elif target_mcu in ['STM32F7', 'STM32H7']: - target_cpu = '-mcpu=cortex-m7' - else: - print("Unknown STM32") - return - cpu_params.append(target_cpu) - - # Set floating point - target_fpu = data_obj['configurations'][conf]['fpu'] - if target_fpu == 'none' or target_fpu == 'None': - target_fpu = '' - elif len(target_fpu) > 0: - target_fpu = '-mfpu=' + target_fpu - cpu_params.append(target_fpu) - - # Set floating point API - target_fpu_abi = data_obj['configurations'][conf]['float_abi'] - if len(target_fpu_abi) > 0: - target_fpu_abi = '-mfloat-abi=' + target_fpu_abi - cpu_params.append(target_fpu_abi) - - # Make replacements - templatefiledata = templatefiledata.replace('{{sr:cpu_params}}', NEWLINE_INDENTED.join(cpu_params)) - - # - # Process all linked files, grouped by "directory name" - # - cmake_set_strings_list = [] - cmake_variables_list = [] - for name in data_obj['linked_files']: - var_name = 'src_' + name + '_SRCS' # Set variable name - files = data_obj['linked_files'][name] # List of files part of the set command - - # This will generate list of files part of set command in readable format - files_text = NEWLINE_INDENTED + NEWLINE_INDENTED.join([gen_relative_path_to_cmake_folder(projectFolderBasePath, f) for f in files]) - - # Add set command with generated files text - cmake_set_strings_list.append('set(' + var_name + ' ' + files_text + ')') - - # Add list of variables - cmake_variables_list.append('${' + var_name + '}') - - # Replace template file with data - templatefiledata = templatefiledata.replace('{{sr:set_source_folder_files}}', '\n\n'.join(cmake_set_strings_list)) - templatefiledata = templatefiledata.replace('{{sr:set_source_folder_files_variables}}', NEWLINE_INDENTED + NEWLINE_INDENTED.join(cmake_variables_list)) - - # Check all files in the same directory as .cproject/.project directory - templatefiledata = templatefiledata.replace( - '{{sr:all_project_dir_SRCS}}', - NEWLINE_INDENTED.join([gen_relative_path_to_cmake_folder(projectFolderBasePath, p) for p in data_obj['all_source_files_in_path']]) - ) - - # - # Check include paths - # Split between each of the compiler types - # - for conf in ['debug']: - for compiler in ['c', 'cxx', 'asm']: - varname = 'include_' + compiler + '_DIRS' - paths = [] - for path in data_obj['configurations'][conf][compiler]['include_paths']: - path = path.replace('${ProjDirPath}', CProjBasePath) - if not os.path.isabs(path): - # We are here adding "Debug" fake name (for relativep paths only) - # because "cwd" path for CubeIDE is "/Debug" - path = os.path.join(os.path.join(CProjBasePath, 'Debug'), path) - - # Normalize path to remove "Debug" from path - paths.append(os.path.normpath(path)) - templatefiledata = templatefiledata.replace('{{sr:' + varname + '}}', NEWLINE_INDENTED.join([gen_relative_path_to_cmake_folder(projectFolderBasePath, p) for p in paths])) - - # - # Check all symbols (global defines) - # Split between each of the compiler types - # - for conf in ['debug']: - for compiler in ['c', 'cxx', 'asm']: - varname = 'symbols_' + compiler + '_SYMB' - templatefiledata = templatefiledata.replace('{{sr:' + varname + '}}', NEWLINE_INDENTED.join(["\"" + f + "\"" for f in data_obj['configurations'][conf][compiler]['symbols']])) - - # - # Setup linked libraries - # - for conf in ['debug']: - libs = data_obj['configurations'][conf]['libraries'] - paths = data_obj['configurations'][conf]['library_directories'] - for i in range(len(paths)): - # Do some optimizations with path if necessary - pass - 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)) - - # - # Setup linker script - # - for conf in ['debug']: - var_replace_name = '{{sr:linker_script_SRC}}' - for l in ['c', 'cxx']: - linker_file_orig = data_obj['configurations'][conf][l]['linker_script'] - if linker_file_orig != '': + }, + 'linked_files': {}, + 'all_source_files_in_path': [] + } + + # Parse XML files + cproj_parsed = False + proj_parsed = False + for f in cproj_files: + try: + fTreeCproj = ET.parse(f) + + # Set base folder of .cproject and .project + CProjBasePath = os.path.dirname(f) + + # Get path difference between where CMakelists.txt file will be placed (project directory) + # versus where originally .cproject/.project file is located + CProjBasePath_ProjectBasePath_diff = CProjBasePath.replace( + os.path.join(projectFolderBasePath, ''), '') + cproj_parsed = True + break + except: + pass + for f in proj_files: + try: + fTreeProj = ET.parse(f) + proj_parsed = True + break + except: + pass + if not cproj_parsed or not proj_parsed: + print(".cproject or .project not found or could not be parsed. Exiting the parse process") + print("--------") + return + print(".cproject or .project files parsed") + + # Print values to user + print("Project top folder path: ", projectFolderBasePath) + print("Project .cproject and .project basepath: ", CProjBasePath) + print("Project base vs .c/.cproj difference path:", + CProjBasePath_ProjectBasePath_diff) + + # + # We can normalize tree to one array once we are inside one configuration. + # Every feature has a "superClass" tag, that can be used for identification purpose + # + print("Processing .cproject file") + fTreeRootCproj = fTreeCproj.getroot() + fTreeCprojNormalized = normalize_xml_tree(fTreeRootCproj) + for tEntry in fTreeCprojNormalized: + # + # We want to parse debug configuration only for the moment + # + if tEntry['tag'] == 'cconfiguration' and 'id' in tEntry['attr'] and 'com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.debug' in tEntry['attr']['id']: + conf_key = 'debug' + + # Get all entries, normalized for specific configuration mode + all_sub_entries = normalize_xml_tree(tEntry['obj']) + for entry in all_sub_entries: + if 'superClass' in entry['attr']: + # Get target MCU + if entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_mcu' and 'value' in entry['attr']: + data_obj['confs'][conf_key]['target_mcu'] = entry['attr']['value'] + + # FPU settings + if entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.option.floatabi' and 'value' in entry['attr']: + data_obj['confs'][conf_key]['float_abi'] = entry['attr']['value'].replace( + 'com.st.stm32cube.ide.mcu.gnu.managedbuild.option.floatabi.value.', '') + if entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.option.fpu' and 'value' in entry['attr']: + data_obj['confs'][conf_key]['fpu'] = entry['attr']['value'].replace( + 'com.st.stm32cube.ide.mcu.gnu.managedbuild.option.fpu.value.', '') + + # + # MCU GCC Assembler options + # + if entry['tag'] == 'tool' and entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler': + continue + if entry['tag'] == 'option' and entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler.compiler': + continue + if entry['tag'] == 'option' and entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler.option.definedsymbols': + # List all symbols for compiler + for listOptionValue in entry["obj"]: + data_obj['confs'][conf_key]['asm']['symbols'].append( + listOptionValue.attrib['value']) + continue + if entry['tag'] == 'option' and entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler.option.includepaths': + # List all include paths for compiler + for listOptionValue in entry["obj"]: + data_obj['confs'][conf_key]['asm']['incl_paths'].append( + listOptionValue.attrib['value']) + continue + if entry['tag'] == 'option' and entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler.option.debuglevel' and 'value' in entry['attr']: + data_obj['confs'][conf_key]['asm']['ddbg_lvl'] = entry['attr']['value'].replace( + 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler.option.debuglevel.value.', '') + continue + if entry['tag'] == 'option' and entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler.option.optimization.level' and 'value' in entry['attr']: + data_obj['confs'][conf_key]['asm']['optim_lvl'] = entry['attr']['value'].replace( + 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler.option.optimization.level.value.', '') + continue + if entry['tag'] == 'option' and entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler.option.otherflags': + for listOptionValue in entry["obj"]: + data_obj['confs'][conf_key]['asm']['other_flags'].append( + listOptionValue.attrib['value']) + continue + + # + # MCU C Compiler options + # + if entry['tag'] == 'tool' and entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler': + continue + if entry['tag'] == 'option' and entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.definedsymbols': + # List all symbols for compiler + for listOptionValue in entry["obj"]: + data_obj['confs'][conf_key]['c']['symbols'].append( + listOptionValue.attrib['value']) + continue + if entry['tag'] == 'option' and entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.includepaths': + # List all include paths for compiler + for listOptionValue in entry["obj"]: + data_obj['confs'][conf_key]['c']['incl_paths'].append( + listOptionValue.attrib['value']) + continue + if entry['tag'] == 'option' and entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.debuglevel': + data_obj['confs'][conf_key]['c']['ddbg_lvl'] = entry['attr']['value'].replace( + 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.debuglevel.value.', '') + continue + if entry['tag'] == 'option' and entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.optimization.level' and 'value' in entry['attr']: + data_obj['confs'][conf_key]['c']['optim_lvl'] = entry['attr']['value'].replace( + 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.optimization.level.value.', '') + continue + if entry['tag'] == 'option' and entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.otherflags' and 'value' in entry['attr']: + for listOptionValue in entry["obj"]: + data_obj['confs'][conf_key]['c']['other_flags'].append( + listOptionValue.attrib['value']) + continue + + # + # MCU CXX Compiler options + # + if entry['tag'] == 'tool' and entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler': + continue + if entry['tag'] == 'option' and entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler.option.definedsymbols': + # List all symbols for compiler + for listOptionValue in entry["obj"]: + data_obj['confs'][conf_key]['cxx']['symbols'].append( + listOptionValue.attrib['value']) + continue + if entry['tag'] == 'option' and entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler.option.includepaths': + # List all include paths for compiler + for listOptionValue in entry["obj"]: + data_obj['confs'][conf_key]['cxx']['incl_paths'].append( + listOptionValue.attrib['value']) + continue + if entry['tag'] == 'tool' and entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.linker': + continue + if entry['tag'] == 'option' and entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler.option.debuglevel' and 'value' in entry['attr']: + data_obj['confs'][conf_key]['cxx']['ddbg_lvl'] = entry['attr']['value'].replace( + 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler.option.debuglevel.value.', '') + continue + if entry['tag'] == 'option' and entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler.option.optimization.level' and 'value' in entry['attr']: + data_obj['confs'][conf_key]['cxx']['optim_lvl'] = entry['attr']['value'].replace( + 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler.option.optimization.level.value.', '') + continue + if entry['tag'] == 'option' and entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler.option.otherflags': + for listOptionValue in entry["obj"]: + data_obj['confs'][conf_key]['cxx']['other_flags'].append( + listOptionValue.attrib['value']) + continue + + # + # MCU GCC Linker + # + if entry['tag'] == 'option' and entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.script' and 'value' in entry['attr']: + data_obj['confs'][conf_key]['c']['linker_script'] = entry['attr']['value'] + continue + if entry['tag'] == 'option' and entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.libraries': + # List all external libraries for CXX compiler + for listOptionValue in entry["obj"]: + data_obj['confs'][conf_key]['c']['libs'].append( + listOptionValue.attrib['value']) + data_obj['confs'][conf_key]['libs'].append( + listOptionValue.attrib['value']) + continue + if entry['tag'] == 'option' and entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.directories': + # List all external library directories + for listOptionValue in entry["obj"]: + data_obj['confs'][conf_key]['c']['libs_dirs'].append( + listOptionValue.attrib['value']) + data_obj['confs'][conf_key]['libs_dirs'].append( + listOptionValue.attrib['value']) + continue + + # + # MCU GXX Linker + # + if entry['tag'] == 'option' and entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.linker.option.script' and 'value' in entry['attr']: + data_obj['confs'][conf_key]['cxx']['linker_script'] = entry['attr']['value'] + continue + if entry['tag'] == 'option' and entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.linker.option.libraries': + # List all external libraries for CXX compiler + for listOptionValue in entry["obj"]: + data_obj['confs'][conf_key]['cxx']['libs'].append( + listOptionValue.attrib['value']) + data_obj['confs'][conf_key]['libs'].append( + listOptionValue.attrib['value']) + continue + if entry['tag'] == 'option' and entry['attr']['superClass'] == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.linker.option.directories': + # List all external library directories + for listOptionValue in entry["obj"]: + data_obj['confs'][conf_key]['cxx']['libs_dirs'].append( + listOptionValue.attrib['value']) + data_obj['confs'][conf_key]['libs_dirs'].append( + listOptionValue.attrib['value']) + continue + + # Check for source folders + # Very experimental -> needs stronger checks + elif entry['tag'] == "sourceEntries": + for folderEntry in entry['obj']: + if 'name' in folderEntry.attrib and folderEntry.attrib['name'] != '': + name = folderEntry.attrib['name'] + files = [] + files = files + \ + glob.glob(os.path.join(CProjBasePath, + name, '**/*.c'), recursive=True) + files = files + \ + glob.glob(os.path.join(CProjBasePath, + name, '**/*.cpp'), recursive=True) + files = files + \ + glob.glob(os.path.join(CProjBasePath, + name, '**/*.s'), recursive=True) + data_obj['confs'][conf_key]['source_folders'].append( + {'name': name, 'files': files}) + + # Stop executing after first "debug" config break - linker_file = linker_file_orig.replace('${workspace_loc:/${ProjName}/', '') - linker_file = linker_file.replace('workspace_loc:', '').replace('', '') - linker_file = linker_file.replace('${ProjName}', '') - linker_file = linker_file.replace('}', '') - if len(linker_file) > 2 and linker_file[0:2] == '..': - # Path starting with "../" is referenced with "Debug" folder from inside '.cproject' folder linker_file = os.path.join('Debug', linker_file) - linker_file = os.path.join('Debug', linker_file) - linker_file = os.path.join(CProjBasePath, linker_file) - # Text format: '${workspace_loc:/${ProjName}/STM32G474RETX_FLASH.ld}' - templatefiledata = templatefiledata.replace(var_replace_name, gen_relative_path_to_cmake_folder(projectFolderBasePath, linker_file)) - - # Print-out JSON dump - #print(json.dumps(data_obj, indent = 4)) - - # Write data to file - cmakelistsfile = os.path.join(projectFolderBasePath, 'CMakeLists.txt') - print("Generating output", cmakelistsfile) - with open(cmakelistsfile, "w") as file: - file.write(templatefiledata) - - # Copy compiler .cmake file to user path - try: - copytree('templates/', os.path.join(projectFolderBasePath, '.')) - os.remove(os.path.join(projectFolderBasePath, 'CMakeLists_template.txt')) - except: - print("Copy exception...") - pass - - # That's it - print("CMakeLists.txt file generated:", cmakelistsfile) - print("Finished") - print("--------") + + # + # Handle .project file + # + print("Processing .project file") + fTreeRootProj = fTreeProj.getroot() + fTreeRootProjNormalized = normalize_xml_tree(fTreeRootProj) + for treeEntry in fTreeRootProjNormalized: + # Check project description + if treeEntry['tag'] == 'projectDescription': + for descEntry in treeEntry['obj']: + if descEntry.tag == 'name': + data_obj['project_name'] = descEntry.text + + # Check for linked resources + if treeEntry['tag'] == 'linkedResources': + # List all links in the chain + for linkEntry in treeEntry['obj']: + path = '' + virtual_folder = '' + for linkEntryTag in linkEntry: + if linkEntryTag.tag == 'locationURI': + path = linkEntryTag.text.replace( + '$%7B', '').replace('%7D', '').replace('$%7', '') + prog = re.compile('PARENT-([0-9]+)-PROJECT_LOC') + result = prog.search(path) + if result: + # Add "folder-up" prefix number of times, linked to matched number + # Then replace "PARENT-xxx-PROJECT_LOC/" with white-space + path = ('../' * int(result.group(1))) + \ + path.replace(result.group(0) + '/', '') + + # Create full path + path = os.path.normpath( + os.path.join(CProjBasePath, path)) + elif linkEntryTag.tag == 'name': + # Get virtual folder to group files together + virtual_folder = os.path.dirname(linkEntryTag.text).replace( + '/', '_').replace('\\', '_').replace('-', '_').lower() + if path != '': + if virtual_folder not in data_obj['linked_files']: + data_obj['linked_files'][virtual_folder] = [] + data_obj['linked_files'][virtual_folder].append(path) + + # + # Group linked files and source folders together to one merge + # + # From now on, work only with linked files across application + # + for conf in ['debug']: + for sourceGroup in data_obj['confs'][conf]['source_folders']: + files = sourceGroup['files'] + for f in files: + folder_name = os.path.dirname(f.replace(os.path.join(CProjBasePath, ''), '')).replace( + '/', '_').replace('\\', '_').replace('-', '_').lower() + if folder_name not in data_obj['linked_files']: + data_obj['linked_files'][folder_name] = [] + if f not in data_obj['linked_files'][folder_name]: + data_obj['linked_files'][folder_name].append(f) + + # + # Glob for files in the same directory as .project and .cproject + # These are automatically added to the project, even if not specifically mentioned in project config + # + files_scan = [] + files_scan = files_scan + \ + glob.glob(os.path.join(CProjBasePath, "**/*.c"), recursive=True) + files_scan = files_scan + \ + glob.glob(os.path.join(CProjBasePath, "**/*.cpp"), recursive=True) + files_scan = files_scan + \ + glob.glob(os.path.join(CProjBasePath, "**/*.s"), recursive=True) + files_scan = [os.path.join(CProjBasePath, f) for f in files_scan] + + # Remove files from build directory + for f in files_scan: + # Remove build folder + if os.path.join(projectFolderBasePath, 'build') in f: + continue + # Get folder name between .cproject location and actual file location (create virtual folder for variable) + folder_name = os.path.dirname(f.replace(os.path.join(CProjBasePath, ''), '')).replace( + '/', '_').replace('\\', '_').replace('-', '_').lower() + if folder_name not in data_obj['linked_files']: + data_obj['linked_files'][folder_name] = [] + if f not in data_obj['linked_files'][folder_name]: + data_obj['linked_files'][folder_name].append(f) + + ## + # TODO: Ignore any .c file from "/build/" directory + # This is ninja build system + # + + # + # Read template file for generated part + # + print("Opening templates/cmake_generated/cmake_generated_template.cmake file") + templatefiledata = '' + with open("templates/cmake_generated/cmake_generated_template.cmake", "r") as file: + templatefiledata = file.read() + + # Set MCU specifics + for conf in ['debug']: + cpu_params = [] + + # Set Cortex + target_mcu = data_obj['confs'][conf]['target_mcu'][0:7].upper() + if len(target_mcu) < 7: + print( + "Target_MCU len is less than 7 characters. Not enough to determine STM32 Cortex-M CPU") + continue + target_mcu = target_mcu[0:7].upper() + if target_mcu in ['STM32F0']: + target_cpu = '-mcpu=cortex-m0' + elif target_mcu in ['STM32L0', 'STM32G0', 'STM32C0']: + target_cpu = '-mcpu=cortex-m0plus' + elif target_mcu in ['STM32F1', 'STM32F2', 'STM32L1']: + target_cpu = '-mcpu=cortex-m3' + elif target_mcu in ['STM32F3', 'STM32F4', 'STM32L4', 'STM32G4', 'STM32WB', 'STM32WL']: + target_cpu = '-mcpu=cortex-m4' + elif target_mcu in ['STM32L5', 'STM32U5']: + target_cpu = '-mcpu=cortex-m33' + elif target_mcu in ['STM32F7', 'STM32H7']: + target_cpu = '-mcpu=cortex-m7' + else: + print("Unknown STM32") + return + cpu_params.append(target_cpu) + + # Set floating point + target_fpu = data_obj['confs'][conf]['fpu'] + if target_fpu == 'none' or target_fpu == 'None': + target_fpu = '' + elif len(target_fpu) > 0: + target_fpu = '-mfpu=' + target_fpu + cpu_params.append(target_fpu) + + # Set floating point API + target_fpu_abi = data_obj['confs'][conf]['float_abi'] + if len(target_fpu_abi) > 0: + target_fpu_abi = '-mfloat-abi=' + target_fpu_abi + cpu_params.append(target_fpu_abi) + + # Make replacements + templatefiledata = templatefiledata.replace( + '{{sr:cpu_params}}', NEWLINE_INDENTED.join(cpu_params)) + + # + # Process all linked files, grouped by "directory name" + # + source_files_paths = [] + for name in data_obj['linked_files']: + # List of files part of the set command + files = data_obj['linked_files'][name] + for f in files: + source_files_paths.append(f) + for p in data_obj['all_source_files_in_path']: + source_files_paths.append(p) + + # 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]) + ) + + # + # Check include paths + # Split between each of the compiler types + # + for conf in ['debug']: + for compiler in ['c', 'cxx', 'asm']: + varname = 'include_' + compiler + '_DIRS' + paths = [] + for path in data_obj['confs'][conf][compiler]['incl_paths']: + path = path.replace('${ProjDirPath}', CProjBasePath) + if not os.path.isabs(path): + # We are here adding "Debug" fake name (for relativep paths only) + # because "cwd" path for CubeIDE is "/Debug" + path = os.path.join(os.path.join( + CProjBasePath, 'Debug'), path) + + # Normalize path to remove "Debug" from path + paths.append(os.path.normpath(path)) + templatefiledata = templatefiledata.replace('{{sr:' + varname + '}}', NEWLINE_INDENTED.join( + [gen_relative_path_to_cmake_folder(projectFolderBasePath, p) for p in paths])) + + # + # Check all symbols (global defines) + # Split between each of the compiler types + # + for conf in ['debug']: + for compiler in ['c', 'cxx', 'asm']: + varname = 'symbols_' + compiler + '_SYMB' + templatefiledata = templatefiledata.replace('{{sr:' + varname + '}}', NEWLINE_INDENTED.join( + ["\"" + f + "\"" for f in data_obj['confs'][conf][compiler]['symbols']])) + + # + # Setup linked libraries + # + for conf in ['debug']: + libs = data_obj['confs'][conf]['libs'] + paths = data_obj['confs'][conf]['libs_dirs'] + for i in range(len(paths)): + # Do some optimizations with path if necessary + pass + 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)) + + # + # Setup linker script + # + for conf in ['debug']: + var_replace_name = '{{sr:linker_script_SRC}}' + for l in ['c', 'cxx']: + linker_file_orig = data_obj['confs'][conf][l]['linker_script'] + if linker_file_orig != '': + break + linker_file = linker_file_orig.replace( + '${workspace_loc:/${ProjName}/', '') + linker_file = linker_file.replace('workspace_loc:', '').replace('', '') + linker_file = linker_file.replace('${ProjName}', '') + linker_file = linker_file.replace('}', '') + if len(linker_file) > 2 and linker_file[0:2] == '..': + # Path starting with "../" is referenced with "Debug" folder from inside '.cproject' folder + linker_file = os.path.join('Debug', linker_file) + linker_file = os.path.join(CProjBasePath, linker_file) + # Text format: '${workspace_loc:/${ProjName}/STM32G474RETX_FLASH.ld}' + templatefiledata = templatefiledata.replace( + var_replace_name, gen_relative_path_to_cmake_folder(projectFolderBasePath, linker_file)) + + # Print-out JSON dump + # print(json.dumps(data_obj, indent = 4)) + + # + # Generated file is now completed + # + # Next step is to write it to user folder + # + cmakelistsfile_generated = os.path.normpath(os.path.join( + projectFolderBasePath, 'cmake_generated/cmake_generated.cmake')) + try: + os.mkdir(os.path.dirname(cmakelistsfile_generated)) + except: + pass + print("Generating output", cmakelistsfile_generated) + with open(cmakelistsfile_generated, "w") as file: + file.write(templatefiledata) + print("generated .cmake file:", cmakelistsfile_generated) + print("test test") + + # + # Check if user's top cmake file exists + # + cmakefilename = os.path.normpath(os.path.join( + projectFolderBasePath, 'CMakeLists.txt')) + if args.f or not os.path.exists(cmakefilename): + # We should create first cmakefile + cmakelistsdata = '' + with open("templates/CMakeLists_template.txt", "r") as file: + cmakelistsdata = file.read() + + # Set project name + project_name = data_obj['project_name'] + if len(project_name) == 0: + project_name = 'unknown' + cmakelistsdata = cmakelistsdata.replace( + '{{sr:project_name}}', project_name) + + # Write data to CMakeLists.txt for user + with open(cmakefilename, "w") as file: + file.write(cmakelistsdata) + print("Generated user CMakeLists.txt file:", cmakefilename) + + # Copy all files to user folder + try: + copytree('templates/', os.path.join(projectFolderBasePath)) + except Exception as e: + traceback.print_exc() + pass + + # Remove remaining files + for f in ['CMakeLists_template.txt', 'cmake_generated/cmake_generated_template.cmake']: + try: + # Remove template file 1 + os.remove(os.path.join(projectFolderBasePath, f)) + except Exception as e: + pass + + # That's it + print("--------") + print("Finished") + print("--------") + ########################################################## # Run script ########################################################## if __name__ == '__main__': - # Define parser structure - parser = argparse.ArgumentParser(description = 'Generate CMakeLists.txt from STM32CubeIDE project path') - parser.add_argument('--path', nargs = '+', type = pathlib.Path, required = True, help = 'STM32CubeIDE root project folder location') - parser.print_help() - args = parser.parse_args() - - # Base path of this fole - basepath = os.path.dirname(os.path.abspath(__file__)) - - # Go through all provided folders - for p in args.path: - path = str(p) - if not os.path.isabs(path): - path = os.path.normpath(os.path.join(basepath, path)) - parse_and_generate(path) + # Define parser structure + parser = get_parser() + parser.print_help() + args = parser.parse_args() + + # Base path of this fole + basepath = os.path.dirname(os.path.abspath(__file__)) + + # Go through all provided folders + for p in args.path: + path = str(p) + if not os.path.isabs(path): + path = os.path.normpath(os.path.join(basepath, path)) + parse_and_generate(path, args) diff --git a/cube-ide-cmake-demo-proj/.vscode/launch.json b/cube-ide-cmake-demo-proj/.vscode/launch.json index 9b3d92d..3f760af 100644 --- a/cube-ide-cmake-demo-proj/.vscode/launch.json +++ b/cube-ide-cmake-demo-proj/.vscode/launch.json @@ -14,7 +14,7 @@ "device": "", //MCU used, ex. "STM32H735IG" "interface": "swd", "serialNumber": "", //Set ST-Link ID if you use multiple at the same time - "runToMain": true, + "runToEntryPoint": "main", "svdFile": "path/to/file.svd", //Path to SVD file to see registers "v1": false, "showDevDebugOutput": "both", diff --git a/cube-ide-cmake-demo-proj/CMakeLists.txt b/cube-ide-cmake-demo-proj/CMakeLists.txt index 1781320..45a3db5 100644 --- a/cube-ide-cmake-demo-proj/CMakeLists.txt +++ b/cube-ide-cmake-demo-proj/CMakeLists.txt @@ -1,188 +1,115 @@ cmake_minimum_required(VERSION 3.22) -message("Entering ${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt") - -# # Core project settings -# -set(PROJ_PATH ${CMAKE_CURRENT_SOURCE_DIR}) project(cube-ide-cmake-demo-proj) enable_language(C CXX ASM) -message("Build type: " ${CMAKE_BUILD_TYPE}) +message("Build type: " ${CMAKE_BUILD_TYPE}) # Setup compiler settings -set(CMAKE_C_STANDARD 11) -set(CMAKE_C_STANDARD_REQUIRED ON) -set(CMAKE_C_EXTENSIONS ON) -set(CMAKE_CXX_STANDARD 20) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_EXTENSIONS ON) - -# -# Core MCU flags, CPU, instruction set and FPU setup -# -set(CPU_PARAMETERS - -mthumb +set(CMAKE_C_STANDARD 11) +set(CMAKE_C_STANDARD_REQUIRED ON) +set(CMAKE_C_EXTENSIONS ON) +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS ON) + +# Core MCU flags, CPU type, instruction set and FPU setup +set(cpu_PARAMS -mthumb + # Other parameters # -mcpu, -mfloat, -mfloat-abi, ... - -mcpu=cortex-m7 - -mfpu=fpv5-d16 - -mfloat-abi=hard ) -# Set linker script -set(linker_script_SRC ${PROJ_PATH}/STM32H735IGKX_FLASH.ld) -set(EXECUTABLE ${CMAKE_PROJECT_NAME}) - -# -# Source files -# -set(src_core_src_SRCS - ${PROJ_PATH}/Core/Src/main.c - ${PROJ_PATH}/Core/Src/stm32h7xx_it.c - ${PROJ_PATH}/Core/Src/syscalls.c - ${PROJ_PATH}/Core/Src/sysmem.c - ${PROJ_PATH}/Core/Src/system_stm32h7xx.c) - -set(src_core_startup_SRCS - ${PROJ_PATH}/Core/Startup/startup_stm32h735igkx.s) - -set(src_drivers_stm32h7xx_hal_driver_src_SRCS - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_exti.c - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_gpio.c - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_pwr.c - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_rcc.c - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_utils.c) - -# -# Include directories -# -set(include_c_DIRS - ${PROJ_PATH}/Core/Inc - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Inc - ${PROJ_PATH}/Drivers/CMSIS/Device/ST/STM32H7xx/Include - ${PROJ_PATH}/Drivers/CMSIS/Include -) -set(include_cxx_DIRS - -) -set(include_asm_DIRS - -) +# Sources +set(sources_SRCS) -# -# Symbols definition -# -set(symbols_c_SYMB - "DEBUG" - "STM32H735xx" - "USE_FULL_LL_DRIVER" - "HSE_VALUE=25000000" - "HSE_STARTUP_TIMEOUT=100" - "LSE_STARTUP_TIMEOUT=5000" - "LSE_VALUE=32768" - "EXTERNAL_CLOCK_VALUE=12288000" - "HSI_VALUE=64000000" - "LSI_VALUE=32000" - "VDD_VALUE=3300" -) -set(symbols_cxx_SYMB - -) -set(symbols_asm_SYMB - "DEBUG" -) +# Include directories for each compiler +set(include_c_DIRS) +set(include_cxx_DIRS) +set(include_asm_DIRS) + +# Symbols definition for each compiler +set(symbols_c_SYMB) +set(symbols_cxx_SYMB) +set(symbols_asm_SYMB) + +# Link directories and names of libraries +set(link_DIRS) +set(link_LIBS) + +# Linker script +set(linker_script_SRC) + +# Compiler options +set(compiler_OPTS) + +# Linker options +set(linker_OPTS) + +# Now call generated cmake +# This will add script generated +# information to the project +include("cmake_generated/cmake_generated.cmake") -# # Link directories setup # Must be before executable is added -# -set(link_DIRS - -) -link_directories(${EXECUTABLE} ${link_DIRS}) - -# -# Executable files -# -add_executable(${EXECUTABLE} - ${src_core_src_SRCS} - ${src_core_startup_SRCS} - ${src_drivers_stm32h7xx_hal_driver_src_SRCS}) - -# -# Add linked libraries for linker -# -set(link_LIBS - -) -target_link_libraries(${EXECUTABLE} ${link_LIBS}) +link_directories(${CMAKE_PROJECT_NAME} ${link_DIRS}) -# -# Project symbols -# -target_compile_definitions(${EXECUTABLE} PRIVATE - # Language specific only - $<$: ${symbols_c_SYMB}> - $<$: ${symbols_cxx_SYMB}> - $<$: ${symbols_asm_SYMB}> +# Create an executable object type +add_executable(${CMAKE_PROJECT_NAME}) - # Configuration specific - $<$: - DEBUG - > - $<$: > -) +# Add sources to executable +target_sources(${CMAKE_PROJECT_NAME} PUBLIC ${sources_SRCS}) -# -# Add include paths for each of the compiler -# -target_include_directories(${EXECUTABLE} PRIVATE - # Language specific only +# Add include paths +target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE $<$: ${include_c_DIRS}> $<$: ${include_cxx_DIRS}> $<$: ${include_asm_DIRS}> +) + +# Add project symbols (macros) +target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE + $<$: ${symbols_c_SYMB}> + $<$: ${symbols_cxx_SYMB}> + $<$: ${symbols_asm_SYMB}> # Configuration specific - $<$: > + $<$:DEBUG> $<$: > ) -# Compiler and linker options -target_compile_options(${EXECUTABLE} PRIVATE - ${CPU_PARAMETERS} +# Add linked libraries +target_link_libraries(${CMAKE_PROJECT_NAME} ${link_LIBS}) + +# Compiler options +target_compile_options(${CMAKE_PROJECT_NAME} PRIVATE + ${cpu_PARAMS} + ${compiler_OPTS} -Wall -Wextra -Wpedantic -Wno-unused-parameter - $<$: - - > + $<$: > $<$: - #-Wno-volatile - #-Wold-style-cast - #-Wuseless-cast - #-Wsuggest-override - > - $<$: - -x assembler-with-cpp - -MMD - -MP - > - $<$: - -Og -g3 -ggdb - > - $<$: - -Og -g0 + + # -Wno-volatile + # -Wold-style-cast + # -Wuseless-cast + # -Wsuggest-override > + $<$:-x assembler-with-cpp -MMD -MP> + $<$:-Og -g3 -ggdb> + $<$:-Og -g0> ) -# Setup linker parameters -target_link_options(${EXECUTABLE} PRIVATE +# Linker options +target_link_options(${CMAKE_PROJECT_NAME} PRIVATE -T${linker_script_SRC} - ${CPU_PARAMETERS} + ${cpu_PARAMS} + ${linker_OPTS} -Wl,-Map=${CMAKE_PROJECT_NAME}.map - -u _printf_float # STDIO float formatting support (remove if not used) + -u _printf_float # STDIO float formatting support (remove if not used) --specs=nosys.specs -Wl,--start-group -lc @@ -190,22 +117,21 @@ target_link_options(${EXECUTABLE} PRIVATE -lstdc++ -lsupc++ -Wl,--end-group + -Wl,-z,max-page-size=8 # Allow good software remapping across address space (with proper GCC section making) -Wl,--print-memory-usage ) # Execute post-build to print size -add_custom_command(TARGET ${EXECUTABLE} POST_BUILD - COMMAND ${CMAKE_SIZE} $ +add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_SIZE} $ ) # Convert output to hex and binary -add_custom_command(TARGET ${EXECUTABLE} POST_BUILD - COMMAND ${CMAKE_OBJCOPY} -O ihex $ ${EXECUTABLE}.hex +add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_OBJCOPY} -O ihex $ ${CMAKE_PROJECT_NAME}.hex ) # Convert to bin file -> add conditional check? -add_custom_command(TARGET ${EXECUTABLE} POST_BUILD - COMMAND ${CMAKE_OBJCOPY} -O binary $ ${EXECUTABLE}.bin +add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_OBJCOPY} -O binary $ ${CMAKE_PROJECT_NAME}.bin ) - -message("Exiting ${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt") diff --git a/cube-ide-cmake-demo-proj/CMakePresets.json b/cube-ide-cmake-demo-proj/CMakePresets.json index 788b377..a86b366 100644 --- a/cube-ide-cmake-demo-proj/CMakePresets.json +++ b/cube-ide-cmake-demo-proj/CMakePresets.json @@ -39,5 +39,23 @@ "CMAKE_BUILD_TYPE": "MinSizeRel" } } + ], + "buildPresets": [ + { + "name": "Debug", + "configurePreset": "Debug" + }, + { + "name": "RelWithDebInfo", + "configurePreset": "RelWithDebInfo" + }, + { + "name": "Release", + "configurePreset": "Release" + }, + { + "name": "MinSizeRel", + "configurePreset": "MinSizeRel" + } ] } \ No newline at end of file diff --git a/cube-ide-cmake-demo-proj/README_how_to_build.md b/cube-ide-cmake-demo-proj/README_how_to_build.md new file mode 100644 index 0000000..9b72365 --- /dev/null +++ b/cube-ide-cmake-demo-proj/README_how_to_build.md @@ -0,0 +1,28 @@ +# How to build the project + +This is a short-version explaining key steps to build project with CMake in VSCode or directly in shell. + +Long version: https://github.com/MaJerle/stm32-cube-cmake-vscode + +## Pre-requisites + +For successful compilation: + +* *CMake* and *Ninja-build* tools installed and available in environment path +* *ARM None Eabi GCC* toolchain installed and available in environment path - if you have installed *STM32CubeIDE*, you have GCC already installed there - find it in directory and add it to env path + +To further download the built project to STM32 hardware: + +* *STM32CubeProgrammer* tool needs to be installed with bin folder in environment path - to have access to *STM32_Programmer_CLI* command - if you have installed *STM32CubeIDE*, you have GCC already installed there - find it in directory and add it to env path + +For debugging from inside VSCode + +* *ST GDB-Server* tool needs to be installed with bin folder in environment path - you get it together with *STM32CubeIDE* package + +## Steps to build the project + +* Open terminal window in folder where `CMakeLists.txt` for your project is located +* Run `cmake --preset Debug` to generate build system for ninja using `Debug` preset, that comes with the default `CMakePresets.json` file +* Run `cmake --build --preset Debug` to actually invoke ninja-build and compile with GCC +* Go to `build/Debug` folder - you will find your `.elf` file there (only if build is a pass). This is default build directory for `Debug` preset that comes with the project +* Clean the project with `cmake --build --preset Debug --target clean` diff --git a/cube-ide-cmake-demo-proj/cmake_generated/cmake_generated.cmake b/cube-ide-cmake-demo-proj/cmake_generated/cmake_generated.cmake new file mode 100644 index 0000000..0d4ccb6 --- /dev/null +++ b/cube-ide-cmake-demo-proj/cmake_generated/cmake_generated.cmake @@ -0,0 +1,77 @@ +cmake_minimum_required(VERSION 3.22) + +# Core MCU flags, CPU, instruction set and FPU setup +set(cpu_PARAMS ${cpu_PARAMS} + -mthumb + + # Other parameters + # -mcpu, -mfloat, -mfloat-abi, ... + -mcpu=cortex-m7 + -mfpu=fpv5-d16 + -mfloat-abi=hard +) + +# Set linker script +set(linker_script_SRC ${linker_script_SRC} + ${CMAKE_CURRENT_SOURCE_DIR}/STM32H735IGKX_FLASH.ld +) + +# Sources +set(sources_SRCS ${sources_SRCS} + ${CMAKE_CURRENT_SOURCE_DIR}/Core/Src/main.c + ${CMAKE_CURRENT_SOURCE_DIR}/Core/Src/stm32h7xx_it.c + ${CMAKE_CURRENT_SOURCE_DIR}/Core/Src/syscalls.c + ${CMAKE_CURRENT_SOURCE_DIR}/Core/Src/sysmem.c + ${CMAKE_CURRENT_SOURCE_DIR}/Core/Src/system_stm32h7xx.c + ${CMAKE_CURRENT_SOURCE_DIR}/Core/Startup/startup_stm32h735igkx.s + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_exti.c + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_gpio.c + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_pwr.c + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_rcc.c + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_utils.c +) + +# Include directories +set(include_c_DIRS ${include_c_DIRS} + ${CMAKE_CURRENT_SOURCE_DIR}/Core/Inc + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Inc + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/CMSIS/Device/ST/STM32H7xx/Include + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/CMSIS/Include +) +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_FULL_LL_DRIVER" + "HSE_VALUE=25000000" + "HSE_STARTUP_TIMEOUT=100" + "LSE_STARTUP_TIMEOUT=5000" + "LSE_VALUE=32768" + "EXTERNAL_CLOCK_VALUE=12288000" + "HSI_VALUE=64000000" + "LSI_VALUE=32000" + "VDD_VALUE=3300" +) +set(symbols_cxx_SYMB ${symbols_cxx_SYMB} + +) +set(symbols_asm_SYMB ${symbols_asm_SYMB} + "DEBUG" +) + +# Link directories +set(link_DIRS ${link_DIRS} + +) + +# Link directories +set(link_LIBS ${link_LIBS} + +) diff --git a/script-projects/h735g-dk-touchgfx/.vscode/launch.json b/script-projects/h735g-dk-touchgfx/.vscode/launch.json index 9b3d92d..3f760af 100644 --- a/script-projects/h735g-dk-touchgfx/.vscode/launch.json +++ b/script-projects/h735g-dk-touchgfx/.vscode/launch.json @@ -14,7 +14,7 @@ "device": "", //MCU used, ex. "STM32H735IG" "interface": "swd", "serialNumber": "", //Set ST-Link ID if you use multiple at the same time - "runToMain": true, + "runToEntryPoint": "main", "svdFile": "path/to/file.svd", //Path to SVD file to see registers "v1": false, "showDevDebugOutput": "both", diff --git a/script-projects/h735g-dk-touchgfx/CMakeLists.txt b/script-projects/h735g-dk-touchgfx/CMakeLists.txt index 23ec4f5..53ffc94 100644 --- a/script-projects/h735g-dk-touchgfx/CMakeLists.txt +++ b/script-projects/h735g-dk-touchgfx/CMakeLists.txt @@ -1,325 +1,115 @@ cmake_minimum_required(VERSION 3.22) -message("Entering ${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt") - -# # Core project settings -# -set(PROJ_PATH ${CMAKE_CURRENT_SOURCE_DIR}) project(STM32H735G-DK) enable_language(C CXX ASM) -message("Build type: " ${CMAKE_BUILD_TYPE}) +message("Build type: " ${CMAKE_BUILD_TYPE}) # Setup compiler settings -set(CMAKE_C_STANDARD 11) -set(CMAKE_C_STANDARD_REQUIRED ON) -set(CMAKE_C_EXTENSIONS ON) -set(CMAKE_CXX_STANDARD 20) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_EXTENSIONS ON) +set(CMAKE_C_STANDARD 11) +set(CMAKE_C_STANDARD_REQUIRED ON) +set(CMAKE_C_EXTENSIONS ON) +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS ON) + +# Core MCU flags, CPU type, instruction set and FPU setup +set(cpu_PARAMS -mthumb -# -# Core MCU flags, CPU, instruction set and FPU setup -# -set(CPU_PARAMETERS - -mthumb # Other parameters # -mcpu, -mfloat, -mfloat-abi, ... - -mcpu=cortex-m7 - -mfpu=fpv5-d16 - -mfloat-abi=hard ) -# Set linker script -set(linker_script_SRC ${PROJ_PATH}/STM32CubeIDE/STM32H735IGKX_FLASH.ld) -set(EXECUTABLE ${CMAKE_PROJECT_NAME}) - -# -# Source files -# -set(src__SRCS - ${PROJ_PATH}/STM32H735G-DK.ioc) - -set(src_drivers_cmsis_SRCS - ${PROJ_PATH}/Core/Src/system_stm32h7xx.c) - -set(src_drivers_stm32h7xx_hal_driver_SRCS - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal.c - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_cortex.c - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_crc.c - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_crc_ex.c - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dma.c - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dma2d.c - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dma_ex.c - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_exti.c - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_flash.c - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_flash_ex.c - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_gpio.c - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_hsem.c - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_i2c.c - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_i2c_ex.c - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_ltdc.c - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_ltdc_ex.c - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_mdma.c - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_ospi.c - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_pwr.c - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_pwr_ex.c - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rcc.c - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rcc_ex.c - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_tim.c - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_tim_ex.c) - -set(src_middlewares_freertos_SRCS - ${PROJ_PATH}/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.c - ${PROJ_PATH}/Middlewares/Third_Party/FreeRTOS/Source/croutine.c - ${PROJ_PATH}/Middlewares/Third_Party/FreeRTOS/Source/event_groups.c - ${PROJ_PATH}/Middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_4.c - ${PROJ_PATH}/Middlewares/Third_Party/FreeRTOS/Source/list.c - ${PROJ_PATH}/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c - ${PROJ_PATH}/Middlewares/Third_Party/FreeRTOS/Source/queue.c - ${PROJ_PATH}/Middlewares/Third_Party/FreeRTOS/Source/stream_buffer.c - ${PROJ_PATH}/Middlewares/Third_Party/FreeRTOS/Source/tasks.c - ${PROJ_PATH}/Middlewares/Third_Party/FreeRTOS/Source/timers.c) - -set(src_application_user_core_SRCS - ${PROJ_PATH}/Core/Src/freertos.c - ${PROJ_PATH}/Core/Src/main.c - ${PROJ_PATH}/Core/Src/stm32h7xx_hal_msp.c - ${PROJ_PATH}/Core/Src/stm32h7xx_hal_timebase_tim.c - ${PROJ_PATH}/Core/Src/stm32h7xx_it.c - ${PROJ_PATH}/STM32CubeIDE/Application/User/Core/syscalls.c - ${PROJ_PATH}/STM32CubeIDE/Application/User/Core/sysmem.c) - -set(src_drivers_bsp_components_SRCS - ${PROJ_PATH}/Drivers/BSP/Components/ft5336/ft5336.c - ${PROJ_PATH}/Drivers/BSP/Components/ft5336/ft5336_reg.c - ${PROJ_PATH}/Drivers/BSP/Components/mx25lm51245g/mx25lm51245g.c - ${PROJ_PATH}/Drivers/BSP/Components/s70kl1281/s70kl1281.c) - -set(src_drivers_bsp_stm32h735g_dk_SRCS - ${PROJ_PATH}/Drivers/BSP/STM32H735G-DK/stm32h735g_discovery_bus.c - ${PROJ_PATH}/Drivers/BSP/STM32H735G-DK/stm32h735g_discovery_ospi.c - ${PROJ_PATH}/Drivers/BSP/STM32H735G-DK/stm32h735g_discovery_ts.c) +# Sources +set(sources_SRCS) -set(src_application_user_touchgfx_app_SRCS - ${PROJ_PATH}/TouchGFX/App/app_touchgfx.c) +# Include directories for each compiler +set(include_c_DIRS) +set(include_cxx_DIRS) +set(include_asm_DIRS) -set(src_application_user_touchgfx_target_SRCS - ${PROJ_PATH}/TouchGFX/target/CortexMMCUInstrumentation.cpp - ${PROJ_PATH}/TouchGFX/target/STM32TouchController.cpp - ${PROJ_PATH}/TouchGFX/target/TouchGFXGPIO.cpp - ${PROJ_PATH}/TouchGFX/target/TouchGFXHAL.cpp) +# Symbols definition for each compiler +set(symbols_c_SYMB) +set(symbols_cxx_SYMB) +set(symbols_asm_SYMB) -set(src_application_user_touchgfx_target_generated_SRCS - ${PROJ_PATH}/TouchGFX/target/generated/OSWrappers.cpp - ${PROJ_PATH}/TouchGFX/target/generated/STM32DMA.cpp - ${PROJ_PATH}/TouchGFX/target/generated/TouchGFXConfiguration.cpp - ${PROJ_PATH}/TouchGFX/target/generated/TouchGFXGeneratedHAL.cpp) +# Link directories and names of libraries +set(link_DIRS) +set(link_LIBS) -set(src_application_user_gui_SRCS - ${PROJ_PATH}/TouchGFX/gui/src/common/FrontendApplication.cpp - ${PROJ_PATH}/TouchGFX/gui/src/containers/ScrollList_myContainer.cpp - ${PROJ_PATH}/TouchGFX/gui/src/model/Model.cpp - ${PROJ_PATH}/TouchGFX/gui/src/screen1_screen/Screen1Presenter.cpp - ${PROJ_PATH}/TouchGFX/gui/src/screen1_screen/Screen1View.cpp) +# Linker script +set(linker_script_SRC) -set(src_application_user_generated_SRCS - ${PROJ_PATH}/TouchGFX/generated/fonts/src/ApplicationFontProvider.cpp - ${PROJ_PATH}/TouchGFX/generated/fonts/src/CachedFont.cpp - ${PROJ_PATH}/TouchGFX/generated/fonts/src/FontCache.cpp - ${PROJ_PATH}/TouchGFX/generated/fonts/src/Font_verdana_10_4bpp_0.cpp - ${PROJ_PATH}/TouchGFX/generated/fonts/src/Font_verdana_20_4bpp_0.cpp - ${PROJ_PATH}/TouchGFX/generated/fonts/src/Font_verdana_40_4bpp_0.cpp - ${PROJ_PATH}/TouchGFX/generated/fonts/src/GeneratedFont.cpp - ${PROJ_PATH}/TouchGFX/generated/fonts/src/Kerning_verdana_10_4bpp.cpp - ${PROJ_PATH}/TouchGFX/generated/fonts/src/Kerning_verdana_20_4bpp.cpp - ${PROJ_PATH}/TouchGFX/generated/fonts/src/Kerning_verdana_40_4bpp.cpp - ${PROJ_PATH}/TouchGFX/generated/fonts/src/Table_verdana_10_4bpp.cpp - ${PROJ_PATH}/TouchGFX/generated/fonts/src/Table_verdana_20_4bpp.cpp - ${PROJ_PATH}/TouchGFX/generated/fonts/src/Table_verdana_40_4bpp.cpp - ${PROJ_PATH}/TouchGFX/generated/fonts/src/UnmappedDataFont.cpp - ${PROJ_PATH}/TouchGFX/generated/gui_generated/src/common/FrontendApplicationBase.cpp - ${PROJ_PATH}/TouchGFX/generated/gui_generated/src/containers/ScrollList_myContainerBase.cpp - ${PROJ_PATH}/TouchGFX/generated/gui_generated/src/screen1_screen/Screen1ViewBase.cpp - ${PROJ_PATH}/TouchGFX/generated/images/src/BitmapDatabase.cpp - ${PROJ_PATH}/TouchGFX/generated/images/src/__designer/image_Blue_Buttons_Round_large.cpp - ${PROJ_PATH}/TouchGFX/generated/images/src/__designer/image_Blue_Icons_Add_new_32.cpp - ${PROJ_PATH}/TouchGFX/generated/images/src/__designer/image_Dark_Backgrounds_Main_bg_texture_320x240px.cpp - ${PROJ_PATH}/TouchGFX/generated/texts/src/LanguageGb.cpp - ${PROJ_PATH}/TouchGFX/generated/texts/src/Texts.cpp - ${PROJ_PATH}/TouchGFX/generated/texts/src/TypedTextDatabase.cpp) +# Compiler options +set(compiler_OPTS) -set(src_application_user_startup_SRCS - ${PROJ_PATH}/STM32CubeIDE/Application/User/Startup/startup_stm32h735igkx.s) +# Linker options +set(linker_OPTS) -# -# Include directories -# -set(include_c_DIRS - ${PROJ_PATH}/Core/Inc - ${PROJ_PATH}/TouchGFX/App - ${PROJ_PATH}/TouchGFX/target/generated - ${PROJ_PATH}/TouchGFX/target - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Inc - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Inc/Legacy - ${PROJ_PATH}/Middlewares/Third_Party/FreeRTOS/Source/include - ${PROJ_PATH}/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2 - ${PROJ_PATH}/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F - ${PROJ_PATH}/Drivers/CMSIS/Device/ST/STM32H7xx/Include - ${PROJ_PATH}/Drivers/CMSIS/Include - ${PROJ_PATH}/Drivers/BSP/Components/Common - ${PROJ_PATH}/Drivers/BSP/STM32H735G-DK - ${PROJ_PATH}/Middlewares/ST/touchgfx/framework/include - ${PROJ_PATH}/TouchGFX/generated/fonts/include - ${PROJ_PATH}/TouchGFX/generated/gui_generated/include - ${PROJ_PATH}/TouchGFX/generated/images/include - ${PROJ_PATH}/TouchGFX/generated/texts/include - ${PROJ_PATH}/TouchGFX/gui/include - ${PROJ_PATH}/TouchGFX/generated/videos/include -) -set(include_cxx_DIRS - ${PROJ_PATH}/Core/Inc - ${PROJ_PATH}/TouchGFX/App - ${PROJ_PATH}/TouchGFX/target/generated - ${PROJ_PATH}/TouchGFX/target - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Inc - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Inc/Legacy - ${PROJ_PATH}/Middlewares/Third_Party/FreeRTOS/Source/include - ${PROJ_PATH}/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2 - ${PROJ_PATH}/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F - ${PROJ_PATH}/Drivers/CMSIS/Device/ST/STM32H7xx/Include - ${PROJ_PATH}/Drivers/CMSIS/Include - ${PROJ_PATH}/Drivers/BSP/Components/Common - ${PROJ_PATH}/Drivers/BSP/STM32H735G-DK - ${PROJ_PATH}/Middlewares/ST/touchgfx/framework/include - ${PROJ_PATH}/TouchGFX/generated/fonts/include - ${PROJ_PATH}/TouchGFX/generated/gui_generated/include - ${PROJ_PATH}/TouchGFX/generated/images/include - ${PROJ_PATH}/TouchGFX/generated/texts/include - ${PROJ_PATH}/TouchGFX/gui/include - ${PROJ_PATH}/TouchGFX/generated/videos/include -) -set(include_asm_DIRS - -) +# Now call generated cmake +# This will add script generated +# information to the project +include("cmake_generated/cmake_generated.cmake") -# -# Symbols definition -# -set(symbols_c_SYMB - "USE_HAL_DRIVER" - "DEBUG" - "STM32H735xx" -) -set(symbols_cxx_SYMB - "USE_HAL_DRIVER" - "DEBUG" - "STM32H735xx" -) -set(symbols_asm_SYMB - "DEBUG" -) - -# # Link directories setup # Must be before executable is added -# -set(link_DIRS - ${PROJ_PATH}/Middlewares/ST/touchgfx/lib/core/cortex_m7/gcc -) -link_directories(${EXECUTABLE} ${link_DIRS}) +link_directories(${CMAKE_PROJECT_NAME} ${link_DIRS}) + +# Create an executable object type +add_executable(${CMAKE_PROJECT_NAME}) -# -# Executable files -# -add_executable(${EXECUTABLE} - ${src__SRCS} - ${src_drivers_cmsis_SRCS} - ${src_drivers_stm32h7xx_hal_driver_SRCS} - ${src_middlewares_freertos_SRCS} - ${src_application_user_core_SRCS} - ${src_drivers_bsp_components_SRCS} - ${src_drivers_bsp_stm32h735g_dk_SRCS} - ${src_application_user_touchgfx_app_SRCS} - ${src_application_user_touchgfx_target_SRCS} - ${src_application_user_touchgfx_target_generated_SRCS} - ${src_application_user_gui_SRCS} - ${src_application_user_generated_SRCS} - ${src_application_user_startup_SRCS}) +# Add sources to executable +target_sources(${CMAKE_PROJECT_NAME} PUBLIC ${sources_SRCS}) -# -# Add linked libraries for linker -# -set(link_LIBS - :libtouchgfx-float-abi-hard.a +# Add include paths +target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE + $<$: ${include_c_DIRS}> + $<$: ${include_cxx_DIRS}> + $<$: ${include_asm_DIRS}> ) -target_link_libraries(${EXECUTABLE} ${link_LIBS}) -# -# Project symbols -# -target_compile_definitions(${EXECUTABLE} PRIVATE - # Language specific only +# Add project symbols (macros) +target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE $<$: ${symbols_c_SYMB}> $<$: ${symbols_cxx_SYMB}> $<$: ${symbols_asm_SYMB}> # Configuration specific - $<$: - DEBUG - > + $<$:DEBUG> $<$: > ) -# -# Add include paths for each of the compiler -# -target_include_directories(${EXECUTABLE} PRIVATE - # Language specific only - $<$: ${include_c_DIRS}> - $<$: ${include_cxx_DIRS}> - $<$: ${include_asm_DIRS}> - - # Configuration specific - $<$: > - $<$: > -) +# Add linked libraries +target_link_libraries(${CMAKE_PROJECT_NAME} ${link_LIBS}) -# Compiler and linker options -target_compile_options(${EXECUTABLE} PRIVATE - ${CPU_PARAMETERS} +# Compiler options +target_compile_options(${CMAKE_PROJECT_NAME} PRIVATE + ${cpu_PARAMS} + ${compiler_OPTS} -Wall -Wextra -Wpedantic -Wno-unused-parameter - $<$: - - > + $<$: > $<$: - #-Wno-volatile - #-Wold-style-cast - #-Wuseless-cast - #-Wsuggest-override - > - $<$: - -x assembler-with-cpp - -MMD - -MP - > - $<$: - -Og -g3 -ggdb - > - $<$: - -Og -g0 + + # -Wno-volatile + # -Wold-style-cast + # -Wuseless-cast + # -Wsuggest-override > + $<$:-x assembler-with-cpp -MMD -MP> + $<$:-Og -g3 -ggdb> + $<$:-Og -g0> ) -# Setup linker parameters -target_link_options(${EXECUTABLE} PRIVATE +# Linker options +target_link_options(${CMAKE_PROJECT_NAME} PRIVATE -T${linker_script_SRC} - ${CPU_PARAMETERS} + ${cpu_PARAMS} + ${linker_OPTS} -Wl,-Map=${CMAKE_PROJECT_NAME}.map - -u _printf_float # STDIO float formatting support (remove if not used) + -u _printf_float # STDIO float formatting support (remove if not used) --specs=nosys.specs -Wl,--start-group -lc @@ -327,22 +117,21 @@ target_link_options(${EXECUTABLE} PRIVATE -lstdc++ -lsupc++ -Wl,--end-group + -Wl,-z,max-page-size=8 # Allow good software remapping across address space (with proper GCC section making) -Wl,--print-memory-usage ) # Execute post-build to print size -add_custom_command(TARGET ${EXECUTABLE} POST_BUILD - COMMAND ${CMAKE_SIZE} $ +add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_SIZE} $ ) # Convert output to hex and binary -add_custom_command(TARGET ${EXECUTABLE} POST_BUILD - COMMAND ${CMAKE_OBJCOPY} -O ihex $ ${EXECUTABLE}.hex +add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_OBJCOPY} -O ihex $ ${CMAKE_PROJECT_NAME}.hex ) # Convert to bin file -> add conditional check? -add_custom_command(TARGET ${EXECUTABLE} POST_BUILD - COMMAND ${CMAKE_OBJCOPY} -O binary $ ${EXECUTABLE}.bin +add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_OBJCOPY} -O binary $ ${CMAKE_PROJECT_NAME}.bin ) - -message("Exiting ${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt") diff --git a/script-projects/h735g-dk-touchgfx/CMakePresets.json b/script-projects/h735g-dk-touchgfx/CMakePresets.json index 788b377..a86b366 100644 --- a/script-projects/h735g-dk-touchgfx/CMakePresets.json +++ b/script-projects/h735g-dk-touchgfx/CMakePresets.json @@ -39,5 +39,23 @@ "CMAKE_BUILD_TYPE": "MinSizeRel" } } + ], + "buildPresets": [ + { + "name": "Debug", + "configurePreset": "Debug" + }, + { + "name": "RelWithDebInfo", + "configurePreset": "RelWithDebInfo" + }, + { + "name": "Release", + "configurePreset": "Release" + }, + { + "name": "MinSizeRel", + "configurePreset": "MinSizeRel" + } ] } \ No newline at end of file diff --git a/script-projects/h735g-dk-touchgfx/README_how_to_build.md b/script-projects/h735g-dk-touchgfx/README_how_to_build.md new file mode 100644 index 0000000..9b72365 --- /dev/null +++ b/script-projects/h735g-dk-touchgfx/README_how_to_build.md @@ -0,0 +1,28 @@ +# How to build the project + +This is a short-version explaining key steps to build project with CMake in VSCode or directly in shell. + +Long version: https://github.com/MaJerle/stm32-cube-cmake-vscode + +## Pre-requisites + +For successful compilation: + +* *CMake* and *Ninja-build* tools installed and available in environment path +* *ARM None Eabi GCC* toolchain installed and available in environment path - if you have installed *STM32CubeIDE*, you have GCC already installed there - find it in directory and add it to env path + +To further download the built project to STM32 hardware: + +* *STM32CubeProgrammer* tool needs to be installed with bin folder in environment path - to have access to *STM32_Programmer_CLI* command - if you have installed *STM32CubeIDE*, you have GCC already installed there - find it in directory and add it to env path + +For debugging from inside VSCode + +* *ST GDB-Server* tool needs to be installed with bin folder in environment path - you get it together with *STM32CubeIDE* package + +## Steps to build the project + +* Open terminal window in folder where `CMakeLists.txt` for your project is located +* Run `cmake --preset Debug` to generate build system for ninja using `Debug` preset, that comes with the default `CMakePresets.json` file +* Run `cmake --build --preset Debug` to actually invoke ninja-build and compile with GCC +* Go to `build/Debug` folder - you will find your `.elf` file there (only if build is a pass). This is default build directory for `Debug` preset that comes with the project +* Clean the project with `cmake --build --preset Debug --target clean` diff --git a/script-projects/h735g-dk-touchgfx/cmake_generated/cmake_generated.cmake b/script-projects/h735g-dk-touchgfx/cmake_generated/cmake_generated.cmake new file mode 100644 index 0000000..8852103 --- /dev/null +++ b/script-projects/h735g-dk-touchgfx/cmake_generated/cmake_generated.cmake @@ -0,0 +1,184 @@ +cmake_minimum_required(VERSION 3.22) + +# Core MCU flags, CPU, instruction set and FPU setup +set(cpu_PARAMS ${cpu_PARAMS} + -mthumb + + # Other parameters + # -mcpu, -mfloat, -mfloat-abi, ... + -mcpu=cortex-m7 + -mfpu=fpv5-d16 + -mfloat-abi=hard +) + +# Set linker script +set(linker_script_SRC ${linker_script_SRC} + ${CMAKE_CURRENT_SOURCE_DIR}/STM32CubeIDE/STM32H735IGKX_FLASH.ld +) + +# Sources +set(sources_SRCS ${sources_SRCS} + ${CMAKE_CURRENT_SOURCE_DIR}/STM32H735G-DK.ioc + ${CMAKE_CURRENT_SOURCE_DIR}/Core/Src/system_stm32h7xx.c + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal.c + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_cortex.c + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_crc.c + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_crc_ex.c + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dma.c + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dma2d.c + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dma_ex.c + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_exti.c + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_flash.c + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_flash_ex.c + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_gpio.c + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_hsem.c + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_i2c.c + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_i2c_ex.c + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_ltdc.c + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_ltdc_ex.c + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_mdma.c + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_ospi.c + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_pwr.c + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_pwr_ex.c + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rcc.c + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rcc_ex.c + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_tim.c + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_tim_ex.c + ${CMAKE_CURRENT_SOURCE_DIR}/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.c + ${CMAKE_CURRENT_SOURCE_DIR}/Middlewares/Third_Party/FreeRTOS/Source/croutine.c + ${CMAKE_CURRENT_SOURCE_DIR}/Middlewares/Third_Party/FreeRTOS/Source/event_groups.c + ${CMAKE_CURRENT_SOURCE_DIR}/Middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_4.c + ${CMAKE_CURRENT_SOURCE_DIR}/Middlewares/Third_Party/FreeRTOS/Source/list.c + ${CMAKE_CURRENT_SOURCE_DIR}/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c + ${CMAKE_CURRENT_SOURCE_DIR}/Middlewares/Third_Party/FreeRTOS/Source/queue.c + ${CMAKE_CURRENT_SOURCE_DIR}/Middlewares/Third_Party/FreeRTOS/Source/stream_buffer.c + ${CMAKE_CURRENT_SOURCE_DIR}/Middlewares/Third_Party/FreeRTOS/Source/tasks.c + ${CMAKE_CURRENT_SOURCE_DIR}/Middlewares/Third_Party/FreeRTOS/Source/timers.c + ${CMAKE_CURRENT_SOURCE_DIR}/Core/Src/freertos.c + ${CMAKE_CURRENT_SOURCE_DIR}/Core/Src/main.c + ${CMAKE_CURRENT_SOURCE_DIR}/Core/Src/stm32h7xx_hal_msp.c + ${CMAKE_CURRENT_SOURCE_DIR}/Core/Src/stm32h7xx_hal_timebase_tim.c + ${CMAKE_CURRENT_SOURCE_DIR}/Core/Src/stm32h7xx_it.c + ${CMAKE_CURRENT_SOURCE_DIR}/STM32CubeIDE/Application/User/Core/syscalls.c + ${CMAKE_CURRENT_SOURCE_DIR}/STM32CubeIDE/Application/User/Core/sysmem.c + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/BSP/Components/ft5336/ft5336.c + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/BSP/Components/ft5336/ft5336_reg.c + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/BSP/Components/mx25lm51245g/mx25lm51245g.c + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/BSP/Components/s70kl1281/s70kl1281.c + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/BSP/STM32H735G-DK/stm32h735g_discovery_bus.c + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/BSP/STM32H735G-DK/stm32h735g_discovery_ospi.c + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/BSP/STM32H735G-DK/stm32h735g_discovery_ts.c + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/App/app_touchgfx.c + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/target/CortexMMCUInstrumentation.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/target/STM32TouchController.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/target/TouchGFXGPIO.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/target/TouchGFXHAL.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/target/generated/OSWrappers.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/target/generated/STM32DMA.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/target/generated/TouchGFXConfiguration.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/target/generated/TouchGFXGeneratedHAL.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/gui/src/common/FrontendApplication.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/gui/src/containers/ScrollList_myContainer.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/gui/src/model/Model.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/gui/src/screen1_screen/Screen1Presenter.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/gui/src/screen1_screen/Screen1View.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/generated/fonts/src/ApplicationFontProvider.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/generated/fonts/src/CachedFont.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/generated/fonts/src/FontCache.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/generated/fonts/src/Font_verdana_10_4bpp_0.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/generated/fonts/src/Font_verdana_20_4bpp_0.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/generated/fonts/src/Font_verdana_40_4bpp_0.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/generated/fonts/src/GeneratedFont.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/generated/fonts/src/Kerning_verdana_10_4bpp.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/generated/fonts/src/Kerning_verdana_20_4bpp.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/generated/fonts/src/Kerning_verdana_40_4bpp.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/generated/fonts/src/Table_verdana_10_4bpp.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/generated/fonts/src/Table_verdana_20_4bpp.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/generated/fonts/src/Table_verdana_40_4bpp.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/generated/fonts/src/UnmappedDataFont.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/generated/gui_generated/src/common/FrontendApplicationBase.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/generated/gui_generated/src/containers/ScrollList_myContainerBase.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/generated/gui_generated/src/screen1_screen/Screen1ViewBase.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/generated/images/src/BitmapDatabase.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/generated/images/src/__designer/image_Blue_Buttons_Round_large.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/generated/images/src/__designer/image_Blue_Icons_Add_new_32.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/generated/images/src/__designer/image_Dark_Backgrounds_Main_bg_texture_320x240px.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/generated/texts/src/LanguageGb.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/generated/texts/src/Texts.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/generated/texts/src/TypedTextDatabase.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/STM32CubeIDE/Application/User/Startup/startup_stm32h735igkx.s +) + +# Include directories +set(include_c_DIRS ${include_c_DIRS} + ${CMAKE_CURRENT_SOURCE_DIR}/Core/Inc + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/App + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/target/generated + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/target + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Inc + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Inc/Legacy + ${CMAKE_CURRENT_SOURCE_DIR}/Middlewares/Third_Party/FreeRTOS/Source/include + ${CMAKE_CURRENT_SOURCE_DIR}/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2 + ${CMAKE_CURRENT_SOURCE_DIR}/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/CMSIS/Device/ST/STM32H7xx/Include + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/CMSIS/Include + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/BSP/Components/Common + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/BSP/STM32H735G-DK + ${CMAKE_CURRENT_SOURCE_DIR}/Middlewares/ST/touchgfx/framework/include + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/generated/fonts/include + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/generated/gui_generated/include + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/generated/images/include + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/generated/texts/include + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/gui/include + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/generated/videos/include +) +set(include_cxx_DIRS ${include_cxx_DIRS} + ${CMAKE_CURRENT_SOURCE_DIR}/Core/Inc + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/App + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/target/generated + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/target + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Inc + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Inc/Legacy + ${CMAKE_CURRENT_SOURCE_DIR}/Middlewares/Third_Party/FreeRTOS/Source/include + ${CMAKE_CURRENT_SOURCE_DIR}/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2 + ${CMAKE_CURRENT_SOURCE_DIR}/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/CMSIS/Device/ST/STM32H7xx/Include + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/CMSIS/Include + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/BSP/Components/Common + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/BSP/STM32H735G-DK + ${CMAKE_CURRENT_SOURCE_DIR}/Middlewares/ST/touchgfx/framework/include + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/generated/fonts/include + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/generated/gui_generated/include + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/generated/images/include + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/generated/texts/include + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/gui/include + ${CMAKE_CURRENT_SOURCE_DIR}/TouchGFX/generated/videos/include +) +set(include_asm_DIRS ${include_asm_DIRS} + +) + +# Symbols definition +set(symbols_c_SYMB ${symbols_c_SYMB} + "USE_HAL_DRIVER" + "DEBUG" + "STM32H735xx" +) +set(symbols_cxx_SYMB ${symbols_cxx_SYMB} + "USE_HAL_DRIVER" + "DEBUG" + "STM32H735xx" +) +set(symbols_asm_SYMB ${symbols_asm_SYMB} + "DEBUG" +) + +# Link directories +set(link_DIRS ${link_DIRS} + ${CMAKE_CURRENT_SOURCE_DIR}/Middlewares/ST/touchgfx/lib/core/cortex_m7/gcc +) + +# Link directories +set(link_LIBS ${link_LIBS} + :libtouchgfx-float-abi-hard.a +) diff --git a/script-projects/h735g-dk-usart/.vscode/launch.json b/script-projects/h735g-dk-usart/.vscode/launch.json index 9b3d92d..3f760af 100644 --- a/script-projects/h735g-dk-usart/.vscode/launch.json +++ b/script-projects/h735g-dk-usart/.vscode/launch.json @@ -14,7 +14,7 @@ "device": "", //MCU used, ex. "STM32H735IG" "interface": "swd", "serialNumber": "", //Set ST-Link ID if you use multiple at the same time - "runToMain": true, + "runToEntryPoint": "main", "svdFile": "path/to/file.svd", //Path to SVD file to see registers "v1": false, "showDevDebugOutput": "both", diff --git a/script-projects/h735g-dk-usart/CMakeLists.txt b/script-projects/h735g-dk-usart/CMakeLists.txt index 24c7537..04d2a20 100644 --- a/script-projects/h735g-dk-usart/CMakeLists.txt +++ b/script-projects/h735g-dk-usart/CMakeLists.txt @@ -1,218 +1,115 @@ cmake_minimum_required(VERSION 3.22) -message("Entering ${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt") - -# # Core project settings -# -set(PROJ_PATH ${CMAKE_CURRENT_SOURCE_DIR}) project(h735g-dk-usart) enable_language(C CXX ASM) -message("Build type: " ${CMAKE_BUILD_TYPE}) +message("Build type: " ${CMAKE_BUILD_TYPE}) # Setup compiler settings -set(CMAKE_C_STANDARD 11) -set(CMAKE_C_STANDARD_REQUIRED ON) -set(CMAKE_C_EXTENSIONS ON) -set(CMAKE_CXX_STANDARD 20) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_EXTENSIONS ON) - -# -# Core MCU flags, CPU, instruction set and FPU setup -# -set(CPU_PARAMETERS - -mthumb +set(CMAKE_C_STANDARD 11) +set(CMAKE_C_STANDARD_REQUIRED ON) +set(CMAKE_C_EXTENSIONS ON) +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS ON) + +# Core MCU flags, CPU type, instruction set and FPU setup +set(cpu_PARAMS -mthumb + # Other parameters # -mcpu, -mfloat, -mfloat-abi, ... - -mcpu=cortex-m7 - -mfpu=fpv5-d16 - -mfloat-abi=hard ) -# Set linker script -set(linker_script_SRC ${PROJ_PATH}/STM32H735IGKX_FLASH.ld) -set(EXECUTABLE ${CMAKE_PROJECT_NAME}) - -# -# Source files -# -set(src_core_src_SRCS - ${PROJ_PATH}/Core/Src/main.c - ${PROJ_PATH}/Core/Src/stm32h7xx_hal_msp.c - ${PROJ_PATH}/Core/Src/stm32h7xx_it.c - ${PROJ_PATH}/Core/Src/syscalls.c - ${PROJ_PATH}/Core/Src/sysmem.c - ${PROJ_PATH}/Core/Src/system_stm32h7xx.c) - -set(src_core_startup_SRCS - ${PROJ_PATH}/Core/Startup/startup_stm32h735igkx.s) - -set(src_fatfs_app_SRCS - ${PROJ_PATH}/FATFS/App/fatfs.c) - -set(src_fatfs_target_SRCS - ${PROJ_PATH}/FATFS/Target/user_diskio.c) - -set(src_middlewares_third_party_fatfs_src_SRCS - ${PROJ_PATH}/Middlewares/Third_Party/FatFs/src/diskio.c - ${PROJ_PATH}/Middlewares/Third_Party/FatFs/src/ff.c - ${PROJ_PATH}/Middlewares/Third_Party/FatFs/src/ff_gen_drv.c) - -set(src_middlewares_third_party_fatfs_src_option_SRCS - ${PROJ_PATH}/Middlewares/Third_Party/FatFs/src/option/syscall.c) - -set(src_drivers_stm32h7xx_hal_driver_src_SRCS - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal.c - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_cortex.c - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dma.c - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dma_ex.c - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_exti.c - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_flash.c - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_flash_ex.c - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_gpio.c - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_hsem.c - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_i2c.c - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_i2c_ex.c - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_mdma.c - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_pwr.c - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_pwr_ex.c - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rcc.c - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rcc_ex.c - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_tim.c - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_tim_ex.c - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_uart.c - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_uart_ex.c) - -# -# Include directories -# -set(include_c_DIRS - ${PROJ_PATH}/FATFS/Target - ${PROJ_PATH}/FATFS/App - ${PROJ_PATH}/Core/Inc - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Inc - ${PROJ_PATH}/Drivers/STM32H7xx_HAL_Driver/Inc/Legacy - ${PROJ_PATH}/Middlewares/Third_Party/FatFs/src - ${PROJ_PATH}/Drivers/CMSIS/Device/ST/STM32H7xx/Include - ${PROJ_PATH}/Drivers/CMSIS/Include -) -set(include_cxx_DIRS - -) -set(include_asm_DIRS - -) +# Sources +set(sources_SRCS) -# -# Symbols definition -# -set(symbols_c_SYMB - "DEBUG" - "USE_HAL_DRIVER" - "STM32H735xx" -) -set(symbols_cxx_SYMB - -) -set(symbols_asm_SYMB - "DEBUG" -) +# Include directories for each compiler +set(include_c_DIRS) +set(include_cxx_DIRS) +set(include_asm_DIRS) + +# Symbols definition for each compiler +set(symbols_c_SYMB) +set(symbols_cxx_SYMB) +set(symbols_asm_SYMB) + +# Link directories and names of libraries +set(link_DIRS) +set(link_LIBS) + +# Linker script +set(linker_script_SRC) + +# Compiler options +set(compiler_OPTS) + +# Linker options +set(linker_OPTS) + +# Now call generated cmake +# This will add script generated +# information to the project +include("cmake_generated/cmake_generated.cmake") -# # Link directories setup # Must be before executable is added -# -set(link_DIRS - -) -link_directories(${EXECUTABLE} ${link_DIRS}) - -# -# Executable files -# -add_executable(${EXECUTABLE} - ${src_core_src_SRCS} - ${src_core_startup_SRCS} - ${src_fatfs_app_SRCS} - ${src_fatfs_target_SRCS} - ${src_middlewares_third_party_fatfs_src_SRCS} - ${src_middlewares_third_party_fatfs_src_option_SRCS} - ${src_drivers_stm32h7xx_hal_driver_src_SRCS}) - -# -# Add linked libraries for linker -# -set(link_LIBS - -) -target_link_libraries(${EXECUTABLE} ${link_LIBS}) +link_directories(${CMAKE_PROJECT_NAME} ${link_DIRS}) -# -# Project symbols -# -target_compile_definitions(${EXECUTABLE} PRIVATE - # Language specific only - $<$: ${symbols_c_SYMB}> - $<$: ${symbols_cxx_SYMB}> - $<$: ${symbols_asm_SYMB}> +# Create an executable object type +add_executable(${CMAKE_PROJECT_NAME}) - # Configuration specific - $<$: - DEBUG - > - $<$: > -) +# Add sources to executable +target_sources(${CMAKE_PROJECT_NAME} PUBLIC ${sources_SRCS}) -# -# Add include paths for each of the compiler -# -target_include_directories(${EXECUTABLE} PRIVATE - # Language specific only +# Add include paths +target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE $<$: ${include_c_DIRS}> $<$: ${include_cxx_DIRS}> $<$: ${include_asm_DIRS}> +) + +# Add project symbols (macros) +target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE + $<$: ${symbols_c_SYMB}> + $<$: ${symbols_cxx_SYMB}> + $<$: ${symbols_asm_SYMB}> # Configuration specific - $<$: > + $<$:DEBUG> $<$: > ) -# Compiler and linker options -target_compile_options(${EXECUTABLE} PRIVATE - ${CPU_PARAMETERS} +# Add linked libraries +target_link_libraries(${CMAKE_PROJECT_NAME} ${link_LIBS}) + +# Compiler options +target_compile_options(${CMAKE_PROJECT_NAME} PRIVATE + ${cpu_PARAMS} + ${compiler_OPTS} -Wall -Wextra -Wpedantic -Wno-unused-parameter - $<$: - - > + $<$: > $<$: - #-Wno-volatile - #-Wold-style-cast - #-Wuseless-cast - #-Wsuggest-override - > - $<$: - -x assembler-with-cpp - -MMD - -MP - > - $<$: - -Og -g3 -ggdb - > - $<$: - -Og -g0 + + # -Wno-volatile + # -Wold-style-cast + # -Wuseless-cast + # -Wsuggest-override > + $<$:-x assembler-with-cpp -MMD -MP> + $<$:-Og -g3 -ggdb> + $<$:-Og -g0> ) -# Setup linker parameters -target_link_options(${EXECUTABLE} PRIVATE +# Linker options +target_link_options(${CMAKE_PROJECT_NAME} PRIVATE -T${linker_script_SRC} - ${CPU_PARAMETERS} + ${cpu_PARAMS} + ${linker_OPTS} -Wl,-Map=${CMAKE_PROJECT_NAME}.map - -u _printf_float # STDIO float formatting support (remove if not used) + -u _printf_float # STDIO float formatting support (remove if not used) --specs=nosys.specs -Wl,--start-group -lc @@ -220,22 +117,21 @@ target_link_options(${EXECUTABLE} PRIVATE -lstdc++ -lsupc++ -Wl,--end-group + -Wl,-z,max-page-size=8 # Allow good software remapping across address space (with proper GCC section making) -Wl,--print-memory-usage ) # Execute post-build to print size -add_custom_command(TARGET ${EXECUTABLE} POST_BUILD - COMMAND ${CMAKE_SIZE} $ +add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_SIZE} $ ) # Convert output to hex and binary -add_custom_command(TARGET ${EXECUTABLE} POST_BUILD - COMMAND ${CMAKE_OBJCOPY} -O ihex $ ${EXECUTABLE}.hex +add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_OBJCOPY} -O ihex $ ${CMAKE_PROJECT_NAME}.hex ) # Convert to bin file -> add conditional check? -add_custom_command(TARGET ${EXECUTABLE} POST_BUILD - COMMAND ${CMAKE_OBJCOPY} -O binary $ ${EXECUTABLE}.bin +add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_OBJCOPY} -O binary $ ${CMAKE_PROJECT_NAME}.bin ) - -message("Exiting ${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt") diff --git a/script-projects/h735g-dk-usart/CMakePresets.json b/script-projects/h735g-dk-usart/CMakePresets.json index 788b377..a86b366 100644 --- a/script-projects/h735g-dk-usart/CMakePresets.json +++ b/script-projects/h735g-dk-usart/CMakePresets.json @@ -39,5 +39,23 @@ "CMAKE_BUILD_TYPE": "MinSizeRel" } } + ], + "buildPresets": [ + { + "name": "Debug", + "configurePreset": "Debug" + }, + { + "name": "RelWithDebInfo", + "configurePreset": "RelWithDebInfo" + }, + { + "name": "Release", + "configurePreset": "Release" + }, + { + "name": "MinSizeRel", + "configurePreset": "MinSizeRel" + } ] } \ No newline at end of file diff --git a/script-projects/h735g-dk-usart/README_how_to_build.md b/script-projects/h735g-dk-usart/README_how_to_build.md new file mode 100644 index 0000000..9b72365 --- /dev/null +++ b/script-projects/h735g-dk-usart/README_how_to_build.md @@ -0,0 +1,28 @@ +# How to build the project + +This is a short-version explaining key steps to build project with CMake in VSCode or directly in shell. + +Long version: https://github.com/MaJerle/stm32-cube-cmake-vscode + +## Pre-requisites + +For successful compilation: + +* *CMake* and *Ninja-build* tools installed and available in environment path +* *ARM None Eabi GCC* toolchain installed and available in environment path - if you have installed *STM32CubeIDE*, you have GCC already installed there - find it in directory and add it to env path + +To further download the built project to STM32 hardware: + +* *STM32CubeProgrammer* tool needs to be installed with bin folder in environment path - to have access to *STM32_Programmer_CLI* command - if you have installed *STM32CubeIDE*, you have GCC already installed there - find it in directory and add it to env path + +For debugging from inside VSCode + +* *ST GDB-Server* tool needs to be installed with bin folder in environment path - you get it together with *STM32CubeIDE* package + +## Steps to build the project + +* Open terminal window in folder where `CMakeLists.txt` for your project is located +* Run `cmake --preset Debug` to generate build system for ninja using `Debug` preset, that comes with the default `CMakePresets.json` file +* Run `cmake --build --preset Debug` to actually invoke ninja-build and compile with GCC +* Go to `build/Debug` folder - you will find your `.elf` file there (only if build is a pass). This is default build directory for `Debug` preset that comes with the project +* Clean the project with `cmake --build --preset Debug --target clean` diff --git a/script-projects/h735g-dk-usart/cmake_generated/cmake_generated.cmake b/script-projects/h735g-dk-usart/cmake_generated/cmake_generated.cmake new file mode 100644 index 0000000..8a73ec9 --- /dev/null +++ b/script-projects/h735g-dk-usart/cmake_generated/cmake_generated.cmake @@ -0,0 +1,95 @@ +cmake_minimum_required(VERSION 3.22) + +# Core MCU flags, CPU, instruction set and FPU setup +set(cpu_PARAMS ${cpu_PARAMS} + -mthumb + + # Other parameters + # -mcpu, -mfloat, -mfloat-abi, ... + -mcpu=cortex-m7 + -mfpu=fpv5-d16 + -mfloat-abi=hard +) + +# Set linker script +set(linker_script_SRC ${linker_script_SRC} + ${CMAKE_CURRENT_SOURCE_DIR}/STM32H735IGKX_FLASH.ld +) + +# Sources +set(sources_SRCS ${sources_SRCS} + ${CMAKE_CURRENT_SOURCE_DIR}/Core/Src/main.c + ${CMAKE_CURRENT_SOURCE_DIR}/Core/Src/stm32h7xx_hal_msp.c + ${CMAKE_CURRENT_SOURCE_DIR}/Core/Src/stm32h7xx_it.c + ${CMAKE_CURRENT_SOURCE_DIR}/Core/Src/syscalls.c + ${CMAKE_CURRENT_SOURCE_DIR}/Core/Src/sysmem.c + ${CMAKE_CURRENT_SOURCE_DIR}/Core/Src/system_stm32h7xx.c + ${CMAKE_CURRENT_SOURCE_DIR}/Core/Startup/startup_stm32h735igkx.s + ${CMAKE_CURRENT_SOURCE_DIR}/FATFS/App/fatfs.c + ${CMAKE_CURRENT_SOURCE_DIR}/FATFS/Target/user_diskio.c + ${CMAKE_CURRENT_SOURCE_DIR}/Middlewares/Third_Party/FatFs/src/diskio.c + ${CMAKE_CURRENT_SOURCE_DIR}/Middlewares/Third_Party/FatFs/src/ff.c + ${CMAKE_CURRENT_SOURCE_DIR}/Middlewares/Third_Party/FatFs/src/ff_gen_drv.c + ${CMAKE_CURRENT_SOURCE_DIR}/Middlewares/Third_Party/FatFs/src/option/syscall.c + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal.c + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_cortex.c + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dma.c + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dma_ex.c + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_exti.c + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_flash.c + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_flash_ex.c + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_gpio.c + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_hsem.c + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_i2c.c + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_i2c_ex.c + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_mdma.c + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_pwr.c + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_pwr_ex.c + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rcc.c + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rcc_ex.c + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_tim.c + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_tim_ex.c + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_uart.c + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_uart_ex.c +) + +# Include directories +set(include_c_DIRS ${include_c_DIRS} + ${CMAKE_CURRENT_SOURCE_DIR}/FATFS/Target + ${CMAKE_CURRENT_SOURCE_DIR}/FATFS/App + ${CMAKE_CURRENT_SOURCE_DIR}/Core/Inc + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Inc + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32H7xx_HAL_Driver/Inc/Legacy + ${CMAKE_CURRENT_SOURCE_DIR}/Middlewares/Third_Party/FatFs/src + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/CMSIS/Device/ST/STM32H7xx/Include + ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/CMSIS/Include +) +set(include_cxx_DIRS ${include_cxx_DIRS} + +) +set(include_asm_DIRS ${include_asm_DIRS} + +) + +# Symbols definition +set(symbols_c_SYMB ${symbols_c_SYMB} + "DEBUG" + "USE_HAL_DRIVER" + "STM32H735xx" +) +set(symbols_cxx_SYMB ${symbols_cxx_SYMB} + +) +set(symbols_asm_SYMB ${symbols_asm_SYMB} + "DEBUG" +) + +# Link directories +set(link_DIRS ${link_DIRS} + +) + +# Link directories +set(link_LIBS ${link_LIBS} + +) diff --git a/templates/CMakeLists.txt b/templates/CMakeLists_template.txt similarity index 98% rename from templates/CMakeLists.txt rename to templates/CMakeLists_template.txt index 57158f1..baee69c 100644 --- a/templates/CMakeLists.txt +++ b/templates/CMakeLists_template.txt @@ -59,7 +59,7 @@ link_directories(${CMAKE_PROJECT_NAME} ${link_DIRS}) add_executable(${CMAKE_PROJECT_NAME}) # Add sources to executable -target_sources(${CMAKE_PROJECT_NAME}, ${sources_SRCS}) +target_sources(${CMAKE_PROJECT_NAME} PUBLIC ${sources_SRCS}) # Add include paths target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE diff --git a/templates/cmake-generated/cmake_generated.cmake b/templates/cmake-generated/cmake_generated.cmake deleted file mode 100644 index bf133a4..0000000 --- a/templates/cmake-generated/cmake_generated.cmake +++ /dev/null @@ -1,49 +0,0 @@ -cmake_minimum_required(VERSION 3.22) - -project({{sr:project_name}}) - -# Core MCU flags, CPU, instruction set and FPU setup -set(cpu_PARAMS - -mthumb - - # Other parameters - # -mcpu, -mfloat, -mfloat-abi, ... - {{sr:cpu_params}} -) - -# Set linker script -set(linker_script_SRC {{sr:linker_script_SRC}}) - -# Source files -{{sr:set_source_folder_files}} - -# Include directories -set(include_c_DIRS - {{sr:include_c_DIRS}} -) -set(include_cxx_DIRS - {{sr:include_cxx_DIRS}} -) -set(include_asm_DIRS - {{sr:include_asm_DIRS}} -) - -# Symbols definition -set(symbols_c_SYMB - {{sr:symbols_c_SYMB}} -) -set(symbols_cxx_SYMB - {{sr:symbols_cxx_SYMB}} -) -set(symbols_asm_SYMB - {{sr:symbols_asm_SYMB}} -) - -# Link directories setup -# Must be before executable is added -set(link_DIRS - {{sr:link_DIRS}} -) - -# Executable files -add_executable(${EXECUTABLE} {{sr:set_source_folder_files_variables}}) diff --git a/templates/cmake_generated/cmake_generated_template.cmake b/templates/cmake_generated/cmake_generated_template.cmake new file mode 100644 index 0000000..a9dbd06 --- /dev/null +++ b/templates/cmake_generated/cmake_generated_template.cmake @@ -0,0 +1,52 @@ +cmake_minimum_required(VERSION 3.22) + +# Core MCU flags, CPU, instruction set and FPU setup +set(cpu_PARAMS ${cpu_PARAMS} + -mthumb + + # Other parameters + # -mcpu, -mfloat, -mfloat-abi, ... + {{sr:cpu_params}} +) + +# Set linker script +set(linker_script_SRC ${linker_script_SRC} + {{sr:linker_script_SRC}} +) + +# Sources +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}} +) + +# 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}} +) + +# Link directories +set(link_DIRS ${link_DIRS} + {{sr:link_DIRS}} +) + +# Link directories +set(link_LIBS ${link_LIBS} + {{sr:link_LIBS}} +)