Reprogramming a KW35 device using the OTAP Client Software

Document created by Edgar Eduardo Lomeli Gonzalez Employee on Jan 23, 2019Last modified by Edgar Eduardo Lomeli Gonzalez Employee on Jan 23, 2019
Version 2Show Document
  • View in full screen mode

Introduction

This document provides guidance to load a new software image in a KW35 device through OTAP (Over The Air Programming) bootloader for KW35. This article also provides the steps needed to download and install the SDK used in the tutorial.

Software Requirements

  1. IAR Embedded Workbench IDE or MCUXpresso IDE.
  2. SDK MKW36A512xxx4 RC4 or further.

Hardware Requirements

  1. MKW35A512xxx4 device.

KW35 Flash Memory Used for the OTAP Software Deployment

The KW35 Flash is partitioned into:

  • 2x256 KB Program Flash (P-Flash) array divided into 2 KB sectors with a flash address range from 0x0000_0000 to 0x0007_FFFF.

 

 

The statements to comprehend how the OTAP Client software and his features works are:

  1. The OTAP Client software is split into two parts, the OTAP bootloader and the OTAP client service. The OTAP bootloader verifies if there is a new image already available to reprogram the device. The OTAP client service software provides the Bluetooth LE custom services needed to communicate with the server that contains the new image file. Therefore, before to start the test, the device has been programmed twice, first with the OTAP bootloader then with the OTAP client service project. The mechanism used to have two different software in the same device is to store each one in different memory regions and this is implemented by the linker file. In the KW35 device, the bootloader application has reserved a 16KB slot of memory starting from the 0x0 address (0x0 to 0x3FFF) thus, the left memory of the first P-Flash memory bank is reserved, among other things, by the OTAP client service application.

     

  2. To create a new image file for the client device, the developer needs to specify to the linker file that the code will be stored with an offset of 16KB since the first addresses are reserved for the bootloader.

  3. At connection event, the server sends all the chunks of code to the client via Bluetooth LE. The client stores the code at the second P-Flash memory bank but is not able to run yet.

     

  4. When the broadcast has finished, and all chunks were sent, the OTAP bootloader detects this situation and triggers a command to reprogram the device with the new application. Due the new application was built with an offset of 16KB, the OTAP bootloader program the device starting from the 0x3FFF address and the OTAP client service application is overwritten by the new image. Then the OTAP bootloader triggers the new application, starting the execution of the code.

     

Software Development Kit download and install

 

  1. Go to MCUXpresso web page.

  2. Log in with your registered account.

  3. Search for “MKW36A” device. Then click on the suggested processor and click on “Build MCUXpresso SDK”

  4. The next page is displayed. Select “All toolchains” in the “Toolchain / IDE” combo box and provide the name to identify the package.

  5. Click on “Add software component”, then deploy the combo box and click on “Select All” option. Save the changes.

  6. Click on “Download SDK” button and accept the license agreement.

  7. If MCUXpresso IDE is used, drag and drop the SDK zip folder in “Installed SDK’s” perspective to install the package.

 

 

Preparing the software to test the OTAP for KW35 device using IAR Embedded Workbench

 

This section provides the steps needed to test the OTAP software on the KW35.

  1. Program the OTAP bootloader on the KW35.

    1.1 Open the OTAP_bootloader project located at the following path:

    <SDK_download_root>\boards\virtual-board-kw35\wireless_examples\framework\bootloader_otap\bm\iar\bootloader_otap_bm.eww

     

     

    1.2 Flash the project (Ctrl + D). Stop the debug session (Ctrl + Shift + D).
  2. Program the OTAP client application on the KW35.

        2.1 Open the OTAP client project located in the path below.
         <SDK_download_root>\boards\frdmkw36\wireless_examples\bluetooth\otac_att\freertos\iar\otac_att_freertos.eww


         2.2 Follow the steps 2 to 12 described in the “4.1. Changes Required in Project Options and Settings” section of the AN12252 “Migration Guide from               MKW36Z512xxx4 to MKW35Z512xxx4” application note.

 

         2.3 Open the app_preinclude.h file under the source directory in the workspace. Find the “gEepromType_d” definition and update the value to                                 “gEepromDevice_InternalFlash_c” as shown below.

 

#define gEepromType_d gEepromDevice_InternalFlash_c

 

         2.4 Save the MKW35Z512xxx4_connectivity.icf file located at:

               <SDK_download_root>\middleware\wireless\framework_5.4.4\Common\devices\MKW35Z4\iar               

               Into the folder of the OTAP Client ATT project:

               <SDK_download_root>\boards\frdmkw36\wireless_examples\bluetooth\otac_att\freertos\iar

 

         2.5 Open the project options window (Alt+F7). In Linker/Config window click the icon next to linker path and select the linker configuration file “MKW35Z512xxx4_connectivity.icf”. Set the "gUseInternalStorageLink_d” flag to 1.

 

 

         2.6 Click the OK button in the project options window to save the new configuration.

         2.7 Flash the project (Ctrl + D). Stop the debug session (Ctrl + Shift + D).

  

Preparing the software to test the OTAP for KW35 device using MCUXpresso IDE

 

