You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
162 lines
4.8 KiB
162 lines
4.8 KiB
## vscode 项目改造
|
|
|
|
***### .vscode 目录***
|
|
设置智能感知
|
|
ctrl+shift+P打开Command Palette,运行C/Cpp: Edit configurations...
|
|
c_cpp_properties.json
|
|
```json
|
|
{
|
|
"configurations": [
|
|
{
|
|
"name": "Win32",
|
|
"includePath": [
|
|
"${workspaceFolder}/**"
|
|
],
|
|
"defines": [
|
|
"_DUSE_HAL_DRIVER",
|
|
"_DSTM32F103xE",
|
|
"_DEBUG",
|
|
"UNICODE",
|
|
"_UNICODE"
|
|
],
|
|
"compilerPath": "C:/Program Files (x86)/GNU Arm Embedded Toolchain/10 2021.10/bin/arm-none-eabi-gcc.exe",
|
|
"cStandard": "c99",
|
|
"cppStandard": "c++11",
|
|
"intelliSenseMode": "windows-gcc-x64",
|
|
"configurationProvider": "ms-vscode.makefile-tools"
|
|
}
|
|
],
|
|
"version": 4
|
|
}
|
|
```
|
|
|
|
settings.json
|
|
```json
|
|
|
|
```
|
|
launch.json 需要对应的 svd文件调试
|
|
```json
|
|
{
|
|
// 使用 IntelliSense 了解相关属性。
|
|
// 悬停以查看现有属性的描述。
|
|
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
|
|
"version": "0.2.0",
|
|
"configurations": [
|
|
{
|
|
"cwd": "${workspaceFolder}",
|
|
"executable": "${workspaceRoot}/build/${workspaceFolderBasename}.elf",
|
|
"name": "Debug with ST-Link",
|
|
"request": "launch",
|
|
"type": "cortex-debug",
|
|
"runToEntryPoint": "main",
|
|
"showDevDebugOutput": "none",
|
|
"servertype": "openocd",
|
|
"configFiles": ["${workspaceRoot}/openocd_script/openocd_stlink_stm32f4.cfg"],
|
|
"preLaunchTask": "build",
|
|
"armToolchainPath": "C:/Program Files (x86)/GNU Arm Embedded Toolchain/10 2021.10/bin/",
|
|
"svdFile": "${workspaceRoot}/cmsis-svd/data/STMicro/STM32F407.svd"
|
|
},
|
|
{
|
|
"cwd": "${workspaceFolder}",
|
|
"executable": "${workspaceRoot}/build/${workspaceFolderBasename}.elf",
|
|
"name": "Debug with ST-Link Not Build",
|
|
"request": "launch",
|
|
"type": "cortex-debug",
|
|
"runToEntryPoint": "main",
|
|
"showDevDebugOutput": "none",
|
|
"servertype": "openocd",
|
|
"configFiles": ["${workspaceRoot}/openocd_script/openocd_stlink_stm32f4.cfg"],
|
|
"preLaunchTask": "",
|
|
"armToolchainPath": "C:/Program Files (x86)/GNU Arm Embedded Toolchain/10 2021.10/bin/",
|
|
"svdFile": "${workspaceRoot}/cmsis-svd/data/STMicro/STM32F407.svd"
|
|
},
|
|
{
|
|
"cwd": "${workspaceFolder}",
|
|
"executable": "${workspaceRoot}/build/${workspaceFolderBasename}.elf",
|
|
"name": "Attach ST-Link Not Build",
|
|
"request": "attach",
|
|
"type": "cortex-debug",
|
|
"runToEntryPoint": "main",
|
|
"showDevDebugOutput": "none",
|
|
"servertype": "openocd",
|
|
"configFiles": ["${workspaceRoot}/openocd_script/openocd_stlink_stm32f4.cfg"],
|
|
"preLaunchTask": "",
|
|
"armToolchainPath": "C:/Program Files (x86)/GNU Arm Embedded Toolchain/10 2021.10/bin/",
|
|
"svdFile": "${workspaceRoot}/cmsis-svd/data/STMicro/STM32F407.svd"
|
|
}
|
|
|
|
]
|
|
}
|
|
```
|
|
tasks.json
|
|
```json
|
|
{
|
|
"version": "2.0.0",
|
|
"tasks": [
|
|
{
|
|
"label": "build",
|
|
"type": "shell",
|
|
"command": "make",
|
|
"args": [
|
|
]
|
|
}
|
|
]
|
|
}
|
|
```
|
|
|
|
### 修改时钟 tick
|
|
Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal.c
|
|
|
|
### makefile
|
|
#### 下载
|
|
openocd -v 测试
|
|
|
|
添加文件
|
|
|
|
openocd_script/openocd_stlink_stm32f1.cfg
|
|
```ini
|
|
source [find interface/stlink.cfg]
|
|
source [find target/stm32f1x.cfg]
|
|
```
|
|
openocd_script/openocd_stlink_stm32f4.cfg
|
|
```ini
|
|
source [find interface/stlink.cfg]
|
|
source [find target/stm32f4x.cfg]
|
|
init
|
|
tpiu config internal - uart off 168000000
|
|
itm ports on
|
|
```
|
|
|
|
stlink.cfg 可改为 stlink-v2.cfg
|
|
|
|
makefile 添加
|
|
upload:
|
|
@openocd -f openocd_script/openocd_stlink_stm32f1.cfg -c init -c halt -c "flash write_image erase $(BUILD_DIR)/$(TARGET).bin 0x08000000" -c reset -c shutdown
|
|
|
|
@openocd -f openocd_script/openocd_stlink_stm32f1.cfg -c init -c halt -c "flash write_image erase $(BUILD_DIR)/$(TARGET).bin 0x08000000" -c reset -c shutdown
|
|
@openocd -f openocd_script/openocd_stlink_stm32f1.cfg -c init -c halt -c "program $(BUILD_DIR)/$(TARGET).bin exit 0x08000000"
|
|
@openocd -f openocd_script/openocd_stlink_stm32f1.cfg -c init -c halt -c "program $(BUILD_DIR)/$(TARGET).elf verify reset exit"
|
|
|
|
|
|
### 调试
|
|
|
|
coretex debug插件
|
|
Cortex-Debug: Device Support Pack - STM32F1
|
|
Cortex-Debug: Device Support Pack - STM32F4
|
|
|
|
arm-none-eabi-gdb.exe: warning: Couldn't determine a path for the index cache directory.
|
|
|
|
添加系统变量 HOME C:\users\esea6
|
|
|
|
ST-LINK_gdbserver.exe 必须在系统路径下
|
|
|
|
### LED点亮
|
|
通过 HAL_GPIO_TogglePin 直接操作
|
|
也可以 重写函数 LED_Toggle() 这样语义更清晰
|
|
HAL_GPIO_TogglePin(GPIOB,GPIO_PIN_5);
|
|
HAL_Delay()
|
|
|
|
### FAQ
|
|
1. 编译后,串口输出中文乱码
|
|
-fexec-charset=GBK
|
|
-finput-charset=UTF-8 |