> 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/firmware/px4/flash-firmware.md). Agents can also search and read this documentation through its [MCP server](https://taiphoon-com.gitbook.io/taiphoon.com-docs/~gitbook/mcp).

# 韌體燒錄

Morakot 出廠為 ArduPilot。改用 PX4 時，先以 STM32CubeProgrammer 透過 USB DFU 全片擦除並燒錄 PX4 bootloader，再以 QGroundControl（QGC）燒錄 PX4 韌體。

## 開始前

* 寄信至 <service@taiphoon.com.tw>，提供飛控型號與硬體版本，取得 Morakot 的 PX4 bootloader（`.bin`）與 PX4 韌體（`.px4`）檔案。
* 從 [ST 官方網站](https://www.st.com/en/development-tools/stm32cubeprog.html)下載並安裝 STM32CubeProgrammer。
* 從 [QGroundControl 下載頁面](https://docs.qgroundcontrol.com/master/en/qgc-user-guide/getting_started/download_and_install.html)下載並安裝 QGroundControl。
* 使用可傳輸資料的 USB 線，直接連接電腦的 USB 埠，不經過 USB Hub。

{% hint style="warning" %}
先卸下螺旋槳。全片擦除會清除飛控快閃記憶體中的所有內容，包含 bootloader 與原本的 ArduPilot 韌體。燒錄期間保持 USB 連線，等待程式完成。
{% endhint %}

{% hint style="info" %}
本文畫面使用 STM32CubeProgrammer 2.20.0 與 QGroundControl Daily v5.2.0-dev，其他版本的選單名稱可能不同。
{% endhint %}

## 1. 以 DFU 燒錄 PX4 bootloader

{% stepper %}
{% step %}

### 進入 DFU 模式

先拔除 USB，按住飛控的 Boot 按鍵再插入 USB 線，讓飛控進入 DFU 模式。Windows 裝置管理員的「通用序列匯流排裝置」下會出現 DFU 裝置，名稱可能顯示為 **DFU in FS Mode** 或 **STM32 BOOTLOADER**。

<figure><img src="https://401369577-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmvFqg0h5Ob1pRXspm7Yi%2Fuploads%2F9jJBjdAdLYbKCOoc5SHl%2Fpx4-dfu-01-device-manager.png?alt=media&amp;token=57206d4d-8731-495a-a5f3-503e53b23bc6" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

### 以 USB 連接飛控

開啟 STM32CubeProgrammer，在右側連線介面選擇 **USB**，確認 **Port** 欄位已列出裝置（例如 `USB1`），再按 **Connect**。連線後右上角顯示 **Connected**。

<figure><img src="https://401369577-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmvFqg0h5Ob1pRXspm7Yi%2Fuploads%2FIspMOZNSiTuAbTHKmLoc%2Fpx4-dfu-02-usb-port.png?alt=media&amp;token=87bbdbca-32c8-43ee-a525-c2733a09fb5d" alt=""><figcaption></figcaption></figure>

<figure><img src="https://401369577-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmvFqg0h5Ob1pRXspm7Yi%2Fuploads%2FLbZ0nbChaL5mDYyuMdsS%2Fpx4-dfu-03-connected.png?alt=media&amp;token=752debcc-10c9-45ea-9ca9-9d1ceacc84fa" 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%2Fk3pywBluRFdDJ2ytmhLl%2Fpx4-dfu-04-erasing-programming.png?alt=media&amp;token=5a7aa0fa-49b8-41ee-9a9b-eff81ae84c18" alt=""><figcaption></figcaption></figure>

<figure><img src="https://401369577-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmvFqg0h5Ob1pRXspm7Yi%2Fuploads%2FXTYQfy9v9UIxwroMQv9G%2Fpx4-dfu-05-full-chip-erase-confirm.png?alt=media&amp;token=0f6d6364-355d-462d-9a7b-65253d405333" alt=""><figcaption></figcaption></figure>

<figure><img src="https://401369577-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmvFqg0h5Ob1pRXspm7Yi%2Fuploads%2FgqGdDsH3oGRXIXL0BC0G%2Fpx4-dfu-06-full-chip-erase-complete.png?alt=media&amp;token=7f90e93f-acf1-44bb-bb77-9be4e868ca2d" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

### 開啟 bootloader 檔案

點左側第一個圖示回到 **Memory & File editing** 頁面，按分頁列的 **+**，選擇 **Open file**，選取 bootloader 檔案（例如 `morakot_v6_bootloader.bin`）後按 **開啟**。

<figure><img src="https://401369577-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmvFqg0h5Ob1pRXspm7Yi%2Fuploads%2FUE2vkCkuhBmnJjxZB5jn%2Fpx4-dfu-07-open-file-menu.png?alt=media&amp;token=29da51cc-19ed-4073-934e-8b8348f9b080" alt=""><figcaption></figcaption></figure>

<figure><img src="https://401369577-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmvFqg0h5Ob1pRXspm7Yi%2Fuploads%2FNL4sVqdwVwPs7eaf6s2x%2Fpx4-dfu-08-open-bootloader.png?alt=media&amp;token=f415ddee-5ee8-489d-afc6-0786a49297ee" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

### 燒錄 bootloader

確認新分頁顯示 bootloader 檔名，按 **Download**。Log 會顯示寫入位址 `Address : 0x08000000` 與燒錄進度。

<figure><img src="https://401369577-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmvFqg0h5Ob1pRXspm7Yi%2Fuploads%2F9wJuddIOfZ50mr9bSSul%2Fpx4-dfu-09-bootloader-loaded.png?alt=media&amp;token=d54c2952-d658-4cc1-ad71-a7bc8e70f511" alt=""><figcaption></figcaption></figure>

<figure><img src="https://401369577-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmvFqg0h5Ob1pRXspm7Yi%2Fuploads%2FheNWd2wtVmSp27f43gEb%2Fpx4-dfu-10-download-progress.png?alt=media&amp;token=de9fbffa-c8f9-4dcb-b99f-b4491567b6f5" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

### 完成燒錄

出現 **File download complete** 後按 **確定**。按 **Disconnect** 結束連線，再拔除 USB。

<figure><img src="https://401369577-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmvFqg0h5Ob1pRXspm7Yi%2Fuploads%2FGsYZ3ZCsiVnggHdggQBF%2Fpx4-dfu-11-download-complete.png?alt=media&amp;token=d69d2c39-0d83-44cb-888a-1680b5437662" alt=""><figcaption></figcaption></figure>
{% endstep %}
{% endstepper %}

## 2. 以 QGroundControl 燒錄 PX4 韌體

影片示範：QGroundControl 燒錄 PX4 韌體。選擇韌體檔案的視窗未錄入影片，見下方步驟 4 的截圖。

{% embed url="<https://firebasestorage.googleapis.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmvFqg0h5Ob1pRXspm7Yi%2Fuploads%2FP9EpkO7yN0aQYShpLYTF%2Fpx4-qgc-flash-firmware.mp4?alt=media&token=d93a7240-46b7-4e2c-ba5f-7e267bc524af>" %}

{% stepper %}
{% step %}

### 開啟 Firmware 頁面

開啟 QGC，按左上角的 Q 圖示，選擇 **Configure**，再點左側的 **Firmware**。

<figure><img src="https://401369577-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmvFqg0h5Ob1pRXspm7Yi%2Fuploads%2F5Zyk7IZK2Ul0MWSvnGJW%2Fpx4-qgc-01-q-menu.png?alt=media&amp;token=7ce16245-76b7-4b75-af20-da16bf5cd6e4" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

### 連接飛控並開始燒錄

以 USB 連接飛控，下拉選單出現裝置後按 **Flash**。

<figure><img src="https://401369577-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmvFqg0h5Ob1pRXspm7Yi%2Fuploads%2FzOyt79K9tGIrVqKNE07B%2Fpx4-qgc-02-device-selected.png?alt=media&amp;token=95c3e9e5-7843-48d8-ac16-af41d0d555fb" alt=""><figcaption></figcaption></figure>

畫面出現 `Now unplug your device and plug it back in to enter bootloader mode.` 時，拔除 USB 再重新插入。

<figure><img src="https://401369577-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmvFqg0h5Ob1pRXspm7Yi%2Fuploads%2FI9m5n1MFMMyzaSldElwP%2Fpx4-qgc-03-replug.png?alt=media&amp;token=d65217a9-b69c-4b4f-a622-27a0466dfbc7" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

### 選擇自訂韌體檔案

**Firmware Setup** 視窗出現後，選擇 **PX4 Pro**，勾選 **Advanced settings**，在版本下拉選單選擇 **Custom firmware file...**，再按 **Ok**。

<figure><img src="https://401369577-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmvFqg0h5Ob1pRXspm7Yi%2Fuploads%2FJ51OPKjeqmt2CSwaBK0U%2Fpx4-qgc-04-firmware-setup.png?alt=media&amp;token=f6579bd2-3a49-48d2-841b-bbf97e577388" alt=""><figcaption></figcaption></figure>

<figure><img src="https://401369577-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmvFqg0h5Ob1pRXspm7Yi%2Fuploads%2FNI5p2CGAS4mXopsUyCwJ%2Fpx4-qgc-05-custom-firmware.png?alt=media&amp;token=90054065-0ec0-4752-a1a7-1e74e1bb4577" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

### 選擇 PX4 韌體檔

在 **Select Firmware File** 視窗選取 `.px4` 韌體檔，按 **開啟**。

<figure><img src="https://401369577-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmvFqg0h5Ob1pRXspm7Yi%2Fuploads%2FoADhTDyE7Xq8Dlzzy0sg%2Fpx4-qgc-06-select-px4-file.png?alt=media&amp;token=7a0da241-5180-41a2-b238-b5525284c2f2" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

### 等待燒錄完成

QGC 依序顯示，燒錄期間不要拔除 USB。

1. `Erasing previous program...`
2. `Programming new version...`
3. `Verifying program...`
4. `Rebooting board`
5. 出現 **Upgrade complete** 即完成。

<figure><img src="https://401369577-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmvFqg0h5Ob1pRXspm7Yi%2Fuploads%2FBJpf1omebIkafP3Td3AR%2Fpx4-qgc-07-flashing.png?alt=media&amp;token=4d849d60-7712-4984-b56b-aac496cc5808" alt=""><figcaption></figcaption></figure>

<figure><img src="https://401369577-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmvFqg0h5Ob1pRXspm7Yi%2Fuploads%2FWupyBxc8szBVKxUoQCOi%2Fpx4-qgc-08-upgrade-complete.png?alt=media&amp;token=c8a8df65-178d-4334-93d9-d54b6f912549" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

### 確認韌體版本

飛控重新啟動並連上 QGC 後，在 **Summary** 確認 **Firmware Version**。

<figure><img src="https://401369577-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmvFqg0h5Ob1pRXspm7Yi%2Fuploads%2F5PpmxEkuiOw0MOnyVqAo%2Fpx4-qgc-09-summary.png?alt=media&amp;token=2ceb5f32-a05e-4f08-ad6b-15e629645005" alt=""><figcaption></figcaption></figure>
{% endstep %}
{% endstepper %}

{% hint style="info" %}

* 出現 `Error: Open failed on port ...` 或 `Upgrade cancelled` 時，依 QGC 的提示將飛控直接接在電腦的 USB 埠（不經過 USB Hub），只用 USB 供電、不接電池，再重新燒錄。
* 燒錄或重新開機後，若 QGC 一直顯示 `Disconnected`，關閉 QGC 後重新開啟。
  {% endhint %}

## 接續設定

前往 [首次設定](https://taiphoon-com.gitbook.io/taiphoon.com-docs/firmware/px4/first-setup.md)。
