From 145a6ffb8850ac8d06295b2929fd7708c4f990ef Mon Sep 17 00:00:00 2001 From: Henrik Lander Date: Fri, 17 Jan 2025 14:45:44 +0100 Subject: [PATCH] samples: Bluetooth: update scanning_while_connecting sample Update bluetooth softdevice controller configuration to achieve faster connection establishment. Signed-off-by: Henrik Lander --- .../scanning_while_connecting/README.rst | 6 ++-- .../scanning_while_connecting/src/main.c | 28 +++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/samples/bluetooth/scanning_while_connecting/README.rst b/samples/bluetooth/scanning_while_connecting/README.rst index 41d0c4c66f5b..d7fdc5ccdcf8 100644 --- a/samples/bluetooth/scanning_while_connecting/README.rst +++ b/samples/bluetooth/scanning_while_connecting/README.rst @@ -182,7 +182,7 @@ The result should look similar to the following output:: I: Connected to FB:92:1D:8E:8C:D8 (random), number of connections 14 I: Connected to D9:E5:51:E0:5E:24 (random), number of connections 15 I: Connected to CF:2F:99:89:A3:4D (random), number of connections 16 - I: 12 seconds to create 16 connections + I: 8 seconds to create 16 connections I: Disconnecting connections... I: --------------------------------------------------------------------- I: --------------------------------------------------------------------- @@ -204,7 +204,7 @@ The result should look similar to the following output:: I: Connected to F4:9C:8C:24:F9:44 (random), number of connections 14 I: Connected to EF:92:DC:88:3B:B3 (random), number of connections 15 I: Connected to C8:BA:1D:6F:95:2B (random), number of connections 16 - I: 9 seconds to create 16 connections + I: 7 seconds to create 16 connections I: Disconnecting connections... I: --------------------------------------------------------------------- I: --------------------------------------------------------------------- @@ -226,7 +226,7 @@ The result should look similar to the following output:: I: Connected to CF:2F:99:89:A3:4D (random), number of connections 14 I: Connected to EF:92:DC:88:3B:B3 (random), number of connections 15 I: Connected to D9:E5:51:E0:5E:24 (random), number of connections 16 - I: 4 seconds to create 16 connections + I: 2 seconds to create 16 connections I: Disconnecting connections... I: --------------------------------------------------------------------- I: --------------------------------------------------------------------- diff --git a/samples/bluetooth/scanning_while_connecting/src/main.c b/samples/bluetooth/scanning_while_connecting/src/main.c index 5287370cb113..2784ed7d6bdb 100644 --- a/samples/bluetooth/scanning_while_connecting/src/main.c +++ b/samples/bluetooth/scanning_while_connecting/src/main.c @@ -437,6 +437,34 @@ int main(void) hci_vs_sdc_central_acl_event_spacing_set(&event_spacing_params); + /** Set a small connection event length to leave more time for scanning. + * + * This can also be set at compile time by using the Kconfig option + * CONFIG_BT_CTLR_SDC_MAX_CONN_EVENT_LEN_DEFAULT in the prj.conf file. + */ + sdc_hci_cmd_vs_event_length_set_t event_length_params = { + .event_length_us = 2000, + }; + + hci_vs_sdc_event_length_set(&event_length_params); + + /** Connection event extension is turned on by default. This is turned on by default + * to achieve higher throughput. As a consequence, the scheduler will schedule + * longer connection events at the cost of scanning events. In this sample application, + * we try to achieve faster connection establishment, so we turn connection + * event extension off. Thus, the controller shedules more time for scanning. + * + * This can also be turned off on compile time by setting the Kconfig option + * BT_CTLR_SDC_CONN_EVENT_EXTEND_DEFAULT=n in the prj.conf file. + * + * See our scheduling documentation under nrfxlib/softdevice_controller for more info. + */ + sdc_hci_cmd_vs_conn_event_extend_t conn_event_extend_params = { + .enable = 0, + }; + + hci_vs_sdc_conn_event_extend(&conn_event_extend_params); + for (uint8_t i = 0; i < ARRAY_SIZE(conn_establishment_modes); i++) { active_conn_establishment_mode = conn_establishment_modes[i];