Ubuntu 下 ODrive 固件開發環境搭建
以下内容适用于希望修改ODrive固件的開發人員。是以,它假定您了解諸如如何使用Git,什麼是編譯器之類的知識。如果這聽起來很陌生,以下内容對您來說可能不适合。
注意:所使用的 Ubuntu 版本為 Ubuntu18.04
文章目錄
- Ubuntu 下 ODrive 固件開發環境搭建
- 1 Visual Studio Code
-
- 1.1 安裝 Visual Studio Code
- 1.2 安裝 Visual Studio Code 擴充插件
- 2 安裝 make & make-guile
- 3 安裝 tup
- 4 安裝 gcc-arm-embedded 工具鍊
- 5 安裝 openocd
- 6 安裝 git
- 7 設定 python3 為預設 python
- 8 嘗試編譯固件源碼
- 9 完成開發環境搭建
-
- 9.1 建構工程
- 9.2 燒錄固件
- 9.3 調試
- 9.4 清除建構檔案
1 Visual Studio Code
1.1 安裝 Visual Studio Code
- Visual Studio Code 官網下載下傳連結:https://code.visualstudio.com/download
-
百度網盤下載下傳連結:
連結 https://pan.baidu.com/s/1osfaEsfw5dNKcDjoJhrrRQ
提取碼 zxgy
輕按兩下下載下傳到的 Visual Studio Code_1.42.0-1580986622_amd64.deb 安裝包,按照提示保持預設安裝即可。
1.2 安裝 Visual Studio Code 擴充插件
- 所需擴充插件:
- C/C++
- Cortex-Debug
- 推薦安裝的擴充插件:
- Include Autocomplete
- Path Autocomplete
- Auto Comment Blocks
插件安裝方法:
- 啟動 Visual Studio Code
- 點選紅框
- 在紅框内輸入 vscode Enter
- 單擊 Visual Studio Code 圖示已啟動
- 點選紅框打開插件管理視圖
- 在紅框中輸入要安裝插件的名稱 (如:C/C++) 回車
- 點選紅框中的 Install 安裝
- 等待安裝完成即可
注意: 安裝完所需插件後請關閉 Visual Studio Code 再進行下邊的步驟
2 安裝 make & make-guile
sudo apt install make
sudo apt install make-guile
驗證安裝是否正确
make --version
3 安裝 tup
sudo add-apt-repository ppa:jonathonf/tup && sudo apt-get update && sudo apt-get install tup
驗證安裝是否正确
4 安裝 gcc-arm-embedded 工具鍊
sudo add-apt-repository ppa:team-gcc-arm-embedded/ppa && sudo apt update && sudo apt install gcc-arm-embedded
驗證安裝是否正确
arm-none-eabi-gcc --version
5 安裝 openocd
sudo apt-get install openocd
驗證安裝是否正确
6 安裝 git
驗證安裝是否正确
git --version
7 設定 python3 為預設 python
由于 Ubuntu18.04 預設已安裝 python3,是以隻需要設定 python3 為預設的 python 即可
sudo rm -f /usr/bin/python
sudo ln -s /usr/bin/python3 /usr/bin/python
驗證安裝是否正确
python --version
8 嘗試編譯固件源碼
推薦使用 git clone ODrive 固件源碼到本地,但是由于政策問題 clone 會非常慢,是以,下面提供了額外的百度網盤下載下傳連結。
- github
-
百度網盤下載下傳:
連結 https://pan.baidu.com/s/1RVbYDL99u2blRTe4mNc5dQ
提取碼 mjq4
注意:以下使用
百度網盤下載下傳位址
下載下傳的固件進行編譯
解壓
ODrive-fw-v0.4.11-19-g1c947631.zip
進入
ODrive-fw-v0.4.11-19-g1c947631
檔案夾,滑鼠右鍵單擊
ODrive_Workspace.code-workspace
檔案,點選 Open With Other Application,然後選擇 Visual Studio Code 打開
單擊紅框中的
tup.config.default
檔案,配置硬體版本,修改為如下代碼:
# Copy this file to tup.config and adapt it to your needs
# make sure this fits your board
CONFIG_BOARD_VERSION=v3.5-24V
CONFIG_USB_PROTOCOL=native
CONFIG_UART_PROTOCOL=ascii
CONFIG_DEBUG=false
# Uncomment this to error on compilation warnings
#CONFIG_STRICT=true
然後将
tup.config.default
檔案重命名為
tup.config
然後儲存。
依次點選菜單中的 Terminal -> Run Build Task… 等待建構、編譯完成
雖然編譯完成了,但是上邊的建構過程存在一些問題,這是由于我們使用的源碼包而不是通過 git clone 到本地的(如果是通過 git clone 到本地則不存在這個問題),是以執行 version.py 腳本時無法正确擷取固件版本資訊。可以修改一下 version.py 内部代碼,不通過 git 指令擷取版本資訊而是手動填寫版本資訊。修改 version.py 内第22行 get_version_from_git() 函數如下:
修改前:
def get_version_from_git():
script_dir = os.path.dirname(os.path.realpath(__file__))
try:
# Determine the current git commit version
git_tag = subprocess.check_output(["git", "describe", "--always", "--tags", "--dirty=*"],
cwd=script_dir)
git_tag = git_tag.decode(sys.stdout.encoding).rstrip('\n')
(major, minor, revision, is_prerelease) = version_str_to_tuple(git_tag)
# if is_prerelease:
# revision += 1
return git_tag, major, minor, revision, is_prerelease
except Exception as ex:
print(ex)
return "[unknown version]", 0, 0, 0, 1
修改後:
def get_version_from_git():
return "fw-v0.4.11-19-g1c947631*", 0, 4, 11, True
9 完成開發環境搭建
9.1 建構工程
- Terminal -> Run Build Task…
終端視窗将被打開。VSCode配置會在此終端中運作指令
make -j4
,來編譯工程。
9.2 燒錄固件
- Terminal -> Run Task… -> flash
終端視窗将被打開。 VSCode配置會在此終端中運作指令
make flash
,來燒錄固件。
9.3 調試
Cortex-Debug 擴充插件,專門用于調試ARM Cortex項目。 您可以在此處閱讀有關Cortex-Debug的更多資訊:https://github.com/Marus/cortex-debug
- 確定将固件源碼檔案夾作為目前檔案夾
- 用最新固件加載到ODrive (如果使用調試模式可以不需要此操作)
- 點選Debug -> Start Debugging (或鍵盤 F5)
- 處理器将重置并進入暫停
- 設定斷點。注意: 您隻能在處理器暫停時設定斷點,如果在運作模式下設定斷點,則不會應用它們
- 運作 (F5)
- Stepping over/in/out, 重新運作, 按下
(F6) 按鈕然後重新設定斷點等pause
- 當調試完畢後,您可以按下
(Shift+F5) 停止調試。同時它會自動關閉openOCDstop
9.4 清除建構檔案
如果您想建構新的代碼分支您可能需要清理建構時生成的檔案。
- 打開指令終端 (View -> Terminal) 然後在指令終端中輸入
回車make clean
如果您有任何問題或疑問,歡迎您加入ODrive社群或QQ群 851421965 進行交流。