clion+arm-cm3+MSYS-mingw +jlink配置用于嵌入式開發

0.前言

正文可以跳過這段
初識clion,應該是2015年首次發布的時候, 那會還是大三,被一則推介廣告吸引到,當時還在用vs studio,但是就喜歡鼓搗新工具,然后下載安裝試用了clion,但是當時對cmake規則知之甚少,而且覺得還麻煩,所以之后就沒有再用clion了。一晃10年已逝。
從事嵌入式MCU開發工作的,現在用過Keil MDK、IAR、VS-Code、RT-thread studio(eclipse核),現在從我輩楷模這里了解用Clion也能做嵌入式開發,那必須試試,
1.為了從github上 clone 稚暉的項目學習進步;
2.了解多種IDE的開發方式,知己知彼,后續可以根據項目適用哪種平臺,靈活的選擇開發方式:
比如,我現在喜歡RT-Thread Studio,因為基于HAL庫的初始化代碼可以很方面的使用cubemx的ioc工程配置,rt-thread系統的管理 也很方便。
Clion 也可以使用ioc工程完成基于HAL庫的的初始化配置。
所以可以根據項目的特點 選擇最易開發的平臺。
3.另外就是大家說的開源問題,商業軟件都涉及licenses,能用開源的方式還是開源的方式,雖然clion也不是開源的,但是商業化的便捷也可以試試到底有多好用。

參考稚暉君-配置CLion用于STM32開發【優雅の嵌入式開發】,隨著系統版本更新,各軟件也都更新,與時俱進,參考配置的過程也不是一帆風順,故記錄一下,我的配置環境和過程,方便交流學習。

1.環境及所需工具

軟件環境:

軟件名版本號描述
Windows 11
STM32CubeMXV6.5.0官網直達
Clion2024.3.4官網直達
MinGW-W64MSYS2更新最新版官網直達
OpenOCDOpenOCD是用于對STM32進行下載仿真的工具,是一個開源軟件包
arm-none-eabi-gcc

關于交叉編譯工具鏈的詳細可跳轉到我的另外一篇博文windows平臺下交叉編譯工具鏈和環境詳解

硬件環境:

軟件名版本號描述
STM32F103VET6
J-LinkV9

2.需要重點注意的點

稚暉的文檔已經很詳細了,我這里只說點卡點
Clion的配置上,在配置預設的MinGW和Cmake環境上,我是使用MSYS2安裝的MinGW-W64環境,
這是正確的配置圖
Clion工具鏈設置
提供一個錯誤的配置圖,該mingw64-環境 是用于配置rt-thread studio的環境和工具鏈的,這個mingw64-環境是我在其它平臺上正常可以使用的環境,也不知道為什么不能正常工作,這里先將其配置為msys下配置的mingw環境 先解決問題;
在這里插入圖片描述
其實 對于 插件管理式的平臺,針對嵌入式開發 離不開這些環境的配置;比如vscode eclipse clion等。

目前clion的這個環境文件很重要,即使我不更改下面的其它可執行文件,即為配置成這樣也可以正常構建
在這里插入圖片描述

我現在有一個問題是 clion 是 如何查找捆綁的cmake gdb的 ?

上述配置完成后 基本上是可以 構建程序了 完成了很重要的一步。

openocd下載和運行

openocd 在稚暉君的教程中需要配置一下 這個 進入方式
在這里插入圖片描述
進入后需要在該界面下新建一個openocd下載和運行的配置環境,類似于keil里面需要下載什么文件進去,使用什么調試工具。

在這里插入圖片描述

按照教程 配置 和稚暉的區別是他使用的DAP 可能windows下 clion支持挺好的 , 我用的jlink 就出現一個錯誤

使用的stm32f1x.cfg文件內容如下

# 選擇 J-Link 適配器
adapter driver jlink# 選擇 SWD 協議
transport select swd# 配置目標芯片(STM32F103VE)
source [find target/stm32f1x.cfg]

錯誤情況:

