Reprogramming a KW36 device using the OTAP Client Software

Document created by Edgar Eduardo Lomeli Gonzalez Employee on Jan 21, 2019Last modified by Edgar Eduardo Lomeli Gonzalez Employee on May 3, 2019
Version 8Show Document
  • View in full screen mode

Introduction

This document guides to load a new software image in a KW36 device through OTAP (Over The Air Programming) bootloader focusing on the various memory features supported by this device.

Software Requirements

  1. IAR Embedded Workbench IDE or MCUXpresso IDE.
  2. SDK FRDM-KW36 1.3.4 or further.

Hardware Requirements

  1. FRDM-KW36 board.

KW36 Flash Memory Used for the OTAP Software Deployment

The KW36 Flash is partitioned into:

  • One 256 KB Program Flash (P-Flash) array divided into 2 KB sectors with a flash address range from 0x0000_0000 to 0x0003_FFFF.
  • One 256 KB FlexNVM array divided in 2 KB sectors, flash address ranges from 0x1000_0000 to 0x1003_FFFF with an Alias memory with address range 0x0004_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 KW36 device, the bootloader application has reserved an 8KB slot of memory starting from the 0x0 address (0x0 to 0x1FFF) thus, the left memory 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 8KB since the first addresses are reserved for the bootloader.

  3. At the connection event, the server sends all the chunks of code to the client via Bluetooth LE. The client can store the code in the first instance at the external flash AT45DB041E or in the On-chip FlexNVM memory. This is can be selected by the OTAP client software.

     

  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 to the new application was built with an offset of 8KB, the OTAP bootloader program the device starting from the 0x1FFF 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.

     

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

 

This section provides the steps needed to test the OTAP software on the FRDM-KW36 board.

  1. Program the OTAP bootloader on the FRDM-KW36.

    1.1 Drag and drop to the FRDM-KW36 client board the OTAP bootloader prebuilt binary from the following path. <SDK_download_root>\tools\wireless\binaries\bootloader_otap_frdmkw36.bin
  2. Program the OTAP client application on the FRDM-KW36.

        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 Set the storage configurations.

               a. Search in the OTAP ATT client project the app_preinclude.h file located in the source folder in the workspace.
                     • To select External Flash storage, set the gEepromType_d define to "gEepromDevice_AT45DB041E_c"
                     • To select FlexNVM storage, set the gEepromType_d define to "gEepromDevice_InternalFlash_c"

 

               b. Open the project options window (Alt+F7). In Linker/Config window update the “gUseInternalStorageLink_d linker flag.
                     • To select External Flash storage, remove the "gUseInternalStorageLink_d=1" flag in the “Configuration file symbol definitions” textbox.
                     • To select FlexNVM storage, add "gUseInternalStorageLink_d=1" flag in the “Configuration file symbol definitions” textbox.

 

 

 

         2.3. Flash the project on the FRDM-KW36 client board (Ctrl + D). Stop the debug session (Ctrl + Shift + D). The default linker configurations of the project allow the OTAP client service application to be flashed with the proper memory offset.

 

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

 

This section provides the steps needed to test the OTAP software on the FRDM-KW36 board.

  1. Program the OTAP bootloader on the FRDM-KW36.

    1.1 Drag and drop to the FRDM-KW36 client board the OTAP bootloader prebuilt binary from the following path.
    <SDK_download_root>\tools\wireless\binaries\bootloader_otap_frdmkw36.bin
  2. Program the OTAP client application on the FRDM-KW36

    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 Set the storage configurations.       

               a. Search in the OTAP ATT client project the app_preinclude.h file located in the source folder in the workspace.
                     • To select External Flash storage, set the gEepromType_d define to "gEepromDevice_AT45DB041E_c"
                     • To select FlexNVM storage, set the gEepromType_d define to "gEepromDevice_InternalFlash_c"

 

               b. Go to Project/Properties, a new window will appear. Then, open the C/C++ Build/Settings/Linker/Miscellaneous perspective.
                     • To select External Flash storage, press the icon below to remove the "--defsym=gUseInternalStorageLink_d=1" flag.

 

 

                     • To select FlexNVM storage, press the icon below and add the "--defsym=gUseInternalStorageLink_d=1" flag

 

 

      2.5. 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. Press the “SW2” button on the FRDM-KW36 board to start advertising.

  4. Create a connection with the found 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 FRDM-KW36 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, this is located at the following path.

    <SDK_download_root>\boards\frdmkw36\wireless_examples\bluetooth\glucose_s\freertos\iar\glucose_s_freertos.eww

  2. Open the project options window (Alt+F7). In Linker/Config window, edit the “Configuration file symbol definitions” textbox with the following linker flags. This is needed to set up the same linker configuration as the OTAP client service application.

    gUseNVMLink_d=1

    gEraseNVMLink_d=1

    gUseBootloaderLink_d=1

    gUseInternalStorageLink_d=0

    __ram_vector_table__=1

  3. 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.

  4. Rebuild the project.

  5. Search the S-Record file (.srec) in the following path.

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

 

Appendix B. Creating an S-Record image file for FRDM-KW36 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. Unzip the FRDM-KW36 SDK package.
  3. Locate the "MKW36Z512xxx4_connectivity.ld" linker file at <SDK_root>/middleware/wireless/framework_5.4.4/Common/devices/MKW36Z4/gcc. Drag and drop the file on the source folder of your project in the MCUXpresso workspace as shown below.
  4. Open the "Project/Properties" window and select "C/C++Build/Settings". Next, go to the the "MCU Linker/Managed Linker Script" perspective and edit the linker script name to "MKW36Z512xxx4_connectivity.ld".
  5. Then, open the C/C++ Build/Settings/Linker/Miscellaneous perspective. 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