12.3.6.2 OTA Application Development

  1. Compile MCC auto generated project:

    • Compile the MCC auto generated project as the folloing.
    • Addressing the mandatory error (if not already done): User action required in app_user_edits.c. Follow the steps mentioned in the note and do the necessary changes. Then comment the #error message as below.

  2. Call BLE OTA Init function in "app.c" and add the include file.

    APP_OTA_HDL_Init();

    #include "app_ota/app_ota_handler.h"
  3. Call BLE OTA event handler function in "app_ble/app_otaps_handler.c".

    APP_OTA_EvtHandler(p_event);
    #include "../app_ota/app_ota_handler.h"
  4. Uncomment timer message ID's in "app_timer/app_timer.c" needed for OTA error handling and reboot timer. When the timer is fired, the related message is posted in freeRTOS application task queue.

  5. Define the timer message ID's in APP_MsgId_T structure in app.h.

    APP_TIMER_OTA_TIMEOUT_MSG,
    APP_TIMER_OTA_REBOOT_MSG,
  6. Call OTA timer handlers in APP_Tasks() in "app.c".

    else if(p_appMsg->msgId == APP_TIMER_OTA_TIMEOUT_MSG)
    {
    APP_OTA_Timeout_Handler();
    }
    else if(p_appMsg->msgId== APP_TIMER_OTA_REBOOT_MSG)
    {
    APP_OTA_Reboot_Handler();
    }
  7. Call DIS service Init function in "app.c" and add the include file.

    BLE_DIS_Add();
    #include "ble_dis/ble_dis.h"
  8. Call BLE gap connected/disconnected event handler in "app_ble/app_ble_handler.c" . app_ble_conn_handler.c handles the events and also restarts the Advertising when disconnected.

    APP_BleGapConnEvtHandler(p_event);
    #include "../app_ble_conn_handler.h"
  9. If the Standby Sleep mode low power functionality is enabled in the application, during the OTA upgrade procedues, it is required to disable the device entering into sleep mode. Add the below check in app_idle_task() when the BT_SYS_EnterSleepMode() is called.

    if (APP_OTA_HDL_GetOTAMode() != APP_OTA_MODE_OTA)
    BT_SYS_EnterSleepMode(RTC_Timer32FrequencyGet(), RTC_Timer32CounterGet()); 
  10. Compile the project for no errors.

API documentation reference: