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
IAR Embedded Workbench IDE or MCUXpresso IDE
Download both, SDK FRDM-KW41Z and SDK USB-KW41Z.
Hardware Requirements
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.
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 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.
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.
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.
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.
To select the External Flash storage method, set the "gEepromType_d" define to "gEepromDevice_AT45DB041E_c"
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.
To select the External Flash storage method, remove the "gUseInternalStorageLink_d=1" linker flag
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.
To select the External Flash storage method, set the "gEepromType_d" define to "gEepromDevice_AT45DB041E_c"
To select the Internal Flash storage method, set the "gEepromType_d" define to "gEepromDevice_InternalFlash_c"
Configure the linker file.
To select the External Flash storage method, are not required any changes in the project from this point. You can skip this step.
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
Save the S-Record file created with the steps in the last section in your smartphone at a known location.
Open the IoT Toolbox App and select OTAP demo. Press “SCAN” to start scanning for a suitable advertiser.
Press the “SW4” button on the FRDM-KW41Z board to start advertising.
Create a connection with the found device.
Press “Open” and search the S-Record file.
Press “Upload” to start the transfer.
Once the transfer is complete, wait a few seconds until the bootloader has finished programming the new image. The new application will start automatically.
View full article