编译
mkdir build
cd build
cmake .. -G"Unix Makefiles"
make -j
或者
cmake -Bbuild -G"Unix Makefiles"
cmake --build build
创建快捷指令:
删除 .vscode/tasks.json,
存储占用和生成 MAP
编译完成后,打印内存占用:在 cmake/gcc.cmake 中添加
-Wl,--gc-sections,--print-memory-usage
生成 map 文件,添加
-Wl,-Map=${PROJECT_NAME}.map,--cref
总体为:
SET(CMAKE_C_LINK_EXECUTABLE "\"${CMAKE_LINKER}\" ${CMAKE_EXE_LINKER_FLAGS} <OBJECTS> -Wl,--start-group ${RASC_CMAKE_EXE_LIBRARY_NAME_FLAGS} -Wl,--end-group -Wl,-Map=${PROJECT_NAME}.map,--cref -Wl,--gc-sections,--print-memory-usage")
SET(CMAKE_CXX_LINK_EXECUTABLE "\"${CMAKE_LINKER}\" ${CMAKE_EXE_LINKER_FLAGS} <OBJECTS> -Wl,--start-group ${RASC_CMAKE_EXE_LIBRARY_NAME_FLAGS} -Wl,--end-group -Wl,-Map=${PROJECT_NAME}.map,--cref -Wl,--gc-sections,--print-memory-usage")
效果:
Memory region Used Size Region Size %age UsedITCM: 0 GB 0 GBDTCM: 0 GB 0 GBFLASH: 5856 B 2 MB 0.28%RAM: 1360 B 640 KB 0.21%DATA_FLASH: 0 GB 64 KB 0.00%QSPI_FLASH: 0 GB 64 MB 0.00%OSPI_DEVICE_0: 0 GB 0 GBOSPI_DEVICE_1: 0 GB 0 GB
OSPI_DEVICE_0_RAM: 0 GB 0 GB
OSPI_DEVICE_1_RAM: 0 GB 0 GBSDRAM: 0 GB 128 MB 0.00%OPTION_SETTING: 0 GB 0 GB
OPTION_SETTING_OFS: 0 GB 24 B 0.00%
OPTION_SETTING_SAS: 0 GB 0 GB
OPTION_SETTING_S: 0 GB 0 GBID_CODE: 16 B 16 B 100.00%
显示图标
删除 .vscode/settings.json,删除前(左)对比删除后(右)
Git 忽略
build
*.d
*.sbd
.vscode/settings.json
pyocd
如果识别不到调试器,请尝试 python 3.10.10 安装 pyocd;
如果没有pyocd指令,记得将C:\Users\xxx\AppData\Roaming\Python\Python310\Scripts路径加入环境变量;
调试
如果不将工具链添加到环境路径,则需要在 launch.json 中指定:
"armToolchainPath": "D:/Applications/Toolchain/arm-gnu-toolchain-13.2.Rel1-mingw-w64-i686-arm-none-eabi/bin"
快捷
配置 tasks.json 使用快捷指令
{// See https://go.microsoft.com/fwlink/?LinkId=733558// for the documentation about the tasks.json format"version": "2.0.0","tasks": [{"label": "prebuild","type": "shell","command": "cmake -Bbuild -G\"Unix Makefiles\""},{"label": "build","type": "shell","command": "cmake --build build -j","problemMatcher": [],"group": {"kind": "build","isDefault": true}}]
}