From 0199c1e38f45a750a4539439d3ffa5e0ce672777 Mon Sep 17 00:00:00 2001 From: Bill Finger Date: Sat, 18 Jan 2025 18:26:45 +0300 Subject: [PATCH] Configure clang tools and update build settings - Added `.clang-tidy` with custom checks to enforce code style. - Created `.clangd` with specific compile flag additions and removals. - Updated `.gitignore` to include new cache, metadata, and configuration files. - Updated `platformio.ini`: - Bumped `Simple FOC` to version 2.3.4 and `STM32_CAN` to version 1.1.2. - Added `gen_compile_commands.py` as an extra script. --- controller/fw/embed/.clang-tidy | 1 + controller/fw/embed/.clangd | 18 ++++++++++++++++++ controller/fw/embed/.gitignore | 4 ++++ controller/fw/embed/check_gcc_version.py | 19 +++++++++++++++++++ controller/fw/embed/gen_compile_commands.py | 8 ++++++++ controller/fw/embed/platformio.ini | 5 +++-- 6 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 controller/fw/embed/.clang-tidy create mode 100644 controller/fw/embed/.clangd create mode 100644 controller/fw/embed/check_gcc_version.py create mode 100644 controller/fw/embed/gen_compile_commands.py diff --git a/controller/fw/embed/.clang-tidy b/controller/fw/embed/.clang-tidy new file mode 100644 index 0000000..3f9824b --- /dev/null +++ b/controller/fw/embed/.clang-tidy @@ -0,0 +1 @@ +Checks: '-*, -misc-definitions-in-headers' diff --git a/controller/fw/embed/.clangd b/controller/fw/embed/.clangd new file mode 100644 index 0000000..05f45f8 --- /dev/null +++ b/controller/fw/embed/.clangd @@ -0,0 +1,18 @@ +CompileFlags: + Add: + [ + # -mlong-calls, + -DSSIZE_MAX, + -DLWIP_NO_UNISTD_H=1, + -Dssize_t=long, + -D_SSIZE_T_DECLARED, + ] + Remove: + [ + -fno-tree-switch-conversion, + -mtext-section-literals, + -mlongcalls, + -fstrict-volatile-bitfields, + -free, + -fipa-pta, + ] diff --git a/controller/fw/embed/.gitignore b/controller/fw/embed/.gitignore index 89cc49c..b0e6063 100644 --- a/controller/fw/embed/.gitignore +++ b/controller/fw/embed/.gitignore @@ -3,3 +3,7 @@ .vscode/c_cpp_properties.json .vscode/launch.json .vscode/ipch +.cache/ +.metadata/ +cubemx_config/ +compile_commands.json diff --git a/controller/fw/embed/check_gcc_version.py b/controller/fw/embed/check_gcc_version.py new file mode 100644 index 0000000..41d1176 --- /dev/null +++ b/controller/fw/embed/check_gcc_version.py @@ -0,0 +1,19 @@ +Import("env") + +# Получаем путь к компилятору из окружения PlatformIO +gcc_path = env.subst("$CC") + +# Выполняем команду для получения версии компилятора +import subprocess + +try: + result = subprocess.run([gcc_path, "--version"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) + if result.returncode == 0: + print(f"GCC version: {result.stdout}") + else: + print(f"Failed to get GCC version: {result.stderr}") +except Exception as e: + print(f"Error while getting GCC version: {e}") + +# Дополнительно проверяем путь к компилятору +print(f"Compiler path: {gcc_path}") diff --git a/controller/fw/embed/gen_compile_commands.py b/controller/fw/embed/gen_compile_commands.py new file mode 100644 index 0000000..0537d0b --- /dev/null +++ b/controller/fw/embed/gen_compile_commands.py @@ -0,0 +1,8 @@ +import os +Import("env") + +# include toolchain paths +env.Replace(COMPILATIONDB_INCLUDE_TOOLCHAIN=True) + +# override compilation DB path +env.Replace(COMPILATIONDB_PATH="compile_commands.json") diff --git a/controller/fw/embed/platformio.ini b/controller/fw/embed/platformio.ini index 854186d..74e0b85 100644 --- a/controller/fw/embed/platformio.ini +++ b/controller/fw/embed/platformio.ini @@ -23,5 +23,6 @@ build_flags = -D HAL_CAN_MODULE_ENABLED -D SIMPLEFOC_PWM_LOWSIDE_ACTIVE_HIGH lib_deps = - askuric/Simple FOC@^2.3.2 - pazi88/STM32_CAN@^1.1.0 + askuric/Simple FOC@^2.3.4 + pazi88/STM32_CAN@^1.1.2 +extra_scripts = pre:gen_compile_commands.py