Failed to allocate memory.

I am having nrf52833 module where I am attempting to run buttonless DFU for this I have made some changes in ble_app_uart_pca10100_s140.hex and have used 

  • SoftDevice as " s140_nrf52_7.0.1_softdevice.hex "
  • Bootloader as "secure_bootloader_ble_s140_pca10100.hex"
  • Have generated bootloader settings page by using command " 

    1. nrfutil settings generate --family NRF52 --application ble_app_uart_pca10100_s140.hex --application-version 3 --bootloader-version 2 --bl-settings-version 1 ble_settings.hex

    2. mergehex --merge ble_settings.hex secure_bootloader_ble_s140_pca10100.hex s140_nrf52_7.0.1_softdevice.hex ble_app_uart_pca10100_s140.hex --output ble_sd_dfu_settings_app.hex "

    After this I have flashed "ble_sd_dfu_settings_app.hex" But unable to see any BLE name flashing.Then I attempted to flash firstly "ble_settings.hex" , " s140_nrf52_7.0.1_softdevice.hex " , "secure_bootloader_ble_s140_pca10100.hex" and then debug the "ble_app_uart_pca10100_s140.hex" via SES. And I have noticed that it was showing "Failed to allocate memory when I send .zip via nrf connect"

Also after updating the .zip file once I am unable to send the .zip file again. Also it is showing  Secure DFU Service as "This service is empty"

 

I am unable to understand how to fix "Failed to allocate memory" error also what do DFU Service as "This service is empty" mean and how to resolve it?

Also when I flashed "ble_sd_dfu_settings_app.hex" why I was not able to see the BLE name? and when I flashed everything individually why does it show BLE name?

 

Parents
  • Hi,

    This should not be a problem if you use the sample out of the box, so I wonder which changes you have made? Can you share your code or a diff showing the changes?

    Also, which SDK version are you using? Based on the log and SoftDevice version I suspect SDK 16? If you are starting now, I would strongly suggest you use SDK 17.1.0 as that is compatible with the latest revision of our devices and also have many bug fixes etc. (Or even better, consider the nRF Connect SDK, ref nRF Connect SDK and nRF5 SDK statement).

  • As for the changes below are the changes that I have done in main.c -

    1. DFU-related #includes

    #include "nrf_power.h"
    #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_bootloader_info.h"
    2. Added app_shutdown_handler
    /**@brief Handler for shutdown preparation.
     *
     * @details During shutdown procedures, this function will be called at a 1 second interval
     *          untill the function returns true. When the function returns true, it means that the
     *          app is ready to reset to DFU mode.
     *
     * @param[in]   event   Power manager event.
     *
     * @retval  True if shutdown is allowed by this power manager handler, otherwise false.
     */
    static bool app_shutdown_handler(nrf_pwr_mgmt_evt_t event)
    {
        switch (event)
        {
            case NRF_PWR_MGMT_EVT_PREPARE_DFU:
                NRF_LOG_INFO("Power management wants to reset to DFU mode.");
                // YOUR_JOB: Get ready to reset into DFU mode
                //
                // If you aren't finished with any ongoing tasks, return "false" to
                // signal to the system that reset is impossible at this stage.
                //
                // Here is an example using a variable to delay resetting the device.
                //
                // if (!m_ready_for_reset)
                // {
                //      return false;
                // }
                // else
                //{
                //
                //    // Device ready to enter
                //    uint32_t err_code;
                //    err_code = sd_softdevice_disable();
                //    APP_ERROR_CHECK(err_code);
                //    err_code = app_timer_stop_all();
                //    APP_ERROR_CHECK(err_code);
                //}
                break;
    
            default:
                // YOUR_JOB: Implement any of the other events available from the power management module:
                //      -NRF_PWR_MGMT_EVT_PREPARE_SYSOFF
                //      -NRF_PWR_MGMT_EVT_PREPARE_WAKEUP
                //      -NRF_PWR_MGMT_EVT_PREPARE_RESET
                return true;
        }
    
        NRF_LOG_INFO("Power management allowed to reset to DFU mode.");
        return true;
    }

    3. Added buttonless_dfu_sdh_state_observer()

    /**@brief Register application shutdown handler with priority 0.
     */
    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)
    {
        if (state == NRF_SDH_EVT_STATE_DISABLED)
        {
            // Softdevice was disabled before going into reset. Inform bootloader to skip CRC on next boot.
            nrf_power_gpregret2_set(BOOTLOADER_DFU_SKIP_CRC);
    
            //Go to system off.
            nrf_pwr_mgmt_shutdown(NRF_PWR_MGMT_SHUTDOWN_GOTO_SYSOFF);
        }
    }

    4. Added ble_dfu_buttonless_evt_handler()
    /* nrf_sdh state observer. */
    NRF_SDH_STATE_OBSERVER(m_buttonless_dfu_state_obs, 0) =
    {
        .handler = buttonless_dfu_sdh_state_observer,
    };
    
    static void ble_dfu_buttonless_evt_handler(ble_dfu_buttonless_evt_type_t event)
    {
        ret_code_t    err_code;
    
        switch (event)
        {
            case BLE_DFU_EVT_BOOTLOADER_ENTER_PREPARE:
                NRF_LOG_INFO("Device is preparing to enter bootloader mode\r\n");
                break;
     
            case BLE_DFU_EVT_BOOTLOADER_ENTER:
                NRF_LOG_INFO("Device will enter bootloader mode\r\n");
                break;
     
            case BLE_DFU_EVT_BOOTLOADER_ENTER_FAILED:
                NRF_LOG_ERROR("Device failed to enter bootloader mode\r\n");
                break;
            default:
                NRF_LOG_INFO("Unknown event from ble_dfu.\r\n");
                break;
        }
    }

    5. Added the following highlighted part in services_init()


    6. Added the following highlighted part in main()


    7. I have changed the following in sdk_config.h
    • #define BLE_DFU_ENABLED 1
    • #define NRF_PWR_MGMT_CONFIG_AUTO_SHUTDOWN_RETRY 1
    • #define NRF_SDH_BLE_SERVICE_CHANGED 1

    8. Added following in "Preprocessor Definitions"

    BL_SETTINGS_ACCESS_ONLY 

    NRF_DFU_TRANSPORT_BLE = 1

    9. Created a new folder within the project and added the following files-

    which SDK version are you using? I am using SDK16.

  • I notice that you added a header file under your point 9. But header fiels are added by adding the path to the include path. So this makes me wonder if you have not added the path to the uttonless derirvice there? That would be \..\..\..\..\..\..\components\ble\ble_services\ble_dfu . This needs to be added.

    Do you get any warnings when you build? If so, can you share them?

Reply
  • I notice that you added a header file under your point 9. But header fiels are added by adding the path to the include path. So this makes me wonder if you have not added the path to the uttonless derirvice there? That would be \..\..\..\..\..\..\components\ble\ble_services\ble_dfu . This needs to be added.

    Do you get any warnings when you build? If so, can you share them?

Children
Related