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

How can I use buttonless DFU with NUS

I am using SDK 14.1.0 S132 for PCA0040 board

i want to combine the next two examples:

examples\ble_peripheral\ble_app_buttonless_dfu

and

examples\ble_peripheral\ble_app_uart

**but I got NO_MEM error after

err_code = ble_dfu_buttonless_async_svci_init(); APP_ERROR_CHECK(err_code);

anyone help to find the reason ?**


Here isthe code:

static ble_uuid_t m_adv_uuids[] = {												
    {BLE_UUID_NUS_RX_SERVICE, NUS_SERVICE_UUID_TYPE},
    {BLE_DFU_SERVICE_UUID, 0x03},
    {BLE_UUID_DEVICE_INFORMATION_SERVICE, BLE_UUID_TYPE_BLE}
};

#ifndef NRF_SDH_BLE_VS_UUID_COUNT
#define NRF_SDH_BLE_VS_UUID_COUNT 4
#endif

static void services_init(void)
{
    uint32_t       err_code;
    ble_nus_init_t nus_init;

    memset(&nus_init, 0, sizeof(nus_init));

    nus_init.data_handler = nus_data_handler;

    err_code = ble_nus_init(&m_nus, &nus_init);
    APP_ERROR_CHECK(err_code);
	
    ble_dfu_buttonless_init_t dfus_init =
    {
        .evt_handler = ble_dfu_evt_handler
    };

    // Initialize the async SVCI interface to bootloader.
    err_code = ble_dfu_buttonless_async_svci_init();
    APP_ERROR_CHECK(err_code);


    err_code = ble_dfu_buttonless_init(&dfus_init);
    APP_ERROR_CHECK(err_code);
}

static void advertising_init(void)
{
    uint32_t               err_code;
    ble_advertising_init_t init;

    memset(&init, 0, sizeof(init));

    init.advdata.name_type          = BLE_ADVDATA_FULL_NAME;
    init.advdata.include_appearance = true;
    init.advdata.flags              = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;

    init.srdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
    init.srdata.uuids_complete.p_uuids  = m_adv_uuids;

    init.config.ble_adv_fast_enabled  = true;
    init.config.ble_adv_fast_interval = APP_ADV_INTERVAL;
    init.config.ble_adv_fast_timeout  = APP_ADV_TIMEOUT_IN_SECONDS;

    init.evt_handler = on_adv_evt;

    err_code = ble_advertising_init(&m_advertising, &init);
    APP_ERROR_CHECK(err_code);


    ble_advertising_conn_cfg_tag_set(&m_advertising, APP_BLE_CONN_CFG_TAG);
}
Parents
  • You need to flash the bootloader to your nrf52832 since nrf_dfu_svci_vector_table_set() which is called by ble_dfu_buttonless_async_svci_init() will check if there is a bootloader present or not. If it does not see the bootloader start address written to UICR, then it will return NRF_ERROR_NO_MEM

    uint32_t nrf_dfu_svci_vector_table_set(void)
    {
        uint32_t err_code;
    
        if (NRF_UICR->NRFFW[0] != 0xFFFFFFFF)
        {
            NRF_LOG_INFO("Setting vector table to bootloader: 0x%08x", NRF_UICR->NRFFW[0]);
            err_code = sd_softdevice_vector_table_base_set(NRF_UICR->NRFFW[0]);
            if (err_code != NRF_SUCCESS)
            {
                NRF_LOG_ERROR("Failed running sd_softdevice_vector_table_base_set");
                return err_code;
            }
    
            return NRF_SUCCESS;
        }
    
        NRF_LOG_ERROR("No bootloader was found");
        return NRF_ERROR_NO_MEM;
    }
    
  • You will also need to create a settings hex using nrfutil and merge it with the bootloader hex so that you start the application, as explained in Appendix 1 of this blog post

  • Hi biorn-spockeli , I have the same problem. I tested : https://devzone.nordicsemi.com/b/blog/posts/getting-started-with-nordics-secure-dfu-bootloader and success . But now , I want to combine ble_app_buttonless_dfu and ble_app_uart . Please show me solution . I have to : 

    1. Flash project bootloader_secure_ble as bootloader 

    2. Using nrfutil make zip file (application + my private key) 

    3. update zip file via DFU to my KIT via Android 

    Or 

    Merge bootloader hex + application (buttonless+nus) using nrfutil , but how to use my private key .

    Please guide me using nrfutil to merge 2 file hex . If I understand wrong , please show me how to fix

  • : You cannot simply merge the two application hex files. You have to either add the DFU service to the ble_app_uart example or add the Nordic UART service to the ble_app_buttonless_dfu example. I would recommend the first, so start by copying the code from services_init() in the ble_app_buttonless_dfu to the services_init() function in ble_app_uart. Make sure you add the files in the nRF_DFU folder, i.e. ble_dfu.c, ble_dfu_bonded.c and ble_dfu_unbonded.c to the ble_app_uart example. Make sure that you change NRF_SDH_BLE_VS_UUID_COUNT to 2 in sdk_config.h as well as increase the RAM allocated to the SoftDevice. 

Reply
  • : You cannot simply merge the two application hex files. You have to either add the DFU service to the ble_app_uart example or add the Nordic UART service to the ble_app_buttonless_dfu example. I would recommend the first, so start by copying the code from services_init() in the ble_app_buttonless_dfu to the services_init() function in ble_app_uart. Make sure you add the files in the nRF_DFU folder, i.e. ble_dfu.c, ble_dfu_bonded.c and ble_dfu_unbonded.c to the ble_app_uart example. Make sure that you change NRF_SDH_BLE_VS_UUID_COUNT to 2 in sdk_config.h as well as increase the RAM allocated to the SoftDevice. 

Children
Related