Intermittent problem restarting advertising: ENOMEM, failed to create advertising set

Hi all,

Short problem description: I am troubleshooting an issue with the nRF5340 wherein the device runs for some time, then eventually gets stuck with an err -12 (ENOMEM) when attempting to create an extended advertising set.

This is on a custom board with the Fanstel nRF5340 module. I am using nRF Connect SDK 1.7.1. I cannot upgrade this, because we have already made a declaration with the Bluetooth SIG for this product. I am using hci_rpmsg on the net core. The code I am troubleshooting runs on the app core.

There are two execution paths by which advertising gets restarted:

1) During normal operation, occasionally the app core receives updated manufacturer data for advertisement via SPI. When this happens, advertising is stopped, the advertising set is deleted, a new one created, and advertising is restarted. Normally, this mechanism will work fine, with no problems and runs indefinitely.

2) When a Bluetooth connection is established, advertising stops (by design). After the connection ends, in the callback for the disconnect, a worker task is queued up to restart advertising. this task does not delete or update the advertising set - it merely restarts advertising.

What happens is that if I connect to the device repeatedly - sometimes after 12 times, other times it might take 300 times - eventually I enter a state where the device has disconnected from Bluetooth and is trying to restart advertising and keeps getting the error ENOMEM when attempting to create the advertising set.

I can increase the number of extended advertising sets allowed (CONFIG_BT_EXT_ADV_MAX_ADV_SET), as has been suggested in other posts I have seen, and I did try that but immediately started to see erratic behavior, so I backed off the change, and I wanted to ask here some questions:

  • Is it better for me to, instead of increasing the number of advertising sets, to figure out what causes the problem and address it? The intent of the design is to have only one advertising set.
  • If I catch this exception, could I have code in place that will resolve the issue automatically, perhaps by deleting old advertising sets or somehow re-initializing advertising? What should that look like?  
  • Is it likely that this error occurs as a result of sloppy code on my side and could be prevented?

Thanks!

Scott

  • Hi Scott,

    If it exists under app/child_image, hci_rpmsg.conf  is included in the build, and used for the net core to configure submodules/settings.

  • Finally got this resolved, with the help of Nordic's insightful Edvin Holmseth, and wanted to share what I learned here in the DevZone post.

    Ultimately the problem was the way the app was set up to update advertising data. Previously, it would be advertising, and when new data came in and the advertisement data needed to be updated, it would:

    1. Stop advertising.
    2. Delete the existing advertising set.
    3. Create a new advertising set with the new data and parameters.
    4. Start advertising again.

    Despite being clunky and overly-complicated, it did work most of the time, but when given enough time, and constant start and stop of advertising from Bluetooth connections, etc, eventually I guess the timing would align and wires would get crossed, two things trying to restart advertising at once, we end up trying to create an advertising set before the old one has been fully deleted, or something.

    What fixed the problem was to simplify the process of updating advertising data:

    1. Stop advertising.
    2. Update the advertising data and/or parameters.
    3. Start advertising again.

    So, it was not necessary or helpful to be deleting the advertising set each time. Instead, we create an advertising set during initialization and just keep using that same one. With this approach, the problem I was seeing is gone.

    Thanks very much to Edvin, and also to Reuven, for your help in working on this problem.

    Scott

Related