Modifying the Application

1. Copy the uart_cmsis sample application into your workspace. The C/C++ perspective opens and displays your newly copied project, as shown below in the "Bringing the Project Into the Workspace" figure.

Figure: Bringing the Project Into the Workspace

2. Add the FOTA software component to your project by using the RTE Configuration Wizard (the uart_cmsis.rteconfig file). When you select the FOTA component and click save, libfota.a, fota.bin, mkfotaimg.exe and the tool mkfotaimg.py are copied into your project, under RTE > Device > <device>, as shown in the "Adding the FOTA Software Component" figure.

 

Figure: Adding the FOTA Software Component

3. Modify the source code to set the FOTA version number and ID:
a. In app.h, define your version numbers and ID:

/*--------------------------------------------

* Application Version

* -------------------------------------------------------------------------------- */

 

#define APP_VER_ID "UART"

 

#define APP_VER_MAJOR 1

 

#define APP_VER_MINOR 0

 

#define APP_VER_REVISION 0

b. In app.c, include sys_fota.h and use the SYS_FOTA_VERSION macro to set the version:

#include "sys_fota.h"

 

/* ----------------------------------------------------------------------------

* Application Version

* ------------------------------------------------------------------------- */

SYS_FOTA_VERSION(APP_VER_ID, APP_VER_MAJOR, APP_VER_MINOR, APP_VER_REVISION);

4. Modify the sample application to activate the DFU when the FOTA_GPIO on the RSL EVB is connected to ground.
a. In app.h, define an appropriate GPIO as FOTA_GPIO. For example:

#define FOTA_GPIO 1

b. In app.c, modify the Initialize() function to configure GPIO1 as a GPIO input:

void Initialize(void)

{

...

/* Configure FOTA_GPIO as GPIO input */

SYS_GPIO_CONFIG(FOTA_GPIO, (GPIO_MODE_GPIO_IN | GPIO_LPF_DISABLE | GPIO_WEAK_PULL_UP | GPIO_6X_DRIVE));

...

}

c. In app.c, add the code below in the while(1) loop of the main() function, to start the DFU when the FOTA GPIO is connected to ground:

while (1)

{

...

 

/* Start update when FOTA_GPIO is connected to ground */

if ((Sys_GPIO_Read(FOTA_GPIO)) == 0)

{

Sys_Fota_StartDfu(0);

}

 

...

}

NOTE: If your application uses SysTick Timer, disable SysTick Timer before passing the control to FOTA DFU mode, Refer to Disable_SysTick_Timer() in the blinky_fota sample code.

The DFU component is activated by calling the Sys_Fota_StartDfu(mode) function defined in sys_fota.h. The mode value 0 is for an application without the Bluetooth Low Energy stack (for example, blinky), and 1 is for an application that uses the Bluetooth Low Energy stack (such as ble_peripheral_server), but this current release version does not support Bluetooth Low Energy sample applications.

5. Replace your linker script sections.ld file with the one that contains the FOTA placement, and also replace your startup.S file, as shown in the "Replacing the sections.ld and startup.S Files" figure. The new linker script and startup.S file can be copied from blinky_fota, or directly from the CMSIS-Pack root folder as follows:
◦ sections.ld: <CMSIS Pack root folder>> ONSemiconductor > <device> > <version> > firmware > source > lib > fota > app
◦ startup.s: <CMSIS Pack root folder> >ONSemiconductor > <device> > <version> > firmware > source > lib > fota > app > non_ble >

 

Figure: Replacing the sections.ld and startup.S Files

6. Modify the project post-build steps (see the "Post-Build Steps" figure) to generate the FOTA image in both Debug and Release build configurations, by going to Project > Properties > C/C++ Build > Settings > Build Steps > Post-build steps. Two steps are required to generate the .fota image. First, we need to generate the application sub-image .bin file using objcopy. Then, we use the mkfotaimg.py tool to generate the FOTA image (.fota file). Both commands can be concatenated with && and added to the post-build steps as in the example that follows. To use this command, copy the code from the Post-Build steps of the existing sample application blinky_fota, as the code in the text below is not directly copyable.

 

${cross_prefix}objcopy -O binary "${BuildArtifactFileName}" "${BuildArtifactFileBaseName}.bin" && "${ProjDirPath}/RTE/Device/RSL15/mkfotaimg.exe" -o "${BuildArtifactFileBaseName}.fota" "${ProjDirPath}/RTE/Device/RSL15/fota.bin" "${BuildArtifactFileBaseName}.bin"

 

Figure: Post-Build Steps

7. Build the uart_cmsis application. If no error occurs, the FOTA image (uart_cmsis.fota) can be found in the Debug or Release folder.