> For the complete documentation index, see [llms.txt](https://taiphoon-com.gitbook.io/taiphoon.com-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://taiphoon-com.gitbook.io/taiphoon.com-docs/support/knowledge-base/stm32cubeprogrammer.md). Agents can also search and read this documentation through its [MCP server](https://taiphoon-com.gitbook.io/taiphoon.com-docs/~gitbook/mcp).

# 使用 STM32CubeProgrammer 燒錄

透過 USB DFU 模式，將韌體檔案寫入飛控。此流程以 Morakot 與 ArduPilot 的 `arducopter_with_bl.hex` 為例。

## 準備工具與韌體

* 從 [ST 官方網站](https://www.st.com/en/development-tools/stm32cubeprog.html)下載並安裝 STM32CubeProgrammer。
* 準備對應飛控型號與硬體版本的 `.hex` 或`.bin` 等韌體檔案。需要取得指定版本時，聯絡 <service@taiphoon.com.tw>。
* 使用可傳輸資料的 USB 線連接飛控與電腦。

{% hint style="warning" %}
先卸下螺旋槳。燒錄期間保持供電與 USB 連線，等待程式完成。韌體檔案或寫入位址錯誤，可能使飛控無法正常啟動。
{% endhint %}

{% stepper %}
{% step %}

### 進入 DFU 模式

先拔除 USB，按住飛控的 Boot 按鍵再插入 USB 線，讓飛控進入 DFU 模式。Windows 可在裝置管理員確認是否出現 DFU 裝置，名稱可能顯示為 **STM32 BOOTLOADER** 或 **DFU in FS Mode**。

<figure><img src="https://160136817-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEhjsOwJXR5yBqExlT0G0%2Fuploads%2F8TKhXzCOQpmxXYaYLLJU%2Fimage.png?alt=media&#x26;token=6d8c9296-78dc-4344-b986-7cbac871060f" alt=""><figcaption></figcaption></figure>

<figure><img src="https://401369577-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmvFqg0h5Ob1pRXspm7Yi%2Fuploads%2FAEGC1HcKxSIoCJ8yLTSp%2Fstm32-dfu-device-manager.png?alt=media&amp;token=daf4d13e-0fc6-4e47-a48d-5a03f1521469" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

### 以 USB 連接飛控

開啟 STM32CubeProgrammer，在右側連線介面選擇 **USB**，確認 DFU 裝置已列出，再按 **Connect**。

<figure><img src="https://160136817-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEhjsOwJXR5yBqExlT0G0%2Fuploads%2F3dP5X2OEpZdPVafizR8l%2Fimage.png?alt=media&#x26;token=08a189f6-f9f1-4683-a5c7-24124e0cf310" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

### 全片擦除

連線後點左側第二個圖示切換到 **Erasing & Programming** 頁面，在 **Erase flash memory** 分頁按 **Full chip erase**（全片擦除）。確認視窗（Are you sure you want to erase full chip flash memory?）按 **確定**，等待出現 `Mass erase command correctly executed.` 後按 **確定**。

<figure><img src="https://401369577-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmvFqg0h5Ob1pRXspm7Yi%2Fuploads%2FxbiHcrRlYBEQ7ucwMgxI%2Fstm32-erasing-programming.png?alt=media&amp;token=8274a1a0-b2d5-4c64-8576-0f5b96085da3" alt=""><figcaption></figcaption></figure>

<figure><img src="https://401369577-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmvFqg0h5Ob1pRXspm7Yi%2Fuploads%2FYChIudmItAs7txm8DwDu%2Fstm32-full-chip-erase-confirm.png?alt=media&amp;token=51edade4-5860-4648-b22e-560f465fe479" alt=""><figcaption></figcaption></figure>

<figure><img src="https://401369577-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmvFqg0h5Ob1pRXspm7Yi%2Fuploads%2Fp1Ju4bXa20Gw8eUzWeOb%2Fstm32-full-chip-erase-complete.png?alt=media&amp;token=c64e06ee-1c41-488f-9e66-212a1b537866" alt=""><figcaption></figcaption></figure>

{% hint style="warning" %}
全片擦除會清除飛控快閃記憶體中的所有內容，包含 bootloader 與韌體。擦除後需燒錄含 bootloader 的韌體檔案（例如 `arducopter_with_bl.hex`），飛控才能正常啟動。
{% endhint %}
{% endstep %}

{% step %}

### 開啟韌體檔案

按 **Open file**，選擇對應產品的 `.hex` 或`.bin` 檔案，再按 **開啟**。下圖選取的檔案為 `arducopter_with_bl.hex`。

<figure><img src="https://160136817-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEhjsOwJXR5yBqExlT0G0%2Fuploads%2FJlLMAFP5BMppS1Q2VnVG%2Fimage.png?alt=media&#x26;token=19b7335f-80d0-413a-b8d0-687c5bd6a326" alt=""><figcaption></figcaption></figure>

<figure><img src="https://160136817-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEhjsOwJXR5yBqExlT0G0%2Fuploads%2FXie8M5goVet43t6vIkl2%2Fimage.png?alt=media&#x26;token=e9c9dd8b-41cf-4649-b68c-18fe8a5639bb" alt=""><figcaption></figcaption></figure>

`.hex` 檔案包含寫入位址；使用 `.bin` 時，需依該韌體的燒錄說明指定寫入位址。
{% endstep %}

{% step %}

### 開始燒錄

核對載入的檔名與寫入位址，按 **Download**（下載／燒錄）將韌體寫入飛控。

<figure><img src="https://160136817-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEhjsOwJXR5yBqExlT0G0%2Fuploads%2FOjny4CjDVEFcYCLvtChp%2Fimage.png?alt=media&#x26;token=b1dddf30-a0f5-452e-874e-75ef2179e076" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

### 等待燒錄完成

等待進度完成，確認程式顯示下載／燒錄成功。若出現錯誤，先保留完整訊息，檢查連線與韌體檔案後再處理。

<figure><img src="https://160136817-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEhjsOwJXR5yBqExlT0G0%2Fuploads%2FstENUXh69t1nO809TVlg%2Fimage.png?alt=media&#x26;token=d2b3110c-8047-435d-be1a-96e4dc40c1b9" alt=""><figcaption></figcaption></figure>

<figure><img src="https://160136817-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEhjsOwJXR5yBqExlT0G0%2Fuploads%2FLItbYpFEgzrbclvmexWa%2Fimage.png?alt=media&#x26;token=8d9794bb-ae66-4736-8c8b-0b37d247a0b2" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

### 重新啟動並確認韌體

結束 STM32CubeProgrammer 的連線，拔除 USB，再重新啟動飛控。確認能讀取韌體版本、狀態與參數。
{% endstep %}
{% endstepper %}

## 接續設定

燒錄完成後，回到 [韌體燒錄](https://taiphoon-com.gitbook.io/taiphoon.com-docs/firmware/ardupilot/flash-autopilot.md) 繼續設定。