Open On-Chip Debugger 0.12.0
Licensed under GNU GPL v2
For bug reports, readhttp://openocd.org/doc/doxygen/bugs.html
Warn : Failed to open device: LIBUSB_ERROR_NOT_SUPPORTED
Error: No J-Link device found

使用 OpenOCD 調試模式

openocd -d3 -f stm32f103c8_blue_pill.cfg

得到的詳細debug 報告

PS D:\MyProjectRepos\MCUDevelopProject\Ctrl-FOC-Lite\2.Firmware\STM32_HAL_version\Ctrl-FOC-Lite-fw> openocd -d3 -f stm32f103c8_blue_pill.cfg
Open On-Chip Debugger 0.12.0
Licensed under GNU GPL v2
For bug reports, readhttp://openocd.org/doc/doxygen/bugs.html
User : 3 2 options.c:52 configuration_output_handler(): debug_level: 3
User : 4 4 options.c:52 configuration_output_handler():
Debug: 5 6 options.c:233 add_default_dirs(): bindir=D:/a/msys64/mingw64/bin
Debug: 6 7 options.c:234 add_default_dirs(): pkgdatadir=D:/a/msys64/mingw64/share/openocd
Debug: 7 9 options.c:235 add_default_dirs(): exepath=D:/msys64/mingw64/bin
Debug: 8 11 options.c:236 add_default_dirs(): bin2data=../share/openocd
Debug: 9 13 configuration.c:33 add_script_search_dir(): adding C:/Users/leesincere/AppData/Roaming/OpenOCD
Debug: 10 16 configuration.c:33 add_script_search_dir(): adding D:/msys64/mingw64/bin/../share/openocd/site
Debug: 11 19 configuration.c:33 add_script_search_dir(): adding D:/msys64/mingw64/bin/../share/openocd/scripts
Debug: 12 22 command.c:155 script_debug(): command - ocd_find stm32f103c8_blue_pill.cfg
Debug: 13 24 configuration.c:88 find_file(): found stm32f103c8_blue_pill.cfg
Debug: 14 28 command.c:155 script_debug(): command - adapter driver jlink
Debug: 15 30 command.c:155 script_debug(): command - transport select swd
Debug: 16 32 command.c:155 script_debug(): command - ocd_find target/stm32f1x.cfg
Debug: 17 35 configuration.c:88 find_file(): found D:/msys64/mingw64/bin/../share/openocd/scripts/target/stm32f1x.cfg
Debug: 18 38 command.c:155 script_debug(): command - ocd_find target/swj-dp.tcl
Debug: 19 41 configuration.c:88 find_file(): found D:/msys64/mingw64/bin/../share/openocd/scripts/target/swj-dp.tcl
Debug: 20 44 command.c:155 script_debug(): command - transport select
Debug: 21 46 command.c:155 script_debug(): command - ocd_find mem_helper.tcl
Debug: 22 48 configuration.c:88 find_file(): found D:/msys64/mingw64/bin/../share/openocd/scripts/mem_helper.tcl
Debug: 23 52 command.c:155 script_debug(): command - add_usage_text mrw address
Debug: 24 54 command.c:155 script_debug(): command - add_help_text mrw Returns value of word in memory.
Debug: 25 56 command.c:155 script_debug(): command - add_usage_text mrh address
Debug: 26 59 command.c:155 script_debug(): command - add_help_text mrh Returns value of halfword in memory.
Debug: 27 62 command.c:155 script_debug(): command - add_usage_text mrb address
Debug: 28 64 command.c:155 script_debug(): command - add_help_text mrb Returns value of byte in memory.
Debug: 29 67 command.c:155 script_debug(): command - add_usage_text mmw address setbits clearbits
Debug: 30 69 command.c:155 script_debug(): command - add_help_text mmw Modify word in memory. new_val = (old_val & ~clearbits) | setbits;
Debug: 31 73 command.c:155 script_debug(): command - transport select
Debug: 32 74 command.c:155 script_debug(): command - expr  [ string first "jtag" $_TRANSPORT ] != -1
Debug: 33 76 command.c:155 script_debug(): command - transport select
Debug: 34 78 command.c:155 script_debug(): command - expr  [ string first "jtag" $_TRANSPORT ] != -1
Debug: 35 81 command.c:155 script_debug(): command - transport select
Debug: 36 82 command.c:155 script_debug(): command - expr  [ string first "swd" $_TRANSPORT ] != -1
Debug: 37 85 command.c:155 script_debug(): command - swd newdap stm32f1x cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id 0x1ba01477
Debug: 38 88 tcl.c:557 jim_newtap_cmd(): Creating New Tap, Chip: stm32f1x, Tap: cpu, Dotted: stm32f1x.cpu, 8 params
Debug: 39 92 core.c:1474 jtag_tap_init(): Created Tap: stm32f1x.cpu @ abs position 0, irlen 0, capture: 0x0 mask: 0x0
Debug: 40 95 command.c:155 script_debug(): command - dap create stm32f1x.dap -chain-position stm32f1x.cpu
Debug: 41 98 command.c:155 script_debug(): command - transport select
Debug: 42 100 command.c:155 script_debug(): command - expr  [ string first "jtag" $_TRANSPORT ] != -1
Debug: 43 103 command.c:155 script_debug(): command - target create stm32f1x.cpu cortex_m -endian little -dap stm32f1x.dap
Debug: 44 107 command.c:289 register_command(): command 'tpiu' is already registered
Debug: 45 109 command.c:289 register_command(): command 'rtt' is already registered
Debug: 46 111 command.c:155 script_debug(): command - stm32f1x.cpu configure -work-area-phys 0x20000000 -work-area-size 0x1000 -work-area-backup 0
Debug: 47 115 target.c:2199 target_free_all_working_areas_restore(): freeing all working areas
Debug: 48 118 target.c:2199 target_free_all_working_areas_restore(): freeing all working areas
Debug: 49 120 target.c:2199 target_free_all_working_areas_restore(): freeing all working areas
Debug: 50 123 command.c:155 script_debug(): command - flash bank stm32f1x.flash stm32f1x 0x08000000 0 0 0 stm32f1x.cpu
Debug: 51 126 tcl.c:1305 handle_flash_bank_command(): 'stm32f1x' driver usage field missing
Debug: 52 129 command.c:155 script_debug(): command - adapter speed 1000
Debug: 53 132 adapter.c:251 adapter_config_khz(): handle adapter khz
Debug: 54 134 adapter.c:215 adapter_khz_to_speed(): convert khz to adapter specific speed value
Debug: 55 136 adapter.c:215 adapter_khz_to_speed(): convert khz to adapter specific speed value
Debug: 56 139 command.c:155 script_debug(): command - adapter srst delay 100
Debug: 57 142 command.c:155 script_debug(): command - transport select
Debug: 58 144 command.c:155 script_debug(): command - expr  [ string first "jtag" $_TRANSPORT ] != -1
Debug: 59 147 command.c:155 script_debug(): command - reset_config srst_nogate
Debug: 60 149 command.c:155 script_debug(): command - transport select
Debug: 61 150 command.c:155 script_debug(): command - expr  [ string first "hla" $_TRANSPORT ] != -1
Debug: 62 153 command.c:155 script_debug(): command - cortex_m reset_config sysresetreq
Debug: 63 155 command.c:155 script_debug(): command - stm32f1x.cpu configure -event examine-end# DBGMCU_CR |= DBG_WWDG_STOP | DBG_IWDG_STOP |#              DBG_STANDBY | DBG_STOP | DBG_SLEEPmmw 0xE0042004 0x00000307 0Debug: 64 161 command.c:155 script_debug(): command - tpiu create stm32f1x.tpiu -dap stm32f1x.dap -ap-num 0 -baseaddr 0xE0040000
Debug: 65 165 command.c:155 script_debug(): command - stm32f1x.tpiu configure -event pre-enable _proc_pre_enable_stm32f1x.tpiu stm32f1x.cpu
Debug: 66 169 command.c:155 script_debug(): command - adapter speed 10000
Debug: 67 171 adapter.c:251 adapter_config_khz(): handle adapter khz
Debug: 68 173 adapter.c:215 adapter_khz_to_speed(): convert khz to adapter specific speed value
Debug: 69 176 adapter.c:215 adapter_khz_to_speed(): convert khz to adapter specific speed value
User : 70 179 options.c:52 configuration_output_handler(): adapter speed: 10000 kHz
User : 71 181 options.c:52 configuration_output_handler():
Info : 72 184 server.c:297 add_service(): Listening on port 6666 for tcl connections
Info : 73 187 server.c:297 add_service(): Listening on port 4444 for telnet connections
Debug: 74 189 command.c:155 script_debug(): command - init
Debug: 75 191 command.c:155 script_debug(): command - target init
Debug: 76 193 command.c:155 script_debug(): command - target names
Debug: 77 195 command.c:155 script_debug(): command - stm32f1x.cpu cget -event gdb-flash-erase-start
Debug: 78 198 command.c:155 script_debug(): command - stm32f1x.cpu configure -event gdb-flash-erase-start reset init
Debug: 79 201 command.c:155 script_debug(): command - stm32f1x.cpu cget -event gdb-flash-write-end
Debug: 80 204 command.c:155 script_debug(): command - stm32f1x.cpu configure -event gdb-flash-write-end reset halt
Debug: 81 208 command.c:155 script_debug(): command - stm32f1x.cpu cget -event gdb-attach
Debug: 82 210 command.c:155 script_debug(): command - stm32f1x.cpu configure -event gdb-attach halt 1000
Debug: 83 213 target.c:1657 handle_target_init_command(): Initializing targets...
Debug: 84 215 semihosting_common.c:109 semihosting_common_init():
Debug: 85 217 jlink.c:635 jlink_init(): Using libjaylink 0.4.0 (compiled with 0.4.0)
Debug: 86 235 jlink.c:514 jaylink_log_handler(): Found device (VID:PID = 1366:0101, bus:address = 001:018)
Warn : 87 238 jlink.c:514 jaylink_log_handler(): Failed to open device: LIBUSB_ERROR_NOT_SUPPORTED
Debug: 88 241 jlink.c:514 jaylink_log_handler(): Found 0 USB device(s)
Error: 89 242 jlink.c:688 jlink_init(): No J-Link device found
Debug: 90 244 command.c:544 run_command(): Command 'init' failed with error code -100
User : 91 247 command.c:608 command_run_line():
Debug: 92 249 target.c:2199 target_free_all_working_areas_restore(): freeing all working areas

