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?

 

  •  I have attached the code kindly find that.

    To test you can directly flash "ble_sd_dfu_settings_app.hex" it is the merge hex of bootloader+softdevice+ble settings. Open nrf Connect app and connect to ble, you will see that BLE is connected but then you can see that "Secure DFU service" is empty and cannot dump the buttonless2.zip file via DFU

    Also the same can be checked via SES debug where you will see that while debugging "ble_app_uart" it says "Failed to allocate memory"

    /cfs-file/__key/communityserver-discussions-components-files/4/5873.ble_5F00_app_5F00_uart.zip

    /cfs-file/__key/communityserver-discussions-components-files/4/Bootloader_5F00_Softdevice.zip

    /cfs-file/__key/communityserver-discussions-components-files/4/buttonless2.zip.....

  • Hi,

    The code that prints "Failed to allocate memory" is written by you and not found in any SDK code. It comes because you are using malloc, but have not added any support for dynamic memory. I do not understand why you do this though, as there does not seem to be any reason for using dynamic memory here? (Generally it is best avoided, and particularily if there is no good reason for using it, as seems the case here).

    Regarding the service not working the problem is easy to spot when you check your errror codes. I see you commended out the APP_ERROR_CHECK after the call to ble_dfu_buttonless_init(), and this does not fix the issue - only masks it. Include the call, and you should see something like this:

    <error> app: ERROR 4 [NRF_ERROR_NO_MEM] at /home/eith/src/nrf5sdk/nRF5_SDK_16.0.0_98a08e2/examples/other_projects/ble_app_uartTest_327723/main.c:497
    PC at: 0x00031451

    Looking at the code this tells us that you got NRF_ERROR_NO_MEM returned from ble_dfu_buttonless_init(). So you know you need to debug there. And if you debug there you will see that the call to sd_ble_uuid_vs_add() fails. This is because NUS was added earlier, but in your sdk_config.h NRF_SDH_BLE_VS_UUID_COUNT is set to 1. This needs to be set to 2. Then you should run again, and you will get this error, as the SoftDevice now needs more RAM:

    <warning> nrf_sdh_ble: Insufficient RAM allocated for the SoftDevice.
    <warning> nrf_sdh_ble: Change the RAM start location from 0x20002AE8 to 0x20002AF8.
    <warning> nrf_sdh_ble: Maximum RAM size for application is 0x1D508.
    <error> nrf_sdh_ble: sd_ble_enable() returned NRF_ERROR_NO_MEM.
    <error> app: ERROR 4 [NRF_ERROR_NO_MEM] at /home/eith/src/nrf5sdk/nRF5_SDK_16.0.0_98a08e2/examples/other_projects/ble_app_uartTest_327723/main.c:695
    PC at: 0x0003189F

    Then you adjust the linker configuration as stated in the error message. And with that, it should work. A very important takeaway here is to not ignore errors.

  • Thank you so much for your effort I will follow what you have told me.  

Related