VSCode + EIDE开发记录
环境:Win10, VSCode + Embedded IDE扩展,使用Cortex-Debug进行调试。
使用CubeMX进行代码生成并在VSCode+EIDE中编辑和编译、调试
- 首先使用CubeMX配置好时钟、外设等,然后生成工程,其中:Project Manager/Project/Toolchain IDE项目,如使用MDK-ARM,则在其后的EIDE中应设置AC5或AC6编译器进行编译,如使用Makefile,则使用GCC编译器。
- 打开VSCode,如选择使用MDK来生成工程,则直接使用EIDE扩展以导入MDK工程的方式来打开工程;如选择使用Makefile的方式生成工程,则首先使用EIDE扩展创建工程,并手动设置好源码目录,头文件查找目录等,添加好xxx.s文件到源码工程(右键Project Resources -> Add file来添加文件到项目中进行编译)。注意要在Project Attributes->Preprocessor Definitions中加入如下宏:USE_HAL_DRIVER和STM32F303x8,其中,STM32F303x8取决于你用的什么MCU,如果你知道你的MCU型号但是不知道对应的宏的话可以查看源码Drivers/CMSIS/Device/ST/STM32FXxx/Include目录,这里的Xxx是你生成工程时候自动生成的。
- 如遇到编译xxx.s的文件出错,查看编译器是否选对了,可以查看xxx.s的头部注释,例如:
/**
******************************************************************************
* @file startup_stm32f303x8.s
* @author MCD Application Team
* @brief STM32F303x6/STM32F303x8 devices vector table for GCC toolchain.
* This module performs:
* - Set the initial SP
* - Set the initial PC == Reset_Handler,
* - Set the vector table entries with the exceptions ISR address,
* - Configure the clock system
* - Branches to main in the C library (which eventually
* calls main()).
* After Reset the Cortex-M4 processor is in Thread mode,
* priority is Privileged, and the Stack is set to Main.
******************************************************************************
* @attention
*
* Copyright (c) 2016 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
这里的STM32F303x6/STM32F303x8 devices vector table for GCC toolchain.
就表明了这个xxx.s文件是使用gcc的汇编格式来使用的。
如果是STM32F303x6/x8 devices vector table for MDK-ARM toolchain.
则表示是用ARMCC的汇编格式来使用的。
- 注意选择好Builder Configurations->CPU Type,以及设置好Linker Script File Path文件名,默认的文件名不可用。
C/C++ IntelliSense设置
- 打开当前目录下的.vscode/c_cpp_properties.json
- 修改compilerPath为gcc编译器路径,例如:
"compilerPath": "C:/Users/yinsua/.eide/tools/gcc_arm/bin/arm-none-eabi-gcc.exe",
- 建议修改C标准为c11:
"cStandard": "c11",
- 重启VSCode,用EIDE打开工程。
- 尝试代码补全。
一般重启VSCode后,下方ouput会出现如下log
[8/28/2024, 11:33:47 AM] For C++ source files, IntelliSenseMode was changed from "windows-gcc-x64" to "windows-gcc-arm" based on compiler args and querying compilerPath: "C:/Users/yinsua/.eide/tools/gcc_arm/bin/arm-none-eabi-gcc.exe"
[8/28/2024, 11:33:47 AM] For C source files, IntelliSenseMode was changed from "windows-gcc-x64" to "windows-gcc-arm" based on compiler args and querying compilerPath: "C:/Users/yinsua/.eide/tools/gcc_arm/bin/arm-none-eabi-gcc.exe"
Cortex-Debug调试
- 检查launch.json中是否已添加Cortex-Debug配置
- 修改executable为当前程序的elf文件格式输出名
- 如果是OpenOCD,则填充configFiles内容
Cortex-Debug + OpenOCD调试STM32F4x示例:
{
"cwd": "${workspaceRoot}",
"executable": "./build/Debug/eide_stm32f411ceu6_test.elf",
"name": "Debug with OpenOCD",
"request": "launch",
"type": "cortex-debug",
"servertype": "openocd",
"configFiles": [
"interface/cmsis-dap.cfg",
"target/stm32f4x.cfg"
],
"searchDir": [],
"runToEntryPoint": "main",
"showDevDebugOutput": "none"
}
也可添加如下内容来增加对其它调试功能的支持:
"svdFile": "${workspaceRoot}/.vscode/STM32F303.svd",
"swoConfig": {
"enabled": true,
"cpuFrequency": 8000000,
"swoFrequency": 2000000,
"source": "probe",
"decoders": [
{ "type": "console", "label": "ITM", "port": 0 }
]
}