

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 在 Renesas RX65N 上下載、建置、刷新和執行 FreeRTOS OTA 示範
<a name="download-rx65n-ota"></a>

**重要**  <a name="deprecation-message"></a>
此參考整合託管在已棄用的 Amazon-FreeRTOS 儲存庫上。我們建議您在建立新專案時從[這裡開始](freertos-getting-started-modular.md)。如果您已經有以現在已棄用的 Amazon-FreeRTOS 儲存庫為基礎的現有 FreeRTOS 專案，請參閱 [Amazon-FreeRTOS Github 儲存庫遷移指南](github-repo-migration.md)。 FreeRTOS 

本章說明如何下載、建置、刷新和執行 Renesas RX65N 上的 FreeRTOS OTA 示範應用程式。

**Topics**
+ [設定您的操作環境](#download-rx65n-ota-environment)
+ [設定您的 AWS 資源](#download-rx65n-ota-setup)
+ [匯入、設定標頭檔案並建置 aws\$1demos 和 boot\$1loader](#download-rx65n-ota-import-configure)

## 設定您的操作環境
<a name="download-rx65n-ota-environment"></a>

本節中的程序使用以下環境：
+ **IDE**：e2 Studio 7.8.0、e2 Studio 2020-07
+ **工具鏈**：CCRX Compiler v3.0.1
+ **目標裝置**：RSKRX65N-2MB
+ **偵錯工具**：E2、E2 Lite 模擬器
+ **軟體**：Renesas Flash Programmer、Renesas Secure Flash Programmer.exe、Tera Term

**設定您的硬體**

1. 將 E2 Lite 模擬器和 USB 序列埠連接到 RX65N 主機板和 PC。

1. 將電源連接至 RX65N。

## 設定您的 AWS 資源
<a name="download-rx65n-ota-setup"></a>

1. 若要執行 FreeRTOS 示範，您必須擁有具有存取 AWS IoT 服務許可之 IAM 使用者的 AWS 帳戶。如果您尚未完成，請遵循中的步驟[設定AWS您的帳戶和許可](freertos-prereqs.md#freertos-account-and-permissions)。

1. 若要設定 OTA 更新，請遵循中的步驟[OTA 更新先決條件](ota-prereqs.md)。特別是，請遵循中的步驟[使用 MQTT 進行 OTA 更新的先決條件](ota-mqtt-freertos.md)。

1. 開啟 [AWS IoT 主控台](https://console.aws.amazon.com/iot/home)。

1. 在左側導覽窗格中，選擇**管理**，然後選擇**要**建立物件的物件。

   物件是其中裝置或邏輯實體的表示法 AWS IoT。它可以是實體裝置或感應器 (例如燈泡或牆上的開關)。它也可以是邏輯實體，例如未連線的應用程式執行個體或實體實體 AWS IoT，但與這樣做的裝置 （例如具有引擎感應器或控制面板的汽車） 相關。 AWS IoT 提供可協助您管理物件的物件登錄檔。

   1. 選擇**建立**，然後選擇**建立單一物件**。

   1. 輸入物件**的名稱**，然後選擇**下一步**。

   1. 選擇 **Create certificate (建立憑證)**。

   1. 下載建立的三個檔案，然後選擇**啟用**。

   1. 選擇 **Attach a policy (連接政策)**。  
![\[主控台畫面顯示要下載的檔案\]](http://docs.aws.amazon.com/zh_tw/freertos/latest/userguide/images/download-these-files-rx65n.png)

   1. 選取您在 中建立的政策[裝置政策](ota-mqtt-freertos.md#ota-mqtt-freertos-device-policy)。

      使用 MQTT 接收 OTA 更新的每個裝置都必須在 中註冊為物件， AWS IoT 而且該物件必須具有類似列出的附加政策。如需 `"Action"` 和 `"Resource"` 物件中的項目的詳細資訊，請參閱 [AWS IoT 核心政策動作](https://docs.aws.amazon.com/iot/latest/developerguide/iot-policy-actions.html)和 [AWS IoT 核心動作資源](https://docs.aws.amazon.com/iot/latest/developerguide/iot-action-resources.html)。

**備註**
      + `iot:Connect` 許可允許您的裝置 AWS IoT 透過 MQTT 連線至 。
      +  AWS IoT 工作 (`.../jobs/*`) 主題的 `iot:Subscribe` 和 `iot:Publish` 許可允許連接的裝置接收工作通知和工作文件，並發佈工作執行的完成狀態。
      + OTA 串流 (`.../streams/*`) AWS IoT 主題的 `iot:Subscribe`和 `iot:Publish`許可允許連線的裝置從中擷取 OTA 更新資料 AWS IoT。需要這些許可才能透過 MQTT 執行韌體更新。
      + `iot:Receive` 許可允許 AWS IoT Core 在這些主題上發佈訊息到連線的裝置。每次交付 MQTT 訊息時，都會檢查此許可。您可以使用此許可來撤銷目前訂閱主題之用戶端的存取權。

1. 建立程式碼簽署設定檔並註冊程式碼簽署憑證 AWS。

   1. 若要建立金鑰和認證，請參閱 [ Renesas MCU 韌體更新設計政策](https://www.renesas.com/us/en/document/apn/renesas-mcu-firmware-update-design-policy)中的第 7.3 節「使用 OpenSSL 產生 ECDSA-SHA256 金鑰對」。

   1. 開啟 [AWS IoT 主控台](https://console.aws.amazon.com/iot/home)。在左側導覽窗格中，選取**管理**，然後選取**任務**。選取**建立任務**，然後選取**建立 OTA 更新任務**。

   1. 在**選取要更新的裝置**下，選擇**選取**，然後選擇您先前建立的物件。選取**下一步**。

   1. 在**建立 FreeRTOS OTA 更新任務**頁面上，執行下列動作：

      1. 針對**選取韌體映像傳輸的通訊協定**，選擇 **MQTT**。

      1. 針對**選取並簽署您的韌體映像**，選擇**為我簽署新的韌體映像**。

      1. 針對**程式碼簽署設定檔**，選擇**建立**。

      1. 在**建立程式碼簽署設定檔**視窗中，輸入**設定檔名稱**。針對**裝置硬體平台**，選取 **Windows Simulator**。針對**程式碼簽署憑證**，選擇**匯入**。

      1. 瀏覽以選取憑證 (`secp256r1.crt`)、憑證私有金鑰 (`secp256r1.key`) 和憑證鏈 (`ca.crt`)。

      1. 在**裝置上輸入程式碼簽署憑證的路徑名稱**。然後選擇 **Create (建立)**。

1. 若要授予 程式碼簽署的存取權 AWS IoT，請遵循中的步驟[授予 程式碼簽署的存取權 AWS IoT](code-sign-policy.md)。

如果您的 PC 上未安裝 Tera Term，您可以從 [https://ttssh2.osdn.jp/index.html.en](https://ttssh2.osdn.jp/index.html.en)：// 下載並設定它，如下所示。請確定您將 USB 序列連接埠從裝置插入 PC。

![\[Tera Term 序列連接埠設定視窗\]](http://docs.aws.amazon.com/zh_tw/freertos/latest/userguide/images/tera-team-rx65n.png)


## 匯入、設定標頭檔案並建置 aws\$1demos 和 boot\$1loader
<a name="download-rx65n-ota-import-configure"></a>

若要開始，請選取最新版本的 FreeRTOS 套件，這會從 GitHub 下載並自動匯入專案。如此一來，您就可以專注於設定 FreeRTOS 和撰寫應用程式程式碼。

1. 啟動 e2 Studio。

1. 選擇**檔案**，然後選擇**匯入**。

1. 選取 **Renesas GitHub FreeRTOS （使用 IoT 程式庫） 專案**。  
![\[e-squared Studio 匯入時段\]](http://docs.aws.amazon.com/zh_tw/freertos/latest/userguide/images/import-renesas-project-rx65n.png)

1. 選擇**檢查更多版本...**以顯示下載對話方塊。  
![\[e-squared Studio 下載對話方塊視窗\]](http://docs.aws.amazon.com/zh_tw/freertos/latest/userguide/images/check-more-version-rx65n.png)

1. 選取最新的套件。  
![\[e-squared Studio 模組下載對話方塊視窗\]](http://docs.aws.amazon.com/zh_tw/freertos/latest/userguide/images/choose-latest-version-rx65n.png)

1. 選擇**同意**以接受最終使用者授權合約。  
![\[e-squared Studio EULA 對話方塊\]](http://docs.aws.amazon.com/zh_tw/freertos/latest/userguide/images/eula-rx65n.png)

1. 等待下載完成。  
![\[下載進度列\]](http://docs.aws.amazon.com/zh_tw/freertos/latest/userguide/images/downloading-rx65n.png)

1. 選取 **aws\$1demos** 和 **boot\$1loader** 專案，然後選擇**完成**以匯入專案。  
![\[匯入專案視窗\]](http://docs.aws.amazon.com/zh_tw/freertos/latest/userguide/images/import-projects-rx65n.png)

1. 對於這兩個專案，開啟專案屬性。在導覽窗格中，選擇**工具鏈編輯器**。

   1. 選擇**目前的工具鏈**。

   1. 選擇**目前的建置器**。  
![\[e-squared Studio 屬性視窗\]](http://docs.aws.amazon.com/zh_tw/freertos/latest/userguide/images/project-properties-rx65n.png)

1. 在導覽窗格中，選擇**設定**。選擇**工具鏈**索引標籤，然後選擇工具鏈**版本**。  
![\[Renesas CCRX 版本 v3.01.00 的工具鏈整合設定，可選擇變更工具鏈。\]](http://docs.aws.amazon.com/zh_tw/freertos/latest/userguide/images/project-properties-toolchain-rx65n.png)

   選擇**工具設定**索引標籤，展開**轉換器**，然後選擇**輸出**。在主視窗中，確定已選取**輸出十六進位檔案**，然後選擇**輸出檔案類型**。  
![\[C/C++ 組建組態設定視窗顯示編譯器和連結器選項，例如輸出十六進位檔案、輸出檔案類型、輸出目錄和檔案分割選項。\]](http://docs.aws.amazon.com/zh_tw/freertos/latest/userguide/images/project-properties-settings-rx65n.png)  
![\[具有堆疊分析、工具鏈編輯器、C/C++ 一般、MCU、專案參考等選項的界面設定樹。\]](http://docs.aws.amazon.com/zh_tw/freertos/latest/userguide/images/project-properties-settings-2-rx65n.png)

1. 在開機載入器專案中，開啟`projects\renesas\rx65n-rsk\e2studio\boot_loader\src\key\code_signer_public_key.h`並輸入公有金鑰。如需如何建立公有金鑰的資訊，請參閱 [Renesas MCU 韌體更新設計政策](https://www.renesas.com/us/en/document/apn/renesas-mcu-firmware-update-design-policy)中的[如何在 RX65N 上使用 Amazon Web Services 實作 FreeRTOS OTA](https://www.renesas.com/us/en/document/apn/rx-family-how-implement-freertos-ota-using-amazon-web-services-rx65n)，以及第 7.3 節「使用 OpenSSL 產生 ECDSA-SHA256 金鑰對」。  
![\[程式碼編輯器顯示具有 CODE_SIGNER_PUBLIC_KEY 定義的 C 標頭檔案，以及 PEM 編碼程式碼簽署者公有金鑰變數。\]](http://docs.aws.amazon.com/zh_tw/freertos/latest/userguide/images/open-bootloader-project-rx65n.png)

   然後建置專案以建立 `boot_loader.mot`。

1. 開啟`aws_demos`專案。

   1. 開啟 [AWS IoT 主控台](https://console.aws.amazon.com/iot/home)。

   1. 在左側的導覽窗格中，選擇**設定**。在**裝置資料端點文字方塊中記下您的自訂端點**。

   1. 選擇**管理**，然後選擇**物件**。記下電路板的 AWS IoT 物件名稱。

   1. 在`aws_demos`專案中，開啟 `demos/include/aws_clientcredential.h` 並指定下列值。

      ```
      #define clientcredentialMQTT_BROKER_ENDPOINT[] = "Your AWS IoT endpoint";
      #define clientcredentialIOT_THING_NAME "The AWS IoT thing name of your board"
      ```  
![\[顯示 AWS IoT 物件名稱和代理程式端點組態設定的程式碼片段。\]](http://docs.aws.amazon.com/zh_tw/freertos/latest/userguide/images/client-credential-rx65n.png)

   1. 開啟 `tools/certificate_configuration/CertificateConfigurator.html` 檔案。

   1. 匯入您先前下載的憑證 PEM 檔案和私有金鑰 PEM 檔案。

   1. 選擇**產生並儲存 aws\$1clientcredential\$1keys.h**，並在 `demos/include/`目錄中取代此檔案。  
![\[Certificate Configuration Tool 具有 欄位，可提供來自 AWS IoT 主控台的用戶端憑證和私有金鑰 PEM 檔案，以及用於產生和儲存 aws_clientcredential_keys.h 檔案的按鈕。\]](http://docs.aws.amazon.com/zh_tw/freertos/latest/userguide/images/certificate-config-tool-rx65n.png)

   1. 開啟 `vendors/renesas/boards/rx65n-rsk/aws_demos/config_files/ota_demo_config.h` 檔案，並指定這些值。

      ```
      #define otapalconfigCODE_SIGNING_CERTIFICATE [] = "your-certificate-key";
      ```

      其中 *your-certificate-key* 是 檔案 的值`secp256r1.crt`。請記得在認證中的每一行後面新增 "\$1"。如需建立 `secp256r1.crt` 檔案的詳細資訊，請參閱 [Renesas MCU 韌體更新設計政策](https://www.renesas.com/us/en/document/apn/renesas-mcu-firmware-update-design-policy)中的[如何在 RX65N 上使用 Amazon Web Services 實作 FreeRTOS OTA](https://www.renesas.com/us/en/document/apn/rx-family-how-implement-freertos-ota-using-amazon-web-services-rx65n)，以及第 7.3 節「使用 OpenSSL 產生 ECDSA-SHA256 金鑰對」。  
![\[原始程式碼檔案，顯示定義 PEM 編碼程式碼簽署者憑證常數字串的 C 程式碼，其中包含修改過的憑證資料。\]](http://docs.aws.amazon.com/zh_tw/freertos/latest/userguide/images/codesigner-cert-rx65n.png)

1. **任務 A：安裝韌體的初始版本**

   1. 開啟 `vendors/renesas/boards/board/aws_demos/config_files/aws_demo_config.h` 檔案、註解 `#define CONFIG_CORE_MQTT_MUTUAL_AUTH_DEMO_ENABLED`，並定義 `CONFIG_OTA_MQTT_UPDATE_DEMO_ENABLED`或 `CONFIG_OTA_HTTP_UPDATE_DEMO_ENABLED`。

   1. 開啟 `demos/include/ aws_application_version.h` 檔案，並將韌體的初始版本設定為 `0.9.2`。  
![\[顯示應用程式版本定義的程式碼片段，包括主要、次要和建置版本編號的巨集。\]](http://docs.aws.amazon.com/zh_tw/freertos/latest/userguide/images/firmware-version-rx65n.png)

   1. 在**區段檢視器**中變更下列設定。  
![\[區段檢視器視窗顯示記憶體地址、區段名稱，例如 SU、SI、註冊和界面元件，例如網路緩衝區、例外狀況和動作按鈕。\]](http://docs.aws.amazon.com/zh_tw/freertos/latest/userguide/images/section-viewer-rx65n.png)

   1. 選擇**建置**以建立`aws_demos.mot`檔案。

1. `userprog.mot` 使用 Renesas Secure Flash Programmer 建立 檔案。 `userprog.mot`是 `aws_demos.mot`和 的組合`boot_loader.mot`。您可以將此檔案刷入 RX65N-RSK 以安裝初始韌體。

   1. 下載 [ https://github.com/renesas/Amazon-FreeRTOS-Tools](https://github.com/renesas/Amazon-FreeRTOS-Tools) 並開啟 `Renesas Secure Flash Programmer.exe`。

   1. 選擇**初始公司**索引標籤，然後設定下列參數：
      + **私有金鑰路徑** – 的位置`secp256r1.privatekey`。
      + **Boot Loader 檔案路徑** – `boot_loader.mot`() 的位置`projects\renesas\rx65n-rsk\e2studio\boot_loader\HardwareDebug`。
      + **檔案路徑** – `aws_demos.mot`() 的位置`projects\renesas\rx65n-rsk\e2studio\aws_demos\HardwareDebug`。  
![\[Renesas Secure Flash Programmer 視窗與 MCU、韌體驗證、序號、AES 金鑰路徑和檔案路徑欄位。\]](http://docs.aws.amazon.com/zh_tw/freertos/latest/userguide/images/secure-flash-rx65n.png)

   1. 建立名為 的目錄`init_firmware`、產生 `userprog.mot`，並將其儲存至 `init_firmware`目錄。確認產生成功。

1. 刷新 RX65N-RSK 上的初始韌體。

   1. 從 [https://www.renesas.com/tw/en/products/software-tools/tools/programmer/renesas-flash-programmer-programming-gui.html](https://www.renesas.com/tw/en/products/software-tools/tools/programmer/renesas-flash-programmer-programming-gui.html)：// 下載最新版本的 Renesas Flash Programmer （程式設計 GUI)。

   1. 開啟 `vendors\renesas\rx_mcu_boards\boards\rx65n-rsk\aws_demos\flash_project\erase_from_bank\ erase.rpj` 檔案以清除銀行上的資料。

   1. 選擇**開始**以清除銀行。  
![\[Renesas Flash Programmer 視窗顯示 RX Group 微型控制器專案詳細資訊、檔案路徑和快閃記憶體操作選項，例如「清除」、「程式設計」和「使用啟動和確定」驗證」按鈕。\]](http://docs.aws.amazon.com/zh_tw/freertos/latest/userguide/images/flash-programmer-erasing-rx65n.png)

   1. 若要刷新 `userprog.mot`，請選擇**瀏覽...**，然後導覽至 `init_firmware` 目錄，選取 `userprog.mot` 檔案，然後選擇**開始**。  
![\[Renesas Flash Programmer 視窗顯示清除操作設定，包括微控制器 RX 群組、瀏覽程式檔案的選項、清除和啟動按鈕，以及要清除之所選區塊的狀態詳細資訊。\]](http://docs.aws.amazon.com/zh_tw/freertos/latest/userguide/images/flash-programmer-complete-rx65n.png)

1. 0.9.2 版 （初始版本） 的韌體已安裝到您的 RX65N-RSK。RX65N-RSK 主機板現在正在接聽 OTA 更新。如果您已在 PC 上開啟 Tera Term，則在初始韌體執行時，您會看到類似以下內容的內容。

   ```
   -------------------------------------------------
   RX65N secure boot program
   -------------------------------------------------
   Checking flash ROM status.
   bank 0 status = 0xff [LIFECYCLE_STATE_BLANK]
   bank 1 status = 0xfc [LIFECYCLE_STATE_INSTALLING]
   bank info = 1. (start bank = 0)
   start installing user program.
   copy secure boot (part1) from bank0 to bank1...OK
   copy secure boot (part2) from bank0 to bank1...OK
   update LIFECYCLE_STATE from [LIFECYCLE_STATE_INSTALLING] to [LIFECYCLE_STATE_VALID]
   bank1(temporary area) block0 erase (to update LIFECYCLE_STATE)...OK
   bank1(temporary area) block0 write (to update LIFECYCLE_STATE)...OK
   swap bank...
   -------------------------------------------------
   RX65N secure boot program
   -------------------------------------------------
   Checking flash ROM status.
   bank 0 status = 0xf8 [LIFECYCLE_STATE_VALID]
   bank 1 status = 0xff [LIFECYCLE_STATE_BLANK]
   bank info = 0. (start bank = 1)
   integrity check scheme = sig-sha256-ecdsa
   bank0(execute area) on code flash integrity check...OK
   jump to user program
   0 1 [ETHER_RECEI] Deferred Interrupt Handler Task started
   1 1 [ETHER_RECEI] Network buffers: 3 lowest 3
   2 1 [ETHER_RECEI] Heap: current 234192 lowest 234192
   3 1 [ETHER_RECEI] Queue space: lowest 8
   4 1 [IP-task] InitializeNetwork returns OK
   5 1 [IP-task] xNetworkInterfaceInitialise returns 0
   6 101 [ETHER_RECEI] Heap: current 234592 lowest 233392
   7 2102 [ETHER_RECEI] prvEMACHandlerTask: PHY LS now 1
   8 3001 [IP-task] xNetworkInterfaceInitialise returns 1
   9 3092 [ETHER_RECEI] Network buffers: 2 lowest 2
   10 3092 [ETHER_RECEI] Queue space: lowest 7
   11 3092 [ETHER_RECEI] Heap: current 233320 lowest 233320
   12 3193 [ETHER_RECEI] Heap: current 233816 lowest 233120
   13 3593 [IP-task] vDHCPProcess: offer c0a80a09ip
   14 3597 [ETHER_RECEI] Heap: current 233200 lowest 233000
   15 3597 [IP-task] vDHCPProcess: offer c0a80a09ip
   16 3597 [IP-task] IP Address: 192.168.10.9
   17 3597 [IP-task] Subnet Mask: 255.255.255.0
   18 3597 [IP-task] Gateway Address: 192.168.10.1
   19 3597 [IP-task] DNS Server Address: 192.168.10.1
   20 3600 [Tmr Svc] The network is up and running
   21 3622 [Tmr Svc] Write certificate...
   22 3697 [ETHER_RECEI] Heap: current 232320 lowest 230904
   23 4497 [ETHER_RECEI] Heap: current 226344 lowest 225944
   24 5317 [iot_thread] [INFO ][DEMO][5317] ---------STARTING DEMO---------
   
   25 5317 [iot_thread] [INFO ][INIT][5317] SDK successfully initialized.
   26 5317 [iot_thread] [INFO ][DEMO][5317] Successfully initialized the demo. Network type for the demo: 4
   27 5317 [iot_thread] [INFO ][MQTT][5317] MQTT library successfully initialized.
   28 5317 [iot_thread] [INFO ][DEMO][5317] OTA demo version 0.9.2
   
   29 5317 [iot_thread] [INFO ][DEMO][5317] Connecting to broker...
   
   30 5317 [iot_thread] [INFO ][DEMO][5317] MQTT demo client identifier is rx65n-gr-rose (length 13).
   31 5325 [ETHER_RECEI] Heap: current 206944 lowest 206504
   32 5325 [ETHER_RECEI] Heap: current 206440 lowest 206440
   33 5325 [ETHER_RECEI] Heap: current 206240 lowest 206240
   38 5334 [ETHER_RECEI] Heap: current 190288 lowest 190288
   39 5334 [ETHER_RECEI] Heap: current 190088 lowest 190088
   40 5361 [ETHER_RECEI] Heap: current 158512 lowest 158168
   41 5363 [ETHER_RECEI] Heap: current 158032 lowest 158032
   42 5364 [ETHER_RECEI] Network buffers: 1 lowest 1
   43 5364 [ETHER_RECEI] Heap: current 156856 lowest 156856
   44 5364 [ETHER_RECEI] Heap: current 156656 lowest 156656
   46 5374 [ETHER_RECEI] Heap: current 153016 lowest 152040
   47 5492 [ETHER_RECEI] Heap: current 141464 lowest 139016
   48 5751 [ETHER_RECEI] Heap: current 140160 lowest 138680
   49 5917 [ETHER_RECEI] Heap: current 138280 lowest 138168
   59 7361 [iot_thread] [INFO ][MQTT][7361] Establishing new MQTT connection.
   62 7428 [iot_thread] [INFO ][MQTT][7428] (MQTT connection 81cfc8, CONNECT operation 81d0e8) Wait complete with result SUCCESS.
   63 7428 [iot_thread] [INFO ][MQTT][7428] New MQTT connection 4e8c established.
   64 7430 [iot_thread] [OTA_AgentInit_internal] OTA Task is Ready.
   65 7430 [OTA Agent T] [prvOTAAgentTask] Called handler. Current State [Ready] Event [Start] New state [RequestingJob]
   66 7431 [OTA Agent T] [INFO ][MQTT][7431] (MQTT connection 81cfc8) SUBSCRIBE operation scheduled.
   67 7431 [OTA Agent T] [INFO ][MQTT][7431] (MQTT connection 81cfc8, SUBSCRIBE operation 818c48) Waiting for operation completion.
   68 7436 [ETHER_RECEI] Heap: current 128248 lowest 127992
   69 7480 [OTA Agent T] [INFO ][MQTT][7480] (MQTT connection 81cfc8, SUBSCRIBE operation 818c48) Wait complete with result SUCCESS.
   70 7480 [OTA Agent T] [prvSubscribeToJobNotificationTopics] OK: $aws/things/rx65n-gr-rose/jobs/$next/get/accepted
   71 7481 [OTA Agent T] [INFO ][MQTT][7481] (MQTT connection 81cfc8) SUBSCRIBE operation scheduled.
   72 7481 [OTA Agent T] [INFO ][MQTT][7481] (MQTT connection 81cfc8, SUBSCRIBE operation 818c48) Waiting for operation completion.
   73 7530 [OTA Agent T] [INFO ][MQTT][7530] (MQTT connection 81cfc8, SUBSCRIBE operation 818c48) Wait complete with result SUCCESS.
   74 7530 [OTA Agent T] [prvSubscribeToJobNotificationTopics] OK: $aws/things/rx65n-gr-rose/jobs/notify-next
   75 7530 [OTA Agent T] [prvRequestJob_Mqtt] Request #0
   76 7532 [OTA Agent T] [INFO ][MQTT][7532] (MQTT connection 81cfc8) MQTT PUBLISH operation queued.
   77 7532 [OTA Agent T] [INFO ][MQTT][7532] (MQTT connection 81cfc8, PUBLISH operation 818b80) Waiting for operation completion.
   78 7552 [OTA Agent T] [INFO ][MQTT][7552] (MQTT connection 81cfc8, PUBLISH operation 818b80) Wait complete with result SUCCESS.
   79 7552 [OTA Agent T] [prvOTAAgentTask] Called handler. Current State [RequestingJob] Event [RequestJobDocument] New state [WaitingForJob]
   80 7552 [OTA Agent T] [prvParseJSONbyModel] Extracted parameter [ clientToken: 0:rx65n-gr-rose ]
   81 7552 [OTA Agent T] [prvParseJSONbyModel] parameter not present: execution
   82 7552 [OTA Agent T] [prvParseJSONbyModel] parameter not present: jobId
   83 7552 [OTA Agent T] [prvParseJSONbyModel] parameter not present: jobDocument
   84 7552 [OTA Agent T] [prvParseJSONbyModel] parameter not present: afr_ota
   85 7552 [OTA Agent T] [prvParseJSONbyModel] parameter not present: protocols
   86 7552 [OTA Agent T] [prvParseJSONbyModel] parameter not present: files
   87 7552 [OTA Agent T] [prvParseJSONbyModel] parameter not present: filepath
   99 7651 [ETHER_RECEI] Heap: current 129720 lowest 127304
   100 8430 [iot_thread] [INFO ][DEMO][8430] State: Ready  Received: 1   Queued: 0   Processed: 0   Dropped: 0
   101 9430 [iot_thread] [INFO ][DEMO][9430] State: WaitingForJob  Received: 1   Queued: 0   Processed: 0   Dropped: 0
   102 10430 [iot_thread] [INFO ][DEMO][10430] State: WaitingForJob  Received: 1   Queued: 0   Processed: 0   Dropped: 0
   103 11430 [iot_thread] [INFO ][DEMO][11430] State: WaitingForJob  Received: 1   Queued: 0   Processed: 0   Dropped: 0
   104 12430 [iot_thread] [INFO ][DEMO][12430] State: WaitingForJob  Received: 1   Queued: 0   Processed: 0   Dropped: 0
   105 13430 [iot_thread] [INFO ][DEMO][13430] State: WaitingForJob  Received: 1   Queued: 0   Processed: 0   Dropped: 0
   106 14430 [iot_thread] [INFO ][DEMO][14430] State: WaitingForJob  Received: 1   Queued: 0   Processed: 0   Dropped: 0
   107 15430 [iot_thread] [INFO ][DEMO][15430] State: WaitingForJob  Received: 1   Queued: 0   Processed: 0   Dropped: 0
   ```

1. **任務 B：更新韌體版本**

   1. 開啟 `demos/include/aws_application_version.h`檔案，並將`APP_VERSION_BUILD`字符值增加到 `0.9.3`。

   1. 重新建置專案。

1. 使用 Renesas Secure Flash Programmer 建立 `userprog.rsu` 檔案，以更新韌體版本。

   1. 開啟 `Amazon-FreeRTOS-Tools\Renesas Secure Flash Programmer.exe` 檔案。

   1. 選擇**更新公司**索引標籤，並設定下列參數：
      + **檔案路徑** – `aws_demos.mot` 檔案的位置 (`projects\renesas\rx65n-rsk\e2studio\aws_demos\HardwareDebug`)。

   1. 建立名為 `update _firmware` 的目錄。產生並`userprog.rsu`儲存到 `update_firmware` 目錄。確認產生成功。  
![\[Renesas Secure Flash Programmer 視窗，其中包含 MCU 選擇、韌體驗證類型、序號、AES MAC 金鑰欄位，以及用於產生安全韌體的檔案路徑輸入。\]](http://docs.aws.amazon.com/zh_tw/freertos/latest/userguide/images/update-firmware-rx65n.png)

1. 將韌體更新 上傳至 Amazon S3 儲存貯體`userproj.rsu`，如中所述[建立 Amazon S3 儲存貯體以存放您的更新](dg-ota-bucket.md)。  
![\[具有資料夾、上傳、版本和許可選項的 Amazon S3 儲存貯體管理介面\]](http://docs.aws.amazon.com/zh_tw/freertos/latest/userguide/images/upload-firmware-rx65n.png)

1. 建立任務以更新 RX65N-RSK 上的韌體。

   AWS IoT Jobs 是一項服務，可通知一或多個連線裝置待定[任務](https://docs.aws.amazon.com/iot/latest/developerguide/iot-jobs.html)。任務可用來管理裝置機群、更新裝置上的韌體和安全憑證，或執行重新啟動裝置和執行診斷等管理任務。

   1. 登入 [AWS IoT 主控台](https://console.aws.amazon.com/iotv2/)。在導覽窗格中，選擇**管理**，然後選擇**任務**。

   1. 選擇**建立任務**，然後選擇**建立 OTA 更新任務**。選取物件，然後選擇**下一步**。

   1. 建立 FreeRTOS OTA 更新任務，如下所示：
      + 選擇 **MQTT**。
      + 選取您在上一節中建立的程式碼簽署設定檔。
      + 選取您上傳至 Amazon S3 儲存貯體的韌體映像。
      + 針對**裝置上的韌體映像路徑**，輸入 **test**。
      + 選擇您在上一節中建立的 IAM 角色。

   1. 選擇**下一步**。  
![\[韌體映像簽署和 OTA 更新設定，其中包含簽署新韌體、選取先前簽署的韌體、使用自訂簽署的韌體、指定程式碼簽署設定檔、韌體映像檔案、裝置上的路徑，以及 OTA 更新任務的 IAM 角色。\]](http://docs.aws.amazon.com/zh_tw/freertos/latest/userguide/images/create-job-next-rx65n.png)

   1. 輸入 ID，然後選擇**建立**。

1. 重新開啟 Tera Term 以確認韌體已成功更新至 OTA 示範 0.9.3 版。  
![\[命令列輸出，顯示執行緒與代理程式的初始化和連線。\]](http://docs.aws.amazon.com/zh_tw/freertos/latest/userguide/images/update-successful-rx65n.png)

1. 在 AWS IoT 主控台上，驗證任務狀態是否**成功**。  
![\[AFR OTA 示範測試任務概觀，顯示 1 個資源成功。\]](http://docs.aws.amazon.com/zh_tw/freertos/latest/userguide/images/completed-succeeded-rx65n.png)