根據調試日志分析,根本原因是 ?Windows 系統下 libusb 與 SEGGER 官方驅動沖突,導致 OpenOCD 無法正確訪問 J-Link 設備。以下是逐行解析和終極解決方案:

?錯誤日志關鍵點分析
?Found device (VID:PID = 1366:0101)
J-Link 設備已被系統識別,VID/PID 正確。
?Failed to open device: LIBUSB_ERROR_NOT_SUPPORTED
OpenOCD 的 libjaylink 庫嘗試通過 libusb 訪問 J-Link,但被系統拒絕。
?No J-Link device found
最終因驅動沖突導致設備訪問失敗。
?根本原因
?Windows 系統同時存在 libusb 和 SEGGER 驅動,OpenOCD 默認優先使用 libusb,但 SEGGER 官方驅動已獨占設備訪問權。
?OpenOCD 配置未完全禁用 libusb,導致底層庫(libjaylink)仍嘗試通過 libusb 通信。

但是嘗試了很多辦法 不知道如何使clion使用segger的驅動,也嘗試了禁用libusb在cfg文件內加入以下代碼 好像無效,

# 禁用 libusb,強制使用 SEGGER 驅動
jlink config use_libusb false
jlink usb 0

根據wiki 文檔 那segger+jlink就不是一個好的調試選項,因為切換后,因為他更換了jlink的驅動程序,使用keil iar 等程序時,就不太好用了,
那不如換調試器了,DAP或者st link

