在 vscode + cmake + GNU 工具链的基础上配置 JLINK

server/2025/1/23 0:11:00/

JLINK_0">安装 JLINK

JLINK 官网链接
在这里插入图片描述
下载安装后找到安装路径下的可执行文件
在这里插入图片描述
将此路径添加到环境变量的 Path 中。

创建 JFlash 项目

打开 JFlash,选择新建项目
在这里插入图片描述
选择单片机型号
在这里插入图片描述
在弹出的窗口中搜索单片机
在这里插入图片描述
其他参数根据实际情况填写
在这里插入图片描述
新建完成:
在这里插入图片描述
接下来设置一下项目
在这里插入图片描述
把 Start Application 勾上,复位方式选择通过复位引脚复位。如果没有这个硬件条件则使用软件复位。
在这里插入图片描述
最后保存工程
在这里插入图片描述
在这里插入图片描述

编写 powershell 脚本

新建一个脚本叫 jlink-release-download.ps1

# 项目参数
$project_name = "test"
$cmake_config = "gcc-release"
$project_path = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent
$workspace_path = Split-Path $project_path -Parent
$build_path = "$workspace_path/out/build/$cmake_config"
$install_path = "$workspace_path/out/install/$cmake_config"# 开始操作
New-Item -Path $build_path -ItemType Directory -Force
Push-Location $build_path
try
{cmake -G "Ninja" $workspace_path `--preset "$cmake_config"if ($LASTEXITCODE){throw "配置失败"}ninja -j12if ($LASTEXITCODE){throw "编译失败"}ninja install
}
finally
{Pop-Location
}Push-Location $install_path
try
{arm-none-eabi-objcopy -O binary `"$install_path/bin/${project_name}.elf" `"$install_path/bin/${project_name}.bin"$jflash_arg_array = @("-openprj${workspace_path}/jflash-project.jflash","-open${install_path}/bin/${project_name}.bin,0x8000000","-auto","-startapp","-exit")$jflash_arg = $jflash_arg_array -join " "$jflash_arg = $jflash_arg.Trim()Write-Host $jflash_argStart-Process -FilePath "JFlash.exe" `-ArgumentList $jflash_arg `-WindowStyle Normal `-Waitif ($LASTEXITCODE){throw "将 ${project_name}.bin 下载到单片机失败。"}Write-Host "将 ${project_name}.bin 下载到单片机成功。"
}
finally
{Pop-Location
}

项目参数部分根据实际情况修改。

为 DEBUG 配置也创建一个 powershell 脚本,叫作 jlink-debug-download.ps1

# 项目参数
$project_name = "test"
$cmake_config = "gcc-debug"
$project_path = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent
$workspace_path = Split-Path $project_path -Parent
$build_path = "$workspace_path/out/build/$cmake_config"
$install_path = "$workspace_path/out/install/$cmake_config"# 开始操作
New-Item -Path $build_path -ItemType Directory -Force
Push-Location $build_path
try
{cmake -G "Ninja" $workspace_path `--preset "$cmake_config"if ($LASTEXITCODE){throw "配置失败"}ninja -j12if ($LASTEXITCODE){throw "编译失败"}ninja install
}
finally
{Pop-Location
}Push-Location $install_path
try
{arm-none-eabi-objcopy -O binary `"$install_path/bin/${project_name}.elf" `"$install_path/bin/${project_name}.bin"$jflash_arg_array = @("-openprj${workspace_path}/jflash-project.jflash","-open${install_path}/bin/${project_name}.bin,0x8000000","-auto","-startapp","-exit")$jflash_arg = $jflash_arg_array -join " "$jflash_arg = $jflash_arg.Trim()Write-Host $jflash_argStart-Process -FilePath "JFlash.exe" `-ArgumentList $jflash_arg `-WindowStyle Normal `-Waitif ($LASTEXITCODE){throw "将 ${project_name}.bin 下载到单片机失败。"}Write-Host "将 ${project_name}.bin 下载到单片机成功。"
}
finally
{Pop-Location
}

创建 task.json

vscode 项目根目录下的 .vscode 目录创建 task.json 文件
在这里插入图片描述
填入以下内容:

{"version": "2.0.0","tasks": [{"label": "stflash-release-download","type": "shell","command": "pwsh","args": ["./stflash-release-download.ps1"],"options": {"cwd": "${workspaceFolder}/test"},"problemMatcher": []},{"label": "stflash-debug-download","type": "shell","command": "pwsh","args": ["./stflash-debug-download.ps1"],"options": {"cwd": "${workspaceFolder}/test"},"problemMatcher": []},{"label": "jlink-debug-download","type": "shell","command": "pwsh","args": ["./jlink-debug-download.ps1"],"options": {"cwd": "${workspaceFolder}/test"},"problemMatcher": []},{"label": "jlink-release-download","type": "shell","command": "pwsh","args": ["./jlink-release-download.ps1"],"options": {"cwd": "${workspaceFolder}/test"},"problemMatcher": []},],
}
  • args 是传递给 pwsh 进程的参数,向它传递 ps1 文件。
  • cwd 是启动 pwsh 进程时赋予它的当前路径,将它改成刚刚创建的 ps1 文件所在的目录。

创建 launch.json

vscode 项目根目录的 .vscode 目录创建 launch.json 文件
在这里插入图片描述
填入以下内容

