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

Device seems to crash when adding new BLE service

I've been trying to add a new BLE service to my device. I've followed the instructions in this tutorial, up to step 7 (so no characteristics or anything), but the device is not advertising. In fact, the software seems to fail entirely; it does not seem to make it past the advertising_init and services_init functions in the initialization sequence. (In main() the device is supposed to blink an LED after this sequence is finished, which it does not.)

I've done nothing to modify the code other than these changes specified in the tutorial. The software compiles and loads on the device without any warnings or errors. I've posted the relevant code below; let me know if you need any more information.

Parents
  • Generally, whenever you're seeing that the nRF device is not advertising after you flashed you should do the following:

    1. Start a debug session
    2. Set a breakpoint in app_error_handler_bare in app_error.c
    3. Run the code and if you end up in the error handler, examine the call stack and identify the function that caused the error.
    4. Look up the error code in the SDK/SoftDevice API documentation on http://infocenter.nordicsemi.com/

    Most likely you've not allocated enough RAM to the SoftDevice or you've passed incorrect parameters to the SoftDevice. 

    Best regards

    Bjørn

  • Hello Bjorn,

    It appears that I've not allocated enough RAM to the softdevice. How do I adjust this in SDK 11? All the tutorials I can find so far are for later SDK versions. (We plan to port our software to SDK 15 in a few weeks, but at the moment we're on a tight deadline and don't have time to do the port just yet.)

  • If you're using Keil then this is done under Options for Target -> Target -> Read/Write Memory Areas. 

    Increase the IRAM1 Start address and decrease the size accordingly, i.e. so that IRAM1 Start + IRAM1 Size <= Total RAM on your nRF5x device. 

    If you're using make and GCC you'll have to modify the linker script, i.e. the RAM Origin and Length

    MEMORY
    {
        FLASH (rx) : ORIGIN = 0x1c000, LENGTH = 0x64000
        RAM (rwx) : ORIGIN = 0x20002080, LENGTH = 0xdf80
    }

Reply
  • If you're using Keil then this is done under Options for Target -> Target -> Read/Write Memory Areas. 

    Increase the IRAM1 Start address and decrease the size accordingly, i.e. so that IRAM1 Start + IRAM1 Size <= Total RAM on your nRF5x device. 

    If you're using make and GCC you'll have to modify the linker script, i.e. the RAM Origin and Length

    MEMORY
    {
        FLASH (rx) : ORIGIN = 0x1c000, LENGTH = 0x64000
        RAM (rwx) : ORIGIN = 0x20002080, LENGTH = 0xdf80
    }

Children
  • I don't quite understand. If I want to increase the amount of memory allocated, shouldn't I decrease the origin and increase the length? Also, is there a good rule of thumb for how much extra memory to allocate for a new service?

  • You want to decrease the RAM allocated to the application, by increasing the origin( also the end address of the SoftDevice RAM section). So you're effectivly increasing the size of the SoftDevice RAM section by increasing the application RAM origin. 

    No, its a trial and error process so you'll have to increase move the origin upwards until the sd_ble_enable() call does not return the NO_MEM error code. We added a second parameter in the sd_ble_enable() call in S132 v3.0.0 which returns the application RAM origin for the configuration passed to the SoftDevice. 

  • Hello Bjorn,
    Once I started increasing the memory a bit, I started getting no error message (it was never hitting the breakpoint), and the device started pushing through RTT

    "sd_ble_enable: ram_start should be adjusted to 0x20001fe8

    RAM length should be adjusted to 0xe018"

    When I tried adjusting it to those values, it simply started printing "sd_ble_enable: RAM START at 0x20001FE8" before restarting the program from the beginning.

    It still doesn't hit the breakpoint in app_error.c, and it still isn't advertising.

  • Which SDK version are you using? The tutorial you're using is based on SDK v11.0.0 and the SoftDevices compatible with this SDK does not return the ram_start address.