This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

DFU OTA for Custom Application

Hi,

I have implemented a custom application(Lets name that file app.hex) which works and sends the data to phone via BLE on my nrf51822 DK. I am using the s110 v8 softdevice(Lets name it sd.hex). I followed the tutorial for DFU OTA and compiled the project "dfu_dual_blank_ble_s110_pca10028.uvprojx" to generate the dual blank DFU hex file. (Lets name it dfu.hex) Firstly I erased my development kit IC completely from nRFgo Studio. Programmed the softdevice, sd.hex file on the board. Then I compiled and burned the chip with "dfu_dual_blank_ble_s110_pca10028.uvprojx" directly from my Kiel platform. I was able to detect the "DfuTarg" from the Nordic nRF Toolbox App in phone.

Following the INIT file generation mentioned in the pdf here, I was able to create a zip file(with just the application specs) which I could load onto the phone and reprogram the firmware with app.hex, successfully with the zip file .

So as of now, DFU over BLE was possible for me.

Here is the problem, I cant seem to program app.hex with dfu.hex from the Nordic nRFgo Studio. Here is my current procedure in sequence.

  1. Program the sd.hex from Nordic nRFgo Studio.
  2. Program the dfu.hex from Nordic nRFgo Studio.
  3. Program the app.hex from Nordic nRFgo Studio.

The problem is even after doing all the above steps, the DK is still advertising with the name "DfuTarg" although I have programmed it advertise with a different name in the app.hex (I have verified app.hex separately to see its advertising name and it works correctly)

So my question is how do I burn the app.hex with a dual blank bootloader first time(which can be later reflashed with say app2.hex, although I have figured out this issue of OTA DFU from phone)?

Parents
  • The answer to the original question is solved by adding app_valid_setting_apply.hex from here.

    I wanted to create a complete guide for newbies to add DFU capabilities to their Custom Application so that its easy for anyone else to get it working. So here it is.

    DFU integration on Custom Application:

    Please Note: Following notes are a dummy's guide to get buttonless DFU working with over the air update from phone and does not focus on teaching what DFU is or the logic flow of the code.

    Reference Guide: Follow the steps mentioned here to the word.

    Simpler way is to navigate to ...\examples\ble_peripheral\ble_app_hrs\pca10028\s110_with_dfu\arm5_no_packs\ble_app_hrs_s110_with_dfu_pca10028.uvprojx and open its main.c file.

    What we are trying to achieve is to make ble_app_hrs's main.c same as your custom applications by adding contents from the former to the latter.

    Tip: You can use plugins in tools like Notepad++ for comparing both files side by side.

    • The application must include Device Manager. Check here to add them. (Do everything mentioned here) or see the more cryptic version here.

    • Search for BLE_DFU_APP_SUPPORT in the ble_app_hrs's main.c and add ALL sections inside

    #ifdef BLE_DFU_APP_SUPPORT .... #endif

    to your custom applications main.c

    • Other Points to note/double check in particular

    • Make sure you define BLE_DFU_APP_SUPPORT in your main.c by adding the following line on the top

      #define BLE_DFU_APP_SUPPORT

    • Also change #define IS_SRVC_CHANGED_CHARACT_PRESENT 0 to #define IS_SRVC_CHANGED_CHARACT_PRESENT 1

    • Comment out the following case sections in on_ble_evt(ble_evt_t * p_ble_evt) // You would have done this in the device manager section

    1. case BLE_GAP_EVT_DISCONNECTED:
    2. case BLE_GAP_EVT_SEC_PARAMS_REQUEST:
    3. case BLE_GATTS_EVT_SYS_ATTR_MISSING:

    Make sure values of following are set as below in device_manager_cnfg.h

    #define DEVICE_MANAGER_APP_CONTEXT_SIZE    16	
    
    #define DM_GATT_CCCD_COUNT               4
    
    • Make sure to add device_manager_init(erase_bonds); in main.c

    Add these lines before anywhere before services_init(); Order somehow matters and I wasted a couple of hours because of this.

    • Add following lines to ble_stack_init() function

      // Register with the SoftDevice handler module for BLE events. err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch);' APP_ERROR_CHECK(err_code);

    • After adding all the contents do the following section on "Including DFU files in application" as mentioned here.

    • Once you did all the above and the project compiles properly. Get the compiled hex file(Lets say its app.hex) Get your softdevice, sd.hex(I am using s110 v8) and app_valid_setting_apply.hex from here.

    • Generate your DFU hex file by following the tutorial from here. I use a dual blank DFU. You can learn more about DFU here.

    • Now you have 4 files, 'app.hex, sd.hex, dfu.hex, app_valid_setting_apply.hex' . Combine them using merge.exe to get combined.hex (Check here to see how to use merge.exe)

    • Flash the file combined.hex file via nrfjprog(Check here to see how to use nrfjprog.exe) to your device. Now Restart the device.

    • Open up nRF Master Control Panel on your Android phone and connect to your device. You would see DFU symbol on top right after connecting. Select you new application file and the associated .dat file(Check here to see how) and upload.

    • Once the upload is complete, restart the device and you should have the new firmware running uploaded over the air.

    Cheers. Hope this helps someone. Because I had a hard time getting this working and I don't want someone else to go through the same.

    Special Thanks to @Alex for helping me fix my issues. :)

