Reprogramming a FRDM-KW41 board using the OTAP Client Software

Document created by Edgar Eduardo Lomeli Gonzalez Employee on Jul 30, 2019Last modified by Edgar Eduardo Lomeli Gonzalez Employee on Sep 2, 2019
Version 5Show Document
  • View in full screen mode

Introduction

This document guides to load a new software image in a KW41 device through Over The Air Programming bootloader. Also, are explained the details of how to set up the client software to change the storage method of the image.

 

Software Requirements

  1. IAR Embedded Workbench IDE or MCUXpresso IDE
  2. Download both, SDK FRDM-KW41Z and SDK USB-KW41Z.

Hardware Requirements

  1. FRDM-KW41Z board

 

OTAP Memory Management During the Update Process

The KW41 has a 512KB Program Flash with a flash address range from 0x0000_0000 to 0x0007_FFFF.

 

 

  1. The OTAP application splits the flash into two independent parts, the OTAP Bootloader, and the OTAP Client. The OTAP Bootloader verifies if there is a new image available at the OTAP Client side to reprogram the device. The OTAP Client software provides the Bluetooth LE custom service needed to communicate the OTAP Client device with the OTAP Server that contains the new image file (The OTAP Server device could be another FRDM-KW41Z connected to a PC with Test Tool or a Smartphone with IoT Toolbox app). Therefore, the OTAP Client device needs to be programmed twice, first with the OTAP Bootloader, then with the Bluetooth LE application supporting OTAP Client. The mechanism created to have two different software coexisting in the same device is storing each one in different memory regions. This functionality is implemented by the linker file. In the KW41 device, the bootloader has reserved a 16 KB slot of memory from 0x0000_0000 to 0x0003_FFFF, thus the left memory is reserved among other things, by the OTAP Client demo.
  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 built with an offset of 16 KB since the first addresses must be reserved for the OTAP Bootloader.
  3. In connection state, the OTAP server sends the image packets (known as chunks) to the OTAP Client device via Bluetooth LE. The OTAP Client device can store these chunks, in first instance, at the external SPI flash or the On-Chip Flash. The destination of the code is selectable in the OTAP Client software.
  4. When the connection has finished and all chunks were sent from the OTAP Server to the OTAP Client device, the OTAP Client software writes information, such as the source of the image update (external flash or internal flash) in a portion of memory known as Bootloader Flags and then resets the MCU to execute the OTAP Bootloader code. The OTAP Bootloader reads the Bootloader Flags to get the information needed to program the device and triggers a commando to reprogram the MCU with the new application. Due to the new application was built with an offset of 16 KB, the OTAP Bootloader programs the device starting from the 0x0000_4000 address and the OTAP Client application is overwritten by the new image, therefore, after the device has been reprogrammed through this method, cannot be programmed a second time as same. Finally, the OTAP Bootloader triggers a command to start the execution of the new code automatically.

 

 

Preparing the Software to Test the OTAP Client for KW41Z Device Using IAR Embedded Workbench

  • Program the OTAP Bootloader on the FRDM-KW41Z. Program the OTAP Bootloader software from the project included in the SDK FRDM-KW41Z at the following path, or you can simply drag and drop the pre-built binary from the following path.

 

        OTAP Bootloader Project:

         <SDK_2.2.0_FRDM-KW41Z_download_path>\boards\frdmkw41z\wireless_examples\framework\bootloader_otap\bm\iar\bootloader_otap_bm.eww

 

         OTAP Bootloader pre-built binary:

           <SDK_2.2.0_FRDM-KW41Z_download_path>\tools\wireless\binaries\bootloader_otap_frdmkw41z.bin

 

  • Open the OTAP Client project included in the SDK FRDM-KW41Z located in the following path.

         <SDK_2.2.0_FRDM-KW41Z_download_path>\boards\frdmkw41z\wireless_examples\bluetooth\otap_client_att\freertos\iar\otap_client_att_freertos.eww

 

  • Customize the OTAP Client software to select the storage method. Locate the app_preinclude.h header file inside the source folder at the workspace.
  1. To select the External Flash storage method, set the "gEepromType_d" define to "gEepromDevice_AT45DB041E_c                    
  2. To select the Internal Flash storage method, set the "gEepromType_d" define to "gEepromDevice_InternalFlash_c"

 

  • Configure the linker flags. Open the project options window (Alt + F7). In "Linker->Config" window, locate the "Configuration file symbol definitions" pane.
  1. To select the External Flash storage method, remove the "gUseInternalStorageLink_d=1" linker flag
  2. To select the Internal Flash storage method, add the "gUseInternalStorageLink_d=1" linker flag

 

 

  • Load the OTAP Client software on the FRDM-KW41Z board (Ctrl + D). Stop the debug session (Ctrl + Shift + D). The default linker configurations of the project allow the OTAP Client application to be stored with the proper memory offset.

 

Preparing the Software to Test the OTAP Client for KW41Z Device Using MCUXpresso IDE

  • Program the OTAP Bootloader on the FRDM-KW41Z. Program the OTAP Bootloader software from the project included in the SDK FRDM-KW41Z at the following path, or you can simply drag and drop the pre-built binary from the following path.

 

        OTAP Bootloader Project:

         wireless_examples->framework->bootloader_otap->bm

 

         OTAP Bootloader pre-built binary:

           <SDK_2.2.0_FRDM-KW41Z_download_path>\tools\wireless\binaries\bootloader_otap_frdmkw41z.bin

 

  • Click on "Import SDK examples(s)" option in the "Quickstart Panel" view.
  • Click twice on the frdmkw41z icon.

 

 

  • Open the OTAP Client project included in the SDK FRDM-KW41Z located in the following path.wireless_examples->bluetooth->otap_client_att->freertos

 

 

  • Customize the OTAP Client software to select the storage method. Locate the app_preinclude.h header file inside the source folder at the workspace.
  1. To select the External Flash storage method, set the "gEepromType_d" define to "gEepromDevice_AT45DB041E_c                    
  2. To select the Internal Flash storage method, set the "gEepromType_d" define to "gEepromDevice_InternalFlash_c"

 

  • Configure the linker file.
  1. To select the External Flash storage method, are not required any changes in the project from this point. You can skip this step.
  2. To select the Internal Flash storage method, search the linker file located in the SDK USB-KW41Z at the following path and replace instead of the default linker file at the source folder in the OTAP Client project. You can copy (Ctrl + C) the linker file from SDK USB-KW41Z and paste (Ctrl + V) on the workspace directly. A warning message will be displayed, select "Overwrite". 

 

       Linker file at the SDK USB-KW41Z:

       <SDK_2.2.0_USB-KW41Z_download_path>\boards\usbkw41z_kw41z\wireless_examples\bluetooth\otap_client_att\freertos\MKW41Z512xxx4_connectivity.ld

 

 

  • Save the changes in the project. Select "Debug" in the "Quickstart Panel". Once the project is already loaded on the device, stop the debug session.

 

Creating an S-Record Image File for FRDM-KW41Z OTAP Client in IAR Embedded Workbench

  • Open the connectivity project that you want to program using the OTAP Bootloader from your SDK FRDM-KW41Z. This example will make use of the glucose sensor project, this is located at the following path.

    <SDK_2.2.0_FRDM-KW41Z_download_path>\boards\frdmkw41z\wireless_examples\bluetooth\glucose_sensor\freertos\iar\glucose_sensor_freertos.eww

 

  • Open the project options window (Alt+F7). In Linker->Config window, add the following linker flag in the “Configuration file symbol definitions” textbox.

        gUseBootloaderLink_d=1

 

 

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

 

 

  • Rebuild the project.
  • Search the S-Record file (.srec) in the following path.<SDK_2.2.0_FRDM-KW41Z_download_path>\boards\frdmkw41z\wireless_examples\bluetooth\glucose_sensor\freertos\iar\debug

 

Creating an S-Record Image File for FRDM-KW41Z OTAP Client in MCUXpresso IDE

  • 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, this is located at the following path.

       wireless_examples->bluetooth->glucose_sensor->freertos

 

  • Search the linker file located in the SDK FRDM-KW41Z at the path below and replace instead of the default linker file at the source folder in the Glucose Sensor project. You can copy (Ctrl + C) the linker file from SDK FRDM-KW41Z and paste (Ctrl + V) on the workspace directly. A warning message will be displayed, select "Overwrite".

 

       Linker file at the SDK FRDM-KW41Z:

       <SDK_2.2.0_FRDM-KW41Z_download_path>\boards\frdmkw41z\wireless_examples\bluetooth\otap_client_att\freertos\MKW41Z512xxx4_connectivity.ld

 

 

  • Open the new "MKW41Z512xxx4_connectivity.ld" linker file. Locate the section placement of the figure below and remove the "FILL" and the "BYTE" statements.

 

   

 

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

 

 

Testing OTAP Client Demo Using IoT Toolbox App

  1. Save the S-Record file created with the steps in the last section 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 “SW4” button on the FRDM-KW41Z 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. 
1 person found this helpful

Attachments

    Outcomes