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