Reply
  • The answer to the original question is solved by adding app_valid_setting_apply.hex from here.

    I wanted to create a complete guide for newbies to add DFU capabilities to their Custom Application so that its easy for anyone else to get it working. So here it is.

    DFU integration on Custom Application:

    Please Note: Following notes are a dummy's guide to get buttonless DFU working with over the air update from phone and does not focus on teaching what DFU is or the logic flow of the code.

    Reference Guide: Follow the steps mentioned here to the word.

    Simpler way is to navigate to ...\examples\ble_peripheral\ble_app_hrs\pca10028\s110_with_dfu\arm5_no_packs\ble_app_hrs_s110_with_dfu_pca10028.uvprojx and open its main.c file.

    What we are trying to achieve is to make ble_app_hrs's main.c same as your custom applications by adding contents from the former to the latter.

    Tip: You can use plugins in tools like Notepad++ for comparing both files side by side.

    • The application must include Device Manager. Check here to add them. (Do everything mentioned here) or see the more cryptic version here.

    • Search for BLE_DFU_APP_SUPPORT in the ble_app_hrs's main.c and add ALL sections inside

    #ifdef BLE_DFU_APP_SUPPORT .... #endif

    to your custom applications main.c

    • Other Points to note/double check in particular

    • Make sure you define BLE_DFU_APP_SUPPORT in your main.c by adding the following line on the top

      #define BLE_DFU_APP_SUPPORT

    • Also change #define IS_SRVC_CHANGED_CHARACT_PRESENT 0 to #define IS_SRVC_CHANGED_CHARACT_PRESENT 1

    • Comment out the following case sections in on_ble_evt(ble_evt_t * p_ble_evt) // You would have done this in the device manager section

    1. case BLE_GAP_EVT_DISCONNECTED:
    2. case BLE_GAP_EVT_SEC_PARAMS_REQUEST:
    3. case BLE_GATTS_EVT_SYS_ATTR_MISSING:

    Make sure values of following are set as below in device_manager_cnfg.h

    #define DEVICE_MANAGER_APP_CONTEXT_SIZE    16	
    
    #define DM_GATT_CCCD_COUNT               4
    
    • Make sure to add device_manager_init(erase_bonds); in main.c

    Add these lines before anywhere before services_init(); Order somehow matters and I wasted a couple of hours because of this.

    • Add following lines to ble_stack_init() function

      // Register with the SoftDevice handler module for BLE events. err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch);' APP_ERROR_CHECK(err_code);

    • After adding all the contents do the following section on "Including DFU files in application" as mentioned here.

    • Once you did all the above and the project compiles properly. Get the compiled hex file(Lets say its app.hex) Get your softdevice, sd.hex(I am using s110 v8) and app_valid_setting_apply.hex from here.

    • Generate your DFU hex file by following the tutorial from here. I use a dual blank DFU. You can learn more about DFU here.

    • Now you have 4 files, 'app.hex, sd.hex, dfu.hex, app_valid_setting_apply.hex' . Combine them using merge.exe to get combined.hex (Check here to see how to use merge.exe)

    • Flash the file combined.hex file via nrfjprog(Check here to see how to use nrfjprog.exe) to your device. Now Restart the device.

    • Open up nRF Master Control Panel on your Android phone and connect to your device. You would see DFU symbol on top right after connecting. Select you new application file and the associated .dat file(Check here to see how) and upload.

    • Once the upload is complete, restart the device and you should have the new firmware running uploaded over the air.

    Cheers. Hope this helps someone. Because I had a hard time getting this working and I don't want someone else to go through the same.

    Special Thanks to @Alex for helping me fix my issues. :)

Children
Related