NXP AN12979 User Manual

AN12979
KW38 - Integrating the OTAP Client Service into a Bluetooth LE Peripheral Device
Rev. 0 — 11/2020

Contents

1 Introduction

The Over The Air Programming (OTAP) NXP’s custom Bluetooth LE service provides the developers a solution to upgrade the software that the MCU contains. It removes the need of cables between the device to be upgraded (OTAP client) and the device that contains the new software (OTAP server).
The best way to take advantage of the OTAP service is to integrate it into the Bluetooth LE application. In that way, you can reprogram the device as many times as required.

2 OTAP client software

OTAP memory management during the update process describes the actual
implementation of the OTAP client software included in the SDK package for FRDM-KW38. Advantages of the OTAP service integration explains the importance of integrating OTAP client software into your application and the expected results.

2.1 OTAP memory management during the update process

1. By default, the KW38 flash memory is partitioned in three main regions:
• One 256 KB Program Flash array (P-Flash) divided into 2 KB sectors with a flash address range from 0x0000_0000 to
0x0003_FFFF.
1 Introduction......................................1
2 OTAP client software.......................1
2.1 OTAP memory management
during the update process........... 1
2.2 Advantages of the OTAP service
integration.................................... 6
3 Prerequisites................................... 7
3.1 Downloading and installing the
software development kit............. 7
4 Customizing a based Bluetooth LE
demo to integrate the OTAP service
........................................................ 9
4.1 Importing the OTAP Bluetooth LE service and framework software
into the HRS project.....................9
4.2 Main modifications in the source
files.............................................16
4.3 Modifications in project settings
and storage configurations........ 26
5 Testing the HRS-OTAP demo.......27
5.1 Preparing the OTAP client SDK
software..................................... 27
5.2 Creating an HRS-OTAP S-record
image to update the software.... 31
5.3 Creating an HRS S-record image to
update the software................... 33
5.4 Testing the HRS-OTAP software
...................................................36
Application Note
• One 256 KB FlexNVM array divided in 2 KB sectors with address range from 0x1000_0000 to 0x1003_FFFF.
• Alias memory with address range from 0x0004_0000 to 0x0007_FFFF. Writing or reading at the Alias range address modifies or returns the FlexNVM content respectively.
NXP Semiconductors
OTAP client software
Figure 1. MCU on-chip memory
2. The OTAP application splits the P-Flash into two independent parts, the OTAP bootloader and the OTAP client.
• The OTAP bootloader verifies if there is a new image available in 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.
Therefore, the OTAP client device needs to be programmed twice, first with the OTAP bootloader, and then with the Bluetooth LE application supporting OTAP client. The mechanism is created to have two different software coexisting in the same device and store each one in different memory regions. This is implemented by the linker file. In the KW38 device, the bootloader application has reserved an 8 KB slot of memory from 0x0000_0000 to 0x0000_1FFF, thus the rest of the memory is reserved, among other things, by the OTAP client application.
KW38 - Integrating the OTAP Client Service into a Bluetooth LE Peripheral Device, Rev. 0, 11/2020
Application Note 2 / 42
NXP Semiconductors
OTAP client software
Figure 2. OTAP client software
3. When generating a new image file for the OTAP 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 contain the Bootloader Flags at the corresponding address to work properly.
KW38 - Integrating the OTAP Client Service into a Bluetooth LE Peripheral Device, Rev. 0, 11/2020
Application Note 3 / 42
NXP Semiconductors
OTAP client software
Figure 3. Software update
4. At the connection state, the OTAP server sends the image packets, known as chunks, to the OTAP client via Bluetooth LE. The OTAP client can store these chunks in the external SPI flash (only available on FRDM-KW38 board), or in the on-chip FlexNVM region. The destination of the code is selectable in the OTAP client software.
Figure 4. Storage of the software update
5. 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. This is shown in the figure below.
KW38 - Integrating the OTAP Client Service into a Bluetooth LE Peripheral Device, Rev. 0, 11/2020
Application Note 4 / 42
NXP Semiconductors
OTAP client software
Figure 5. Simplified flow diagram of OTAP software
6. As 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 image. If the new image does not contain the OTAP service included, the device is not able to be programmed again due to the lack of OTAP functionality. For more description, see Advantages of
the OTAP service integration.
KW38 - Integrating the OTAP Client Service into a Bluetooth LE Peripheral Device, Rev. 0, 11/2020
Application Note 5 / 42
NXP Semiconductors
Figure 6. Memory content at the end of the software update process
OTAP client software
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.
These values might change with linker settings. You can inspect the effective memory addresses in your project.

2.2 Advantages of the OTAP service integration

As explained in OTAP memory management during the update process, the OTAP client software can reprogram the device only once, because it is overwritten by the new application.
Suppose that an OTAP client device is programmed with the OTAP client software and this device requests an update, for example, a Heart Rate Sensor (HRS). The image that the OTAP server sends to the OTAP client must be the HRS. After the reprogramming process, the device that was the OTAP client, now, has turned into an HRS. The HRS does not have the capabilities to communicate with the OTAP server and request for another update. But if the HRS image had included the OTAP client service as well, the device would have the possibility to request another software update, for example, a modified Glucose Sensor with OTAP Service.
As the Glucose Sensor software includes the OTAP client, the device can request another software update from the OTAP server. That way, the developer can continue upgrading the software as many times as needed. In other words, to be able to upgrade the software on the OTAP client device in the future, the application sent over the air should include OTAP service support.
KW38 - Integrating the OTAP Client Service into a Bluetooth LE Peripheral Device, Rev. 0, 11/2020
Application Note 6 / 42
NXP Semiconductors
Prerequisites
Figure 7. OTAP integration functionality example
This application note is intended as guidance to add the OTAP service to a Bluetooth LE application.

3 Prerequisites

This document is provided together with a functional demo of the OTAP service integration. The example is based on the HRS project, available in the FRDM-KW38 SDK package and developed on the MCUXpresso IDE platform. The following are required to complete the implementation of the HRS-OTAP integration demo:
• MCUXpresso IDE v11.0.0 or later
• FRDM-KW38 SDK
• HRS – OTAP demo package
• FRDM-KW38 board
• A smartphone with IoT Toolbox NXP app, available for Android and iOS.

3.1 Downloading and installing the software development kit

This chapter provides all the steps needed to download the SDK for the FRDM-KW38 used as a starting point.
1. Navigate to the MCUXpresso website.
2. Click Select Development Board. Log in with your registered account.
3. In the Search by Name field, search for FRDM-KW38. Then click the suggested board and click Build MCUXpresso SDK.
KW38 - Integrating the OTAP Client Service into a Bluetooth LE Peripheral Device, Rev. 0, 11/2020
Application Note 7 / 42
NXP Semiconductors
Prerequisites
Figure 8. Building the FRDM-KW38 SDK package
4. Select MCUXpresso IDE in the Toolchain/IDE combo box. Select the supported OS and provide the name to identify the package in your MCUXpresso Dashboard.
Figure 9. Customizing the installation settings
KW38 - Integrating the OTAP Client Service into a Bluetooth LE Peripheral Device, Rev. 0, 11/2020
Application Note 8 / 42
NXP Semiconductors
Customizing a based Bluetooth LE demo to integrate the OTAP service
5. Click Download SDK and it will take a few minutes until the system gets the package into your account on the MCUXpresso web page. Read and accept the license agreement. The SDK download starts automatically on your PC.
6. Open MCUXpresso IDE. Drag and drop the FRDM-KW36 SDK zip in the Installed SDK’s list.
Figure 10. Importing SDK package to MCUXpresso IDE
Now, you have downloaded and installed the SDK package for the FRDM-KW38 board.

4 Customizing a based Bluetooth LE demo to integrate the OTAP service

The following steps describe the process of customizing a Bluetooth LE demo imported from the SDK to integrate the OTAP service. This guide uses a Heart Rate Sensor project (HRS) as a starting point, so some steps may differ for another Bluetooth LE SDK example.

4.1 Importing the OTAP Bluetooth LE service and framework software into the HRS project

To integrate the OTAP client service in your application, you will need to import additional software that is not included in other SDK examples by default. Hence, the first step consists in to make a comparison between your project and the OTAP client SDK project to locate which files you will need to merge in your project to support this service in your application. A comparison between the HRS (left) and the OTAP client (right) is shown in Figure 11. Files and folders highlighted in red are part of the OTAP client software, but not in the HRS. Consequently, we need to incorporate these files in our HRS example to add the OTAP feature in this project. If you are interested in adding OTAP to other Bluetooth LE SDK projects or in your custom Bluetooth LE project, you need to look for the missing files and incorporate them following the same methodology described in this example.
KW38 - Integrating the OTAP Client Service into a Bluetooth LE Peripheral Device, Rev. 0, 11/2020
Application Note 9 / 42
NXP Semiconductors
Customizing a based Bluetooth LE demo to integrate the OTAP service
Figure 11. Source tree comparison
KW38 - Integrating the OTAP Client Service into a Bluetooth LE Peripheral Device, Rev. 0, 11/2020
Application Note 10 / 42
NXP Semiconductors
Customizing a based Bluetooth LE demo to integrate the OTAP service
The folders and files that are in OTAP but not in HRS, must be imported in your HRS project. For instance, in Figure 11, the followings are required to be imported:
• bluetooth -> profiles -> otap
• framework -> Flash -> External
• framework ->OtaSupport
• framework ->SerialManager ->source ->SPI_Adapter
• source -> common -> otap_client
• linkscripts -> main_text_section.ldt
To include these folders and source files in your project, perform the following steps.
1. Expand the bluetooth and framework folders in your workspace. Select the folder needed for updates and click the right mouse button. Select New -> Folder. The Folder window appears to provide the same name as the missing folder in the source directory, as shown in Figure 12.
KW38 - Integrating the OTAP Client Service into a Bluetooth LE Peripheral Device, Rev. 0, 11/2020
Application Note 11 / 42
NXP Semiconductors
Customizing a based Bluetooth LE demo to integrate the OTAP service
Figure 12. Creating the Bluetooth and Framework folders
2. Repeat Step 1 for the left folders. The result look similar as Figure 13.
KW38 - Integrating the OTAP Client Service into a Bluetooth LE Peripheral Device, Rev. 0, 11/2020
Application Note 12 / 42
NXP Semiconductors
Customizing a based Bluetooth LE demo to integrate the OTAP service
Figure 13. HRS directory updated
3. Copy the files inside all the recently created folders from the OTAP client and save it into your project. Ensure that all the files are in the same folder from the HRS side. For this example, these files are listed as below.
otap_interface.h and otap_service.c in the bluetooth -> profiles -> otap folder.
KW38 - Integrating the OTAP Client Service into a Bluetooth LE Peripheral Device, Rev. 0, 11/2020
Application Note 13 / 42
Loading...
+ 29 hidden pages