This section provides the steps needed to test the OTAP software on the KW35.

  1. Program the OTAP bootloader on the KW35.

         1.1 Open MCUXpresso IDE. Click on “Import SDK example(s)” option in the “Quickstart Panel” view.            

 

         1.2 Click on virtual-board-kw35 SDK icon.
         1.3 Deploy the wireless_examples\framework\bootloader_otap folders and select bm project. Click Finish button.                                                                           1.4 Select “Debug” option in the Quickstart Panel. Once the project is already loaded on the device, stop the debug session.

 

   2. Program the OTAP client application on the KW35.

         2.1 Open MCUXpresso IDE. Click on “Import SDK example(s)” option in the “Quickstart Panel” view.              

 

         2.2 Click twice on the frdmkw36 icon.                                                                           2.3 Type “otac_att” in the examples textbox and select the freertos project at wireless_examples\bluetooth\otac_att\freertos. Finally, click on Finish button.

 

 

         2.4 Follow the steps 5 to 17 described in the “5.1. Changes Required in Project Options and Settings” section of the AN12252 “Migration Guide from MKW36Z512xxx4 to MKW35Z512xxx4” application note.

 

         2.5. Open the app_preinclude.h file under the source directory in the workspace. Find the “gEepromType_d” definition and update the value to                “gEepromDevice_InternalFlash_c” as shown below.

#define gEepromType_d gEepromDevice_InternalFlash_c

 

         2.6 Save the MKW35Z512xxx4_connectivity.ld file located at:

               <SDK_download_root>\middleware\wireless\framework_5.4.4\Common\devices\MKW35Z4\gcc

               Into the source folder in the workspace.

 

 

         2.7 Open the Project/Properties window. Next, go to the MCU Linker/Managed Linker Script perspective and edit the Linker Script name to “MKW35Z512xxx4_connectivity.ld”.

 

 

         2.8 Go to MCU Linker/Miscellaneous view. Press the icon below, a new window will be deployed. Add the following definition in the “Other options” box: --defsym=gUseInternalStorageLink_d=1.

 

 

         2.9 Click the “Apply and Close” button in the project options window to save the new configuration.

         2.10 Select “Debug” option in the Quickstart Panel. Once the project is already loaded on the device, stop the debug session.

 

Running OTAP demo with the IoT Toolbox App

  1. Save the S-Record file created with the steps in Appendix A or Appendix B in your smartphone at a known location.
  2. Open the IoT Toolbox App and select OTAP demo. Press “SCAN” to start scanning for a suitable advertiser.

  3. Perform a falling edge on the PTB18 in the KW35 to start advertising.

  4. Create a connection with the founded device.

  5. Press “Open” and search the S-Record file.

  6. Press “Upload” to start the transfer.

  7. Once the transfer is complete, wait a few seconds until the bootloader has finished programming the new image. The new application will start automatically. 

 

Appendix A. Creating an S-Record image file for KW35 client using IAR Embedded Workbench

  1. Open the connectivity project that you want to program using the OTAP bootloader from your SDK. This example will make use of the glucose sensor project.

    <SDK_download_root>\boards\frdmkw36\wireless_examples\bluetooth\glucose_s\freertos\iar\glucose_s_freertos.eww
  2. Follow the steps 2 to 12 described in the “4.1. Changes Required in Project Options and Settings” section of the AN12252 “Migration Guide from              MKW36Z512xxx4 to MKW35Z512xxx4” application note.

  3. Save the MKW35Z512xxx4_connectivity.icf file located at:

    <SDK_download_root>\middleware\wireless\framework_5.4.4\Common\devices\MKW35Z4\iar               

    In the containing folder of your project.

    <SDK_download_root>\boards\frdmkw36\wireless_examples\bluetooth\glucose_s\freertos\iar

  4. Open the project options window (Alt+F7). In Linker/Config window click the icon next to linker path and select the linker configuration file MKW35Z512xxx4_connectivity.icf. Then, enable “gUseBootloaderLink_d” macro in the “Configuration file symbol definitions” textbox.

  5. Go to the “Output Converter” window. Deselect the “Override default" checkbox, expand the “Output format” combo box and select Motorola S-records format. Click OK button.                                                                                                                                          

  6. Rebuild the project.

  7. Search the S-Record file in the following path:

    <SDK_download_root>\boards\frdmkw36\wireless_examples\bluetooth\glucose_s\freertos\iar\debug

 

Appendix B. Creating an S-Record image file for KW35 client using MCUXpresso IDE

  1. Open the connectivity project that you want to program using the OTAP bootloader from MCUXpresso IDE This example will make use of the glucose sensor project

  2. Follow the steps 5 to 17 described in the “5.1. Changes Required in Project Options and Settings” section of the AN12252 “Migration Guide from MKW36Z512xxx4 to MKW35Z512xxx4” application note.
  3. Save the MKW35Z512xxx4_connectivity.ld file located at:

    <SDK_download_root>\middleware\wireless\framework_5.4.4\Common\devices\MKW35Z4\gcc

    Into the source folder in the workspace.                                                                                                                 

  4. Open the Project/Properties window. Next, go to the MCU Linker/Managed Linker Script perspective and edit the Linker Script name to “MKW35Z512xxx4_connectivity.ld”.                                                                                 

  5. Go to MCU Linker/Miscellaneous view. Press the icon below, a new window will be deployed. Add the following definition in the “Other options” box: --defsym=gUseBootloaderLink_d=1. Click the “Apply and Close” button.                             

  6. Build the project.

  7. Deploy the “Binaries” icon in the workspace. Click the right mouse button on the “.axf” file. Select “Binary Utilities/Create S-Record” option. The S-Record file will be saved at “Debug” folder in the workspace with “.s19” extension.

 

Attachments

    Outcomes