# Betaflight

## 韌體編譯

### 0. 前置條件

作業系統為Ubuntu或Windows WSL

### 1. 構建 Betaflight 開發環境

Betaflight 是一個開源的飛控韌體，主要用於無人機和遙控飛行器。以下是構建 Betaflight 開發環境的步驟：

### 2. 複製Betaflight Github儲存庫

1. 開啟終端。
2. 執行以下命令以複製 Betaflight 儲存庫：

   ```bash
   git clone --recursive https://github.com/betaflight/betaflight.git
   ```
3. 進入代碼庫目錄：

   ```bash
   cd betaflight
   ```
4. 安裝必要工具：`sudo apt install curl`
5. 安裝 GCC 工具鏈：

   <pre class="language-bash"><code class="lang-bash"><strong>make arm_sdk_install
   </strong></code></pre>

### 3. 編譯 Betaflight 韌體

1. 執行以下命令進行代碼編譯：

   ```bash
   make <Board Name, Ex: MATEKF405AIO>
   ```

   *將* Board Name*替換為飛控板的具體名稱。*
2. 編譯成功後會出現以下訊息

   <figure><img src="https://160136817-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEhjsOwJXR5yBqExlT0G0%2Fuploads%2F0Ckl5hFwi2NKynPMJA9z%2Fimage.png?alt=media&#x26;token=89a54466-93b5-4365-a24c-a01915f30816" alt=""><figcaption></figcaption></figure>
3. 編譯的韌體位置在betaflight/obj底下的hex檔案

   <figure><img src="https://160136817-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEhjsOwJXR5yBqExlT0G0%2Fuploads%2Fp9BZlQjV177kFVSfvHB0%2Fimage.png?alt=media&#x26;token=54b5c49d-7d48-4e34-b862-639df4223689" alt=""><figcaption></figcaption></figure>

## 韌體燒錄

1. 飛控版開啟DFU模式，USB 連接到電腦。

   <figure><img src="https://160136817-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEhjsOwJXR5yBqExlT0G0%2Fuploads%2FGzlu0BgKkGoqOmKOxh5T%2Fimage.png?alt=media&#x26;token=2e618afd-cf40-4a55-be2e-c8a5434fd127" alt=""><figcaption></figcaption></figure>

2. 使用 Betaflight Configurator 燒錄編譯好的韌體。

   <figure><img src="https://160136817-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEhjsOwJXR5yBqExlT0G0%2Fuploads%2FJtmxN8VHNO6CRM5DHqMA%2Fbetaflight%20configurator%E7%87%92%E9%8C%84%E6%95%99%E5%AD%B81.png?alt=media&#x26;token=eb6f8cca-9ed4-4e94-914b-651ecc7d7a32" alt=""><figcaption></figcaption></figure>

3. Betaflight韌體位置(hex檔案)

   <figure><img src="https://160136817-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEhjsOwJXR5yBqExlT0G0%2Fuploads%2FNgjUqEoz5BEw6erdoELH%2Fimage.png?alt=media&#x26;token=a5da0331-9eb4-4437-8dce-c7c2db61f644" alt=""><figcaption></figcaption></figure>

4. 開始燒錄Betaflight韌體

   <figure><img src="https://160136817-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEhjsOwJXR5yBqExlT0G0%2Fuploads%2FcXR0zDpwzYp6SQeVt8ow%2Fbetaflight%20configurator%E7%87%92%E9%8C%84%E6%95%99%E5%AD%B82.png?alt=media&#x26;token=f6d2e36f-9fb3-42b1-a47a-9b0d6ebd246e" alt=""><figcaption></figcaption></figure>

5. 燒錄中

   <figure><img src="https://160136817-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEhjsOwJXR5yBqExlT0G0%2Fuploads%2F8Pc8IxxxSTn1Abcd7U4w%2Fimage.png?alt=media&#x26;token=262a4cfb-b885-466a-9d95-225cf5320304" alt=""><figcaption></figcaption></figure>

6. 燒錄完成

   <figure><img src="https://160136817-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEhjsOwJXR5yBqExlT0G0%2Fuploads%2Fvu1aVqhqkm7vpbIbb84o%2Fimage.png?alt=media&#x26;token=c947b3b8-8a03-4184-bc0a-d84cb4963fb0" alt=""><figcaption></figcaption></figure>

***

## 自定義韌體編譯

**如何編譯自定義的飛控板**

1. 複製已經存在的飛控板定義，重新命名資料夾，EX:KAKUTEF4V2\_ICM42688P

   <figure><img src="https://160136817-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEhjsOwJXR5yBqExlT0G0%2Fuploads%2FvZ6LgK39MwB4KIjhUdtA%2Fimage.png?alt=media&#x26;token=7a3255bc-d49f-4dcd-8622-915f295e5260" alt=""><figcaption></figcaption></figure>

2. 修改config.h

   <figure><img src="https://160136817-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEhjsOwJXR5yBqExlT0G0%2Fuploads%2FqiIqRO8H8XuD9mIjaPva%2Fimage.png?alt=media&#x26;token=bb01e0cc-3c9b-46d7-8fad-cc03c19cb73a" alt=""><figcaption></figcaption></figure>

3. 開啟終端，切換到betaflight資料夾，編譯新飛控板的韌體:&#x20;

   `make KAKUTEF4V2_ICM42688P`

4. 編譯完的韌體將位於`betaflight/V4.5.0/betaflight/obj/`資料夾中

   <figure><img src="https://160136817-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEhjsOwJXR5yBqExlT0G0%2Fuploads%2F1Vw162KQhpGbsUtYUxap%2Fimage.png?alt=media&#x26;token=f8af60a6-7f06-4a12-824e-c68a74c0aa4d" alt=""><figcaption></figcaption></figure>