總結

至此,總算是能完成的搭建好 構建 debug的環境配置了,盡管jlink+openocd不是一個聯合調試的好選項。

參考

1.參考1 解決openocd無法識別jlink的問題LIBUSB_ERROR_NOT_SUPPORTED
2.解決libusb問題參考2
3.segger wiki原參考文檔

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/web/71709.shtml
繁體地址,請注明出處:http://hk.pswp.cn/web/71709.shtml
英文地址,請注明出處:http://en.pswp.cn/web/71709.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

藍橋杯備考:離散化詳解

首先,為什么要有離散化呢? 比如這道題,我們應該開一個差分數組,但是a,b之間的間隔可是太大了,難道我們要開一個2的三十二次方大小的數組嗎?我們也是開不了這么大的數組的 我們就需要把這些數離…

初學者快速入門Python爬蟲 (無廢話版)

全篇大概 5000 字(含代碼),建議閱讀時間 40min 一、Python爬蟲簡介 1.1 什么是網絡爬蟲? 定義: 網絡爬蟲(Web Crawler)是自動瀏覽互聯網并采集數據的程序,就像電子蜘蛛在網頁間"爬行"。 分類&…

Day05 實例:正向反向連接內外網環境防火墻出入站

一、正反向連接 0、先將防火墻關閉 Linux: sudo systemctl stop firewalld Windows:netsh advfirewall set allprofiles state off 1、正向連接 1.1 Linux連接Windows 00x1 開啟兩臺服務器 并且給Windows拖入nc.exe 00x2 Windows綁定自己5566端…

