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

Custom service + DFU

I've used DFU alongside with HRS and it seems to work fine.

This time I'm using a custom service and I'm trying to add a DFU alongside. They just don't seem to play well together.

How can a custom service mess up the DFU service? I've been through the usually suspects eg:

ble_enable_params.common_enable_params.vs_uuid_count = 2;

thanks,

Parents
  • I just re-started the merge now it works, I was just a lot more methodical this time around (it only took 3 tries). I'm using SDK 12.2, so the bootloader libs need to be updated

    Here were the steps (see other posts about modifying the bootloader files)

    modified:   sdk/components/ble/ble_services/ble_dfu/ble_dfu.c
    modified:   sdk/components/libraries/bootloader/ble_dfu/nrf_ble_dfu.c
    modified:   sdk/components/libraries/bootloader/dfu/nrf_dfu.c
    

    Add missing C files for my particular project:

    $(SDK_ROOT)/components/libraries/scheduler/app_scheduler.c
    $(SDK_ROOT)/components/libraries/crc32/crc32.c
    $(SDK_ROOT)/components/libraries/fds/fds.c
    $(SDK_ROOT)/components/libraries/util/sdk_mapped_flags.c
    $(PROJ_DIR)/nrf_dfu_flash_buttonless.c
    $(SDK_ROOT)/components/ble/common/ble_conn_state.c
    $(SDK_ROOT)/components/ble/ble_services/ble_dfu/ble_dfu.c
    $(SDK_ROOT)/components/ble/peer_manager/gatt_cache_manager.c
    $(SDK_ROOT)/components/ble/peer_manager/gatts_cache_manager.c
    $(SDK_ROOT)/components/ble/peer_manager/id_manager.c
    $(SDK_ROOT)/components/ble/nrf_ble_gatt/nrf_ble_gatt.c
    $(SDK_ROOT)/components/ble/peer_manager/peer_data.c
    $(SDK_ROOT)/components/ble/peer_manager/peer_data_storage.c
    $(SDK_ROOT)/components/ble/peer_manager/peer_database.c
    $(SDK_ROOT)/components/ble/peer_manager/peer_id.c
    $(SDK_ROOT)/components/ble/peer_manager/peer_manager.c
    $(SDK_ROOT)/components/ble/peer_manager/pm_buffer.c
    $(SDK_ROOT)/components/ble/peer_manager/pm_mutex.c
    $(SDK_ROOT)/components/ble/peer_manager/security_dispatcher.c
    $(SDK_ROOT)/components/ble/peer_manager/security_manager.c \

    I believe the peer manger stuff is needed for DFU just for the fds_init() call

    Edit sdk_config.h to add these changes:

    #define CRC32_ENABLED 1 #define PEER_MANAGER_ENABLED 1 #define APP_SCHEDULER_ENABLED 1 #define FDS_ENABLED 1

    Next is to add DFU service to my custom service module

    Add the following stock functions (body not pasted here):

    static void advertising_start(void)
    static void ble_dfu_evt_handler(ble_dfu_t * p_dfu, ble_dfu_evt_t * p_evt)
    static void pm_evt_handler(pm_evt_t const * p_evt)
    static void sys_evt_dispatch(uint32_t sys_evt)
    static void peer_manager_init(bool erase_bonds)
    

    Add the following to ble_stack_init

     ble_enable_params.common_enable_params.vs_uuid_count   = 2;
    // Register with the SoftDevice handler module for BLE events.
    err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch);
    APP_ERROR_CHECK(err_code);
    

    Add the following to services_init()

    ble_dfu_init_t dfus_init;
    
    // Initialize the Device Firmware Update Service.
    memset(&dfus_init, 0, sizeof(dfus_init));
    
    dfus_init.evt_handler                               = ble_dfu_evt_handler;
    dfus_init.ctrl_point_security_req_write_perm        = SEC_SIGNED;
    dfus_init.ctrl_point_security_req_cccd_write_perm   = SEC_SIGNED;
    
    err_code = ble_dfu_init(&m_dfus, &dfus_init);
    APP_ERROR_CHECK(err_code);
    

    Add the following to vle_evt_dispatch()

    ble_dfu_on_ble_evt(&m_dfus, p_ble_evt);
    

    Add the following to the BLE init function call

    peer_manager_init(true);
    

    Update the linker script

    SEARCH_DIR(.) GROUP(-lgcc -lc -lnosys)

    MEMORY { FLASH (rx) : ORIGIN = 0x1f000, LENGTH = 0x59000 RAM (rwx) : ORIGIN = 0x20002138, LENGTH = 0xdec8 BOOTLOADER_SETTINGS (rw) : ORIGIN = 0x0007F000, LENGTH = 0x1000 }

    SECTIONS { .bootloaderSettings(NOLOAD) : {

    } > BOOTLOADER_SETTINGS

    .fs_data : { PROVIDE(__start_fs_data = .); KEEP((.fs_data)) PROVIDE(__stop_fs_data = .); } > RAM .pwr_mgmt_data : { PROVIDE(__start_pwr_mgmt_data = .); KEEP((.pwr_mgmt_data)) PROVIDE(__stop_pwr_mgmt_data = .); } > RAM } INSERT AFTER .data;

    INCLUDE "nrf5x_common.ld"

Reply
  • I just re-started the merge now it works, I was just a lot more methodical this time around (it only took 3 tries). I'm using SDK 12.2, so the bootloader libs need to be updated

    Here were the steps (see other posts about modifying the bootloader files)

    modified:   sdk/components/ble/ble_services/ble_dfu/ble_dfu.c
    modified:   sdk/components/libraries/bootloader/ble_dfu/nrf_ble_dfu.c
    modified:   sdk/components/libraries/bootloader/dfu/nrf_dfu.c
    

    Add missing C files for my particular project:

    $(SDK_ROOT)/components/libraries/scheduler/app_scheduler.c
    $(SDK_ROOT)/components/libraries/crc32/crc32.c
    $(SDK_ROOT)/components/libraries/fds/fds.c
    $(SDK_ROOT)/components/libraries/util/sdk_mapped_flags.c
    $(PROJ_DIR)/nrf_dfu_flash_buttonless.c
    $(SDK_ROOT)/components/ble/common/ble_conn_state.c
    $(SDK_ROOT)/components/ble/ble_services/ble_dfu/ble_dfu.c
    $(SDK_ROOT)/components/ble/peer_manager/gatt_cache_manager.c
    $(SDK_ROOT)/components/ble/peer_manager/gatts_cache_manager.c
    $(SDK_ROOT)/components/ble/peer_manager/id_manager.c
    $(SDK_ROOT)/components/ble/nrf_ble_gatt/nrf_ble_gatt.c
    $(SDK_ROOT)/components/ble/peer_manager/peer_data.c
    $(SDK_ROOT)/components/ble/peer_manager/peer_data_storage.c
    $(SDK_ROOT)/components/ble/peer_manager/peer_database.c
    $(SDK_ROOT)/components/ble/peer_manager/peer_id.c
    $(SDK_ROOT)/components/ble/peer_manager/peer_manager.c
    $(SDK_ROOT)/components/ble/peer_manager/pm_buffer.c
    $(SDK_ROOT)/components/ble/peer_manager/pm_mutex.c
    $(SDK_ROOT)/components/ble/peer_manager/security_dispatcher.c
    $(SDK_ROOT)/components/ble/peer_manager/security_manager.c \

    I believe the peer manger stuff is needed for DFU just for the fds_init() call

    Edit sdk_config.h to add these changes:

    #define CRC32_ENABLED 1 #define PEER_MANAGER_ENABLED 1 #define APP_SCHEDULER_ENABLED 1 #define FDS_ENABLED 1

    Next is to add DFU service to my custom service module

    Add the following stock functions (body not pasted here):

    static void advertising_start(void)
    static void ble_dfu_evt_handler(ble_dfu_t * p_dfu, ble_dfu_evt_t * p_evt)
    static void pm_evt_handler(pm_evt_t const * p_evt)
    static void sys_evt_dispatch(uint32_t sys_evt)
    static void peer_manager_init(bool erase_bonds)
    

    Add the following to ble_stack_init

     ble_enable_params.common_enable_params.vs_uuid_count   = 2;
    // Register with the SoftDevice handler module for BLE events.
    err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch);
    APP_ERROR_CHECK(err_code);
    

    Add the following to services_init()

    ble_dfu_init_t dfus_init;
    
    // Initialize the Device Firmware Update Service.
    memset(&dfus_init, 0, sizeof(dfus_init));
    
    dfus_init.evt_handler                               = ble_dfu_evt_handler;
    dfus_init.ctrl_point_security_req_write_perm        = SEC_SIGNED;
    dfus_init.ctrl_point_security_req_cccd_write_perm   = SEC_SIGNED;
    
    err_code = ble_dfu_init(&m_dfus, &dfus_init);
    APP_ERROR_CHECK(err_code);
    

    Add the following to vle_evt_dispatch()

    ble_dfu_on_ble_evt(&m_dfus, p_ble_evt);
    

    Add the following to the BLE init function call

    peer_manager_init(true);
    

    Update the linker script

    SEARCH_DIR(.) GROUP(-lgcc -lc -lnosys)

    MEMORY { FLASH (rx) : ORIGIN = 0x1f000, LENGTH = 0x59000 RAM (rwx) : ORIGIN = 0x20002138, LENGTH = 0xdec8 BOOTLOADER_SETTINGS (rw) : ORIGIN = 0x0007F000, LENGTH = 0x1000 }

    SECTIONS { .bootloaderSettings(NOLOAD) : {

    } > BOOTLOADER_SETTINGS

    .fs_data : { PROVIDE(__start_fs_data = .); KEEP((.fs_data)) PROVIDE(__stop_fs_data = .); } > RAM .pwr_mgmt_data : { PROVIDE(__start_pwr_mgmt_data = .); KEEP((.pwr_mgmt_data)) PROVIDE(__stop_pwr_mgmt_data = .); } > RAM } INSERT AFTER .data;

    INCLUDE "nrf5x_common.ld"

Children
No Data
Related