{// 使用 IntelliSense 了解相关属性。// 悬停以查看现有属性的描述。// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387"version": "0.2.0","configurations": [{"name": "ST-Link Debug","preLaunchTask": "stflash-debug-download","cwd": "${workspaceFolder}/out/install/gcc-debug/bin/","executable": "${workspaceFolder}/out/install/gcc-debug/bin/test.elf","request": "launch","type": "cortex-debug","runToEntryPoint": "main","servertype": "stlink","showDevDebugOutput": "raw","liveWatch": {"enabled": true,"samplesPerSecond": 4},},{"name": "JLink Debug","preLaunchTask": "jlink-debug-download","cwd": "${workspaceFolder}/out/install/gcc-debug/bin/","executable": "${workspaceFolder}/out/install/gcc-debug/bin/test.elf","request": "launch","type": "cortex-debug","runToEntryPoint": "main","servertype": "jlink","showDevDebugOutput": "raw","device": "STM32H743II","liveWatch": {"enabled": true,"samplesPerSecond": 4},"serverArgs": ["-if","JTAG"],}]
}

CMakePresets.json

附上我的 CMakePresets.json 文件的内容。这不是本文要讲述的。本文只讲述如何在已经配置好 cmake 和 GNU 工具链的情况下配置 JLINK

{"version": 3,"configurePresets": [{"name": "options","hidden": true,"cacheVariables": {"platform": "arm-none-eabi-cortex-m7","obj_copy": "arm-none-eabi-objcopy","CMAKE_SYSTEM_PROCESSOR": "arm","CMAKE_SYSTEM_ARCH": "armv7-m","CMAKE_SYSTEM_NAME": "Generic","CMAKE_C_COMPILER": "arm-none-eabi-gcc","CMAKE_CXX_COMPILER": "arm-none-eabi-g++","CMAKE_ASM_COMPILER": "arm-none-eabi-gcc","CMAKE_LINKER": "arm-none-eabi-ld","CMAKE_SIZE": "arm-none-eabi-size","CMAKE_STRIP": "arm-none-eabi-ld"},"vendor": {"microsoft.com/VisualStudioSettings/CMake/1.0": {"intelliSenseMode": "linux-gcc-arm","disableExternalAnalysis": true}}},{"name": "gcc-debug","displayName": "gcc-debug","inherits": "options","generator": "Ninja","binaryDir": "${sourceDir}/out/build/${presetName}","installDir": "${sourceDir}/out/install/${presetName}","cacheVariables": {"CMAKE_BUILD_TYPE": "Debug"}},{"name": "gcc-release","displayName": "gcc-release","inherits": "options","generator": "Ninja","binaryDir": "${sourceDir}/out/build/${presetName}","installDir": "${sourceDir}/out/install/${presetName}","cacheVariables": {"CMAKE_BUILD_TYPE": "Release"}}]
}

http://www.ppmy.cn/server/160596.html

相关文章

STM32 FreeRTOS中断管理

目录 FreeRTOS的中断管理 1、STM32中断优先级管理 2、FreeRTOS任务优先级管理 3、寄存器和内存映射寄存器 4、BASEPRI寄存器 5、FreeRTOS与STM32中断管理结合使用 vPortRaiseBASEPRI vPortSetBASEPRI 6、FromISR后缀 7、在中断服务函数中调用FreeRTOS的API函数需注意 F…

电脑如何访问手机文件?

手机和电脑已经深深融入了我们的日常生活,无时无刻不在为我们提供服务。除了电脑远程操控电脑外,我们还可以在电脑上轻松地访问Android或iPhone手机上的文件。那么,如何使用电脑远程访问手机上的文件呢? 如何使用电脑访问手机文件…

Android 11适配全攻略:从理论到实践

随着Google正式发布Android 11,开发者们迎来了新的挑战和机遇。Android 11不仅带来了全新的用户体验和功能提升,还要求开发者们对应用进行相应的适配,以确保应用的兼容性和稳定性。本文将从理论到实践,全面解析Android 11的适配攻…

【Java】阿里云OSS上传、删除文件

阿里云OSS上传、删除文件 编写AliOssConfig&#xff1a; import lombok.Data;/*** <p>DESC: </p>* <p>VERSION:1.0.0</p>*/ Data public class AliOssConfig {private String endpoint;private String accessKey;private String accessSecret;private…

开发常用工具

在项目开发中&#xff0c;工具的使用起到了至关重要的作用&#xff0c;正所谓工欲善其事&#xff0c;必先利其器&#xff0c;掌握一些实用的开发工具能够使我们的开发效率事半功倍。 那么我们应该掌握哪些开发工具的使用方法呢&#xff1f;其实一路走来&#xff0c;我们已经介…

【Go】Go Gin框架初识(一)

1. 什么是Gin框架 Gin框架&#xff1a;是一个由 Golang 语言开发的 web 框架&#xff0c;能够极大提高开发 web 应用的效率&#xff01; 1.1 什么是web框架 web框架体系图&#xff08;前后端不分离&#xff09;如下图所示&#xff1a; 从上图中我们可以发现一个Web框架最重要…

Java-抽象方法

抽象方法&#xff1a; ●抽象方法&#xff1a;将共性的行为&#xff08;方法&#xff09;抽取到父类之后。由于每一个子类执行的内容是不一样&#xff0c;所以&#xff0c;在父类中不能确定具体的方法体。该方法就可以定义为抽象方法。 ●抽象类&#xff1a;如果一个类中存在…

[gpu驱动] H200 nvidia-fabricmanager-550升级到nvidia-fabricmanager-565报错,升级步骤

报错日志: root@h1-12-gpu:/home/canopy# apt install nvidia-fabricmanager-565 Reading package lists... Done Building dependency tree... Done Reading state information... Done Some packages could not be installed. This may mean that you have requested an imp…