電力系統中各參數的詳細解釋【智能電表】

一、核心電力參數 電壓 (Voltage) 單位:伏特(V) 含義:電勢差,推動電流流動的動力 類型:線電壓(三相系統)、相電壓,如220V(家用)或380V&#xff…

【仿muduo庫one thread one loop式并發服務器實現】

文章目錄 一、項目介紹1-1、項目總體簡介1-2、項目開發環境1-3、項目核心技術1-4、項目開發流程1-5、項目如何使用 二、框架設計2-1、功能模塊劃分2-1-1、SERVER模塊2-1-2、協議模塊 2-2、項目藍圖2-2-1、整體圖2-2-2、模塊關系圖2-2-2-1、Connection 模塊關系圖2-2-2-2、Accep…

Ubuntu 下 nginx-1.24.0 源碼分析 - ngx_cycle_modules

聲明在 src/core/ngx_module.h ngx_int_t ngx_cycle_modules(ngx_cycle_t *cycle);實現在 src/core/ngx_module.c ngx_int_t ngx_cycle_modules(ngx_cycle_t *cycle) {/** create a list of modules to be used for this cycle,* copy static modules to it*/cycle->modul…

Vue3實戰學習(IDEA中打開、啟動與搭建Vue3工程極簡腳手架教程(2025超詳細教程)、Windows系統命令行啟動Vue3工程)(2)

目錄 一、命令行中重新啟動已搭建好的Vue3工程。(快速上手) (0)Windows環境下使用命令行從零到一手動搭建Vue3工程教程。 (1)首先找到已建Vue3工程的目錄。 (2)無需再下載依賴包,直接執行npm ru…

使用websocket,注入依賴service的bean為null

問題:依賴注入失敗,service獲取不到,提示null 這是參考代碼 package com.shier.ws;import cn.hutool.core.date.DateUtil; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; import com.google.gson.Gson; import com.s…

《A++ 敏捷開發》- 18 軟件需求

需求并不是關于需求 (Requirements are not really about requirements) 大家去公共圖書館寄存物品,以前都是掃二維碼開箱,有些圖書館升級了使用指紋識別。 “是否新方法比以前好?”我問年輕的開發人員。 “當然用指紋識別好。新技術&#x…

基于AMD AU15P FPGA的SLVS-EC橋PCIe設計方案分享

作者:Hello,Panda 各位FPGAer周末愉快,今天熊貓君分享一個基于AMD AU15P FPGA的SLVS-EC橋PCIe設計方案。 一、方案背景 先說方案的應用背景:眾所周知,較為上層的如基于AI的機器視覺應用,大多基于高端的專用SoC、AI專…

Redis|Springboot集成Redis

文章目錄 總體概述本地Java連接Redis常見問題集成Jedis集成lettuce集成RedisTemplate——推薦使用連接單機連接集群 總體概述 jedis-lettuce-RedisTemplate三者的聯系 jedis第一代lettuce承上啟下redistemplate著重使用 本地Java連接Redis常見問題 bind配置請注釋掉保護模式…

機器學習(六)

一,決策樹: 簡介: 決策樹是一種通過構建類似樹狀的結構(顛倒的樹),從根節點開始逐步對數據進行劃分,最終在葉子節點做出預測結果的模型。 結構組成: 根節點:初始的數據集…

恢復IDEA的Load Maven Changes按鈕

寫代碼的時候不知道點到什么東西了,pom文件上的這個彈窗就是不出來了,重啟IDEA,reset windos都沒用,網上搜也沒收到解決方案 然后開打開其他項目窗口時,看到那個的功能名叫 Hide This Notification 于是跑到Setting里…

怎么使用Sam Helper修改手機屏幕分辨率,使得游戲視野變廣?

1.準備Shizuku 和Sam Helper軟件 2.打開設置,找到關于本機,連續點擊版本號五次打開開發者選項 3.找到開發者選項,打開USB調試和無線調試 4.返回桌面,我們接著打開shizuku,點擊配對,這里打開開發者選項,找…

【招聘精英】

我們公司是一個位于石家莊的一個科技型新型技術公司。主要做人力資源、用工、科技等方面。 有意向回石家莊的或者已經在石家莊的技術大咖、軟件大牛、產品大佬、UI大神可以來了解一下。 現在招聘 高級前端開發 高級java開發 其他崗位也可以聯系。 有意向的朋友可以私信我。 -…

大模型信息整理

1. Benchmarks Reasoning, conversation, Q&A benchmarks HellaSwagBIG-Bench HardSQuADIFEvalMuSRMMLU-PROMT-BenchDomain-specific benchmarks GPQAMedQAPubMedQAMath benchmarks GSM8KMATHMathEvalSecurity-related benchmarks PyRITPurple Llama CyberSecEval2. 國內外…

Redis-限流方案

在實際業務中,可能會遇到瞬時流量劇增的情況,大量的請求可能會導致服務器過載和宕機。為了保護系統自身和上下游服務,需要采用限流的方式,拒絕部分請求。 限流就是對請求的頻率進行控制,迅速拒絕超過請求閾值的請求。 …

無感方波開環強拖總結

一、強拖階段的核心原理與設計要點 開環換相邏輯 固定頻率斜坡:以預設斜率逐步提升換相頻率(如0.5-5Hz/ms),強制電機跟隨磁場旋轉。電壓-頻率協調控制:初始階段施加高電壓(80%-100%額定)克服靜摩…

Java虛擬機之垃圾收集(一)

目錄 一、如何判定對象“生死”? 1. 引用計數算法(理論參考) 2. 可達性分析算法(JVM 實際使用) 3. 對象的“緩刑”機制 二、引用類型與回收策略 三、何時觸發垃圾回收? 1. 分代回收策略 2. 手動觸發…

代碼隨想錄算法訓練營第22天 | 組合 組合總和 電話號碼的字母組合

77. 組合 77. 組合 - 力扣&#xff08;LeetCode&#xff09; class Solution {List<Integer> path new ArrayList<>();List<List<Integer>> result new ArrayList<>();public void backTracking(int n,int k,int startIndex){if(path.size() …