Creating an OTAP Software Update Basing on Driver Examples for KW36

Document created by Edgar Eduardo Lomeli Gonzalez Employee on Jan 10, 2020Last modified by Edgar Eduardo Lomeli Gonzalez Employee on May 5, 2020
Version 5Show Document
  • View in full screen mode

Introduction

Over The Air Programming is a custom Bluetooth LE service intended to update the software running on the device, removing the need of cables and a physical link. The following post: Reprogramming a KW36 device using the OTAP Client Software provides more information about how does it work and how to create a bootable software update for the KW36 based on a connectivity example. However, some applications require software updates that are not based on NXP's Bluetooth LE stack. This post provides the steps to create a software update using as the starting point the blinking LED example included in the SDK FRDM-KW36.

 

Creating an OTAP software update from LED Output SDK example

1- Import any example from the "driver_examples" folder on MCUXpresso IDE. This example uses the "led_output" project.

 

 

2- Create a new folder in the project named "linkscripts". To do it, select your project in the workspace, then click right mouse button and go to "New->Folder". Select your project in the "New Folder" window, and provide the name. See the following figures.

 

 

 

3- Unzip your FRDM-KW36 SDK. Then go to: <SDK_KW36_path>\middleware\wireless\framework_5.4.6\Common\devices\MKW36Z4\mcux\linkscript_bootloader. Drag and drop all files on the "linkscripts" folder on your project.

 

 

4- Remove the BYTE and FILL statements from the "end_text.ldt" linker script.

 

 

5- Select your project in the workspace. Go to Project->Properties->C/C++ Build->MCU Settings. You need to edit the "Memory details" pane to look as depicted in the figure following figure.

 

 

For edit, you can delete a section using the "Delete" button. You can add a Flash o RAM section using "Add Flash" and "Add RAM" buttons. To change the "Driver" fields, click on the icon next to the driver's name, then select the "FTFE_2K_PD.cfx" driver from the list. See the following figures. 

 

 

 

6- Add the following code on the application file (in this case, gpio_led_output.c in the source folder).

a) Include the following code at "Definitions" section. 

/* Boot Flags Support */
#define gBootValueForTRUE_c (0x00)
#if FSL_FEATURE_FLASH_PFLASH_BLOCK_WRITE_UNIT_SIZE == 4
#define gBootFlagUnprogrammed_c 0xFF,0xFF,0xFF,0xFF
#elif FSL_FEATURE_FLASH_PFLASH_BLOCK_WRITE_UNIT_SIZE == 8
#define gBootFlagUnprogrammed_c 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
#else
#error The gBootFlagUnprogrammed_c macro is not defined for this FSL_FEATURE_FLASH_PFLASH_BLOCK_WRITE_UNIT_SIZE.
#endif

b) Include the following code at "Prototypes" section.

/*! Structure containing the boot flags */
typedef struct __attribute__ ((__packed__))
{
unsigned char newBootImageAvailable[FSL_FEATURE_FLASH_PFLASH_BLOCK_WRITE_UNIT_SIZE];
unsigned char bootProcessCompleted[FSL_FEATURE_FLASH_PFLASH_BLOCK_WRITE_UNIT_SIZE];
unsigned char version[FSL_FEATURE_FLASH_PFLASH_BLOCK_WRITE_UNIT_SIZE];
unsigned char internalStorageAddr [FSL_FEATURE_FLASH_PFLASH_BLOCK_WRITE_UNIT_SIZE];
#if defined(CPU_K32W032S1M2VPJ_cm4) && (CPU_K32W032S1M2VPJ_cm4 == 1)
unsigned char sbkek[SBKEK_SIZE];
unsigned char magic[12];
#endif
}bootInfo_t;

c) Include the following code at "Variables" section.

/*! Variables used by the Bootloader */
#if defined(__IAR_SYSTEMS_ICC__)
#pragma location = "BootloaderFlags"
const bootInfo_t gBootFlags =
#elif defined(__GNUC__)
const bootInfo_t gBootFlags __attribute__ ((section(".BootloaderFlags"))) =
#elif defined(__CC_ARM)
volatile const bootInfo_t gBootFlags __attribute__ ((section(".BootloaderFlags"))) =
#else
#error "Compiler unknown!"
#endif
{
{gBootFlagUnprogrammed_c},
{gBootValueForTRUE_c},
{0x00, 0x02},
{gBootFlagUnprogrammed_c},
#if defined(CPU_K32W032S1M2VPJ_cm4) && (CPU_K32W032S1M2VPJ_cm4 == 1)
{PLACEHOLDER_SBKEK},
{BOOT_MAGIC_WORD}
#endif
};

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

 

 

Reprogramming KW36 with LED Output SDK example using the OTAP software

The SREC file created in this post can be used to reprogram the KW36 running the OTAP client software. Please visit this post: Reprogramming a KW36 device using the OTAP Client Software in which is explained the steps to run OTAP client software.

 

Please let me know any questions.

Attachments

    Outcomes