Bluetooth connection cache processing

I attempted to use nRF52840 for multi-connection data interaction, but whenever I was debugging, I always encountered the problem of being unable to establish a connection. The return value of bt_conn_le_create was -12.

My communication has the following characteristics:
1. There is a high probability of concurrent operations. Since it involves communication among up to 16 peripherals and each communication session lasts for 1 minute, the central often attempts to connect to multiple devices simultaneously.
2. Because the peripherals use 2M PHY and Coded PHY, they switch PHYs at regular intervals.
3. Device communication is prone to termination. Since the peripherals are battery-powered devices, I had to incorporate timeout interrupt communication mechanisms in both the peripherals and the central, which led to abnormal interruptions in the connection sometimes.
The problems I encountered:
1. Sometimes it is impossible to search for any device. This situation usually occurs during the transition from Coded to 2M phy.
2. Due to some communication abnormalities, the device resources were not properly released, resulting in bt_conn_le_create returning -12.
3. If you have any other suggestions for code optimization, I would appreciate it if you could point them out.
My code has been provided, and the main part of the code is ble_server.c.

To facilitate the troubleshooting, I will briefly summarize the code structure:
1. Lines 0-195
Some structure definitions
2. Lines 196-210
The sending and receiving callbacks of nus
3. Lines 232-326
The relevant functions for device processing (I need a necessary data structure to manage my communication), including adding communication devices, etc..
4. Lines 326-546
!! Some callback functions of the Bluetooth API!!
I think the problem lies in these parts. Especially (connected) and (disconnected)
Lines 5.546 - 1186 I used a priority level of 9 (as far as I know, this priority level is lower than that of Bluetooth). A state machine is used to manage the real-time connection or disconnection of device communication.
And the problematic part here is the _SMF_FUNCTION_HEADER_(connecting_entry) function on line 870.
You can see that I explicitly attempted to shut down BLE and restart it, but it had no effect.

Other documents might also have had an impact.
main.c :
Use a state machine with a priority of 10 as the middleware for communication, to manage connection timeouts and release device model resources (note: these are not communication resources; the model resources and communication resources are bound through the device hardware ID).
2. Use a work queue with a priority level of 9 to implement the thread pool technology and simulate one-to-one device communication.
prj.conf:
Related configuration

ble_server.zip

Parents Reply Children
No Data
Related