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 Nov 24, 2019
Version 13Show 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_SDK_2.2.1 v1.3.5.

Hardware Requirements

  1. FRDM-KW36 board.

KW36 Flash Memory Used for the OTAP Client Software

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 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. 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 and this is implemented by the linker file. In the KW36 device, the bootloader application has reserved an 8 KB slot of memory from 0x0000_0000 to 0x0000_1FFF, thus the left memory is reserved, among other things, by the OTAP client application.

  2. To create a new image file for the client device, the developer needs to specify that the code will be stored with an offset of 8 KB since the first addresses must be reserved for the bootloader (making use of the linker script). The new application should also contain the boot flags at the corresponding address to work properly. 

  3. At the connection state, the OTAP server sends the image packets (known as chunks) to the OTAP client via Bluetooth LE. The OTAP client device can store these chunks, in the first instance, at the external SPI flash (only available on the FRDM-KW36 board) or the On-Chip FlexNVM memory. The destination of the code is selectable in the OTAP client software.

     

  4. When the transfer of the image has finished, and all chunks were sent from the OTAP server to the OTAP client, the OTAP client software writes information, such as the source of the image update (external flash or FlexNVM) 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 command to reprogram the MCU with the new application. Due to the new application was built with an offset of 8 KB, the OTAP bootloader programs the device starting from the 0x0000_2000 address and the OTAP client application is overwritten by the new image, then the OTAP bootloader triggers a command to start the execution of the new code.

     

 

NOTE

In practice, the boundary created between the OTAP client software and the software update addresses when the internal storage is enabled is not placed exactly in the boundary of the P-Flash and FlexNVM memory regions. Even more, these values might change depending on your linker settings. You can inspect the effective memory addresses in your project.

 

Programming the OTAP Bootloader and the OTAP Client in IAR Embedded Workbench IDE

  1. Open the "MKW36Z512xxx4_PD_bootloader.icf" linker file located at the following path, using your preferred text editor:

    <SDK_download_path>\boards\frdmkw36\wireless_examples\framework\bootloader_otap\bm\iar\ MKW36Z512xxx4_PD_bootloader.icf

  2. Search the “__region_RAM_start__” and “__region_RAM_end__”  symbols and edit the values as follows:
    define symbol __region_RAM_start__ = 0x1FFFC000;
    define symbol __region_RAM_end__ = 0x1FFFDFFF;
  3. Open the OTAP Bootloader software in the following path:

    <SDK_download_path>\boards\frdmkw36\wireless_examples\framework\bootloader_otap\bm\iar bootloader_otap_bm.eww

  4. Program the project clicking on the "Download and Debug" icon (Ctrl + D). Once the FRDM-KW36 was programmed, stop the debug session  (Ctrl + Caps Lock + D).
  5. Open the OTAP Client project located in the following path:

    <SDK_download_root>\boards\frdmkw36\wireless_examples\bluetooth\otac_att\freertos\iar\otac_att_freertos.eww

  6. Select the storage configurations
    1. Search in the OTAP Client project the "app_preinclude.h" file located in the source folder in the workspace.
      • To select external storage, set the "gEepromType_d" define to "gEepromDevice_AT45DB041E_c"
      • To select internal storage, set the "gEepromType_d" define to "gEepromDevice_InternalFlash_c"
    2. Open the project options window (Alt + F7). In Linker->Config window update the "gUseInternalStorageLink_d" linker flag.
      • To select external storage, remove the "gUseInternalStorageLink=1" flag in the "Configuration file symbol definitions" textbox
      • To select internal storage, add the "gUseInternalStorageLink=1" flag in the "Configuration file symbol definitions" textbox
  7. Remove the "gEraseNVMLink_d=1" linker flag at the "Configuration file symbol definitions" textbox.
  8. Save the changes.
  9. Program the project clicking on the "Download and Debug" icon (Ctrl + D). Once the FRDM-KW36 was programmed, stop the debug session  (Ctrl + Caps Lock + D).

 

Creating an SREC Software Update for OTAP Client in IAR Embedded Workbench IDE

  1. Open the connectivity project that you want to program using the OTAP bootloader from your SDK. This example will make use of the heart rate sensor project, this is located at the following path:<SDK_download_root>\boards\frdmkw36\wireless_examples\bluetooth\hrs\freertos\iar\hrs_freertos.eww
  2. Open the project options window (Alt+F7). In Linker->Config window, edit the “Configuration file symbol definitions” textbox, including the "gUseBootloaderLink_d=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 the "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\hrs\freertos\iar\debug\hrs_freertos.srec

 

Programming the OTAP Bootloader and the OTAP Client in MCUXpresso IDE

  1. Open MCUXpresso IDE. Click on the “Import SDK example(s)” option in the “Quickstart Panel” view.
  2. Click twice on the frdmkw36 icon.
  3. Search the OTAP Bootloader example at: wireless_examples->framework->bootloader_otap. Click on the “finish” button.
  4. Select the OTAP Bootloader project in the workspace. Navigate to Project->Properties->C/C++Build->MCU settings. Edit the following fields in the “Memory details” section. Save the changes.                         
  5. Clean and build the project. Flash the project on the FRDM-KW36 board.
  6. Follow steps 1 to 3 to import the OTAP Client project. Search “otac_att” and select the desired version. Click on the “Finish” button.                     
  7. Set the storage configurations:
    1. Open the "app_preinclude.h" file located in the source folder of the project:
      • To select external storage, set the "gEepromType_d" define to "gEepromDevice_AT45DB041E_c"
      • To select internal storage, set the "gEepromType_d" define to "gEepromDevice_InternalFlash_c"
    2. Navigate to Project->Properties->C/C++Build->MCU settings.
      • To select external storage, configure the following fields:
      • To select internal storage, configure the following fields:
  8. Clean and build the project. Flash the project on the FRDM-KW36 board.

Creating an SREC Software Update for OTAP Client in MCUXpresso IDE

  1. Import the connectivity project that you want to program using the OTAP bootloader from MCUXpresso IDE. This example will make use of the heart rate sensor project.
  2. Navigate to Project->Properties->C/C++Build->MCU settings. Configure the following fields and save the changes:  
  3. Navigate to your workspace. Locate the “linkscripts” folder and include into it the following file:<SDK_download_root>\middleware\wireless\framework_5.4.5\Common\devices\MKW36Z4\mcux\linkscript_bootloader\main_text_section.ldt
  4. Open the “end_text.ldt” linker script and remove the “BYTE” and “FILL” statements:   
  5. Navigate to the workspace. Locate the “framework” folder and include into it the “OtaSupport” folder located in the following path:<SDK_download_root>\middleware\wireless\framework_5.4.5
  6. Navigate to "Project->Properties" in MCUXpresso IDE. Go to “C/C++ Build->Settings->Tool Settings->MCU C Compiler->Includes”. Click on the icon next to “Include paths” textbox (see figure below). A new window will appear, then click on the “Workspace” button.
  7. Deploy your directory tree in the folder selection window. Select the “framework->OtapSupport->Interface” folder and click the “OK” button to save the changes. Ensure that the path was imported onto the “Include paths” view.
  8. Repeat steps 5 to 7 to include in the “framework->Flash” folder, the “External” folder located in the following path:

    <SDK_download_root>\middleware\wireless\framework_5.4.5\Flash

  9. Save and 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 the “Debug” folder in the workspace with “.s19” extension.

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

 


4 people found this helpful

Attachments

    Outcomes