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

Using nrf52840 to try to add dfu service in the hrs example failed (SDK15.3.0)

hello ,everyone,

I want to add the dfu service to the hrs example, but after I follow the step by step guide operation, I import the (settings+softdevice+bootloader+app) hybrid file into nrf52840. My phone does not receive his Bluetooth signal (even The basic hrs service won't run), so I think it should be a problem with my code. Can you provide an example of adding an app to other examples? Thank you very much for your reply!

Parents
  • : Which step-by-step guide have you been following? 

    If the application is not starting up properly, then you need to debug the application and look at the return codes from the functions that you have added. I assume that you have added the following code 

     ble_dfu_buttonless_init_t dfus_init = {0};
    
    dfus_init.evt_handler = ble_dfu_evt_handler;
    
    err_code = ble_dfu_buttonless_init(&dfus_init);
    APP_ERROR_CHECK(err_code);
    
    

    to services_init(). Set a breakpoint in app_error_handler_bare() in app_error.c and then look at the call stack if you hit the breakpoint, this will tell you which function that generated the error. 

    Best regards

    Bjørn

  • hello,I am using the tutorial for this website.http://www.sunyouqun.com/2018/04/nordic-ble-dfu-4-buttonless-app/

    it's Chinese, but all the changes are shown in the form of pictures. Now I explain the work I have done.

    first,Open the <sdk>\examples\ble_peripheral\ble_app_hrs project to make sure the project works

    1.Add source file
    Add a folder nRF_DFU to the project and add the following files:

    <sdk>\components\ble\ble_services\ble_dfu\ble_dfu.c
    <sdk>\components\ble\ble_services\ble_dfu\ble_dfu_bonded.c
    <sdk>\components\ble\ble_services\ble_dfu\ble_dfu_unbonded.c
    <sdk>\components\libraries\bootloader\dfu\nrf_dfu_svci.c

    2.Add Include directory
    Find User Include Directories in the project configuration window and add the following path:

    ../../../../../../components/libraries/bootloader
    ../../../../../../components/libraries/bootloader/ble_dfu
    ../../../../../../components/libraries/bootloader/dfu
    ../../../../../../components/libraries/svc
    If you use SEGGER Embedded Studio, you need to pay extra attention to the spaces at the end of these paths, which may result in not being recognized correctly.

    3.Add macro switch
    Find Preprocessor Definitions in the Project Configuration window and add the following items:

    NRF_DFU_SVCI_ENABLED
    NRF_DFU_TRANSPORT_BLE=1
    BL_SETTINGS_ACCESS_ONLY

    4.Configuring sdk_config
    In sdk_config.h, make the following changes:

    BLE_DFU_ENABLED = 1
    NRF_SDH_BLE_VS_UUID_COUNT += 1

    5.Add header file
    Add the following header file to main.c:

    #include "nrf_dfu_ble_svci_bond_sharing.h"
    #include "nrf_svci_async_function.h"
    #include "nrf_svci_async_handler.h"
    #include "ble_dfu.h"
    #include "nrf_power.h"
    #include "nrf_bootloader_info.h"

    6.Add code
    Open the main.c of the Buttonless sample project and copy the following functions into the main.c of the current project:

    static bool app_shutdown_handler(nrf_pwr_mgmt_evt_t event){};
    NRF_PWR_MGMT_HANDLER_REGISTER(app_shutdown_handler, 0);
    static void buttonless_dfu_sdh_state_observer(nrf_sdh_state_evt_t state, void * p_context){};
    NRF_SDH_STATE_OBSERVER(m_buttonless_dfu_state_obs, 0) = {};
    static void ble_dfu_evt_handler(ble_dfu_buttonless_evt_type_t event){};

    Add Buttonless DFU Service
    Add the DFU service at the end of the main.c/services_init function:

    ble_dfu_buttonless_init_t dfus_init = {0};
    
    // Initialize the async SVCI interface to bootloader.
    err_code = ble_dfu_buttonless_async_svci_init();
    APP_ERROR_CHECK(err_code);
    
    dfus_init.evt_handler = ble_dfu_evt_handler;
    
    err_code = ble_dfu_buttonless_init(&dfus_init);
    APP_ERROR_CHECK(err_code);  

    7.Adjust memory address
    Follow the steps above and walk down, you can already compile. Burn Softdevice and Application, open the serial port tool, you should see the log message prompts that the memory address and memory size need to be adjusted.

    (In this step, I didn't see any information on the serial port, so I don't know how to modify the RAM, maybe the memory of nrf52840 is enough)

    Then I can compile and get the app.hex file

    8.Bootloader settings

    I confirmed that I used the correct version of softdevice and bootloader (s140_nrf52_6.1.1_softdevice.hex and complie the file in sdk15.3.0/example/dfu/secure_bootloader/pca10056 folder to get the bootloader.hex), and then got the final hex file by the following command. 

    nrfutil settings generate --family NRF52840 --application app.hex --application-version 3 --bootloader-version 2 --bl-settings-version 1 settings.hex

    mergehex --merge bootloader.hex s140_nrf52_6.1.1_softdevice.hex --output production_final1.hex

    mergehex --merge production_final1.hex app.hex --output production_final2.hex

    mergehex --merge production_final2.hex settings.hex --output production_final.hex

    nrfjprog --eraseall -f NRF52

    nrfjprog -f NRF52 --program "production_final.hex" --verify  

    nrfjprog --reset -f NRF52

    Unfortunately, I didn't search for the nrf52840's Bluetooth link, and I didn't even see the led light blinking (the hrs example and the buttonless example will have a led light blinking at runtime), I don't know where I am having problems, maybe I need to configure flash RAM? Then I did not find a more suitable tutorial, I look forward to your reply.

  • Thanks for the detailed explanation. 

    Can you built the debug the application?

    You should be able to see how much RAM you need to allocate to the SoftDevice by examining the p_app_ram_start variable in nrf_sdh_ble_enable() which is called in ble_stack_init(). 

    ret_code_t nrf_sdh_ble_enable(uint32_t * const p_app_ram_start)
    {
        // Start of RAM, obtained from linker symbol.
        uint32_t const app_ram_start_link = *p_app_ram_start;
    
        ret_code_t ret_code = sd_ble_enable(p_app_ram_start);
        if (*p_app_ram_start > app_ram_start_link)
        {
            NRF_LOG_WARNING("Insufficient RAM allocated for the SoftDevice.");
    
            NRF_LOG_WARNING("Change the RAM start location from 0x%x to 0x%x.",
                            app_ram_start_link, *p_app_ram_start);
            NRF_LOG_WARNING("Maximum RAM size for application is 0x%x.",
                            ram_end_address_get() - (*p_app_ram_start));
        }
        else
        {
            NRF_LOG_DEBUG("RAM starts at 0x%x", app_ram_start_link);
            if (*p_app_ram_start != app_ram_start_link)
            {
                NRF_LOG_DEBUG("RAM start location can be adjusted to 0x%x.", *p_app_ram_start);
    
                NRF_LOG_DEBUG("RAM size for application can be adjusted to 0x%x.",
                              ram_end_address_get() - (*p_app_ram_start));
            }
        }
    
        if (ret_code == NRF_SUCCESS)
        {
            m_stack_is_enabled = true;
        }
        else
        {
            NRF_LOG_ERROR("sd_ble_enable() returned %s.", nrf_strerror_get(ret_code));
        }
    
        return ret_code;
    }
    

    To get the LOG output you need to make sure that NRF_LOG_ENABLED in sdk_config.h is set to 1. You also need to set which backend to use by setting either NRF_LOG_BACKEND_RTT_ENABLED or NRF_LOG_BACKEND_UART_ENABLED to 1.

    If its not the SD ram setting that is incorrect, then please set a app_error_handler_bare() in app_error.c and then look at the call stack if you hit the breakpoint, this will tell you which function that generated the error. 

    Best regards

    Bjørn

  • I think my problem may be that I don't know how to configure RAM memory after adding a service. Where can I configure the memory through the serial port? Similar to the following example: <warning> nrf_sdh_ble: RAM starts at 0x200020E0, can be adjusted to 0x200020F0.
    <warning> nrf_sdh_ble: RAM size can be adjusted to 0xDF10.
    <error> nrf_sdh_ble: sd_ble_enable() returned NRF_ERROR_NO_MEM.

Reply
  • I think my problem may be that I don't know how to configure RAM memory after adding a service. Where can I configure the memory through the serial port? Similar to the following example: <warning> nrf_sdh_ble: RAM starts at 0x200020E0, can be adjusted to 0x200020F0.
    <warning> nrf_sdh_ble: RAM size can be adjusted to 0xDF10.
    <error> nrf_sdh_ble: sd_ble_enable() returned NRF_ERROR_NO_MEM.

Children
No Data
Related