From afa751caecdf8238b62efd192f4be8d5e00e6520 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Fri, 29 Aug 2025 22:45:34 +0200 Subject: [PATCH 1/3] Bluetooth: Controller: Relax radio packet pointer assignment deadline Relax the radio packet pointer assignment deadline assertion until access address being transmitted. The PDU buffer is probably only needed just after access address is being transmitted or received by the radio. This will give some more breathing room for slow CPUs like in nRF51x SoCs. Signed-off-by: Vinayak Kariappa Chettimada --- .../controller/ll_sw/nordic/lll/lll_scan.c | 21 ++++++++++++++++--- .../ll_sw/nordic/lll/lll_scan_aux.c | 3 ++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_scan.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_scan.c index 4f2d6607fbf56..79f60677be7c5 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_scan.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_scan.c @@ -791,7 +791,12 @@ static void isr_tx(void *param) radio_pkt_rx_set(node_rx->pdu); /* assert if radio packet ptr is not set and radio started rx */ - LL_ASSERT(!radio_is_ready()); + if (IS_ENABLED(CONFIG_BT_CTLR_PROFILE_ISR)) { + LL_ASSERT_MSG(!radio_is_address(), "%s: Radio ISR latency: %u", __func__, + lll_prof_latency_get()); + } else { + LL_ASSERT(!radio_is_address()); + } #if defined(CONFIG_BT_CTLR_PRIVACY) if (ull_filter_lll_rl_enabled()) { @@ -1211,7 +1216,12 @@ static inline int isr_rx_pdu(struct lll_scan *lll, struct pdu_adv *pdu_adv_rx, radio_pkt_tx_set(pdu_tx); /* assert if radio packet ptr is not set and radio started tx */ - LL_ASSERT(!radio_is_ready()); + if (IS_ENABLED(CONFIG_BT_CTLR_PROFILE_ISR)) { + LL_ASSERT_MSG(!radio_is_address(), "%s: Radio ISR latency: %u", __func__, + lll_prof_latency_get()); + } else { + LL_ASSERT(!radio_is_address()); + } if (IS_ENABLED(CONFIG_BT_CTLR_PROFILE_ISR)) { lll_prof_cputime_capture(); @@ -1343,7 +1353,12 @@ static inline int isr_rx_pdu(struct lll_scan *lll, struct pdu_adv *pdu_adv_rx, radio_pkt_tx_set(pdu_tx); /* assert if radio packet ptr is not set and radio started tx */ - LL_ASSERT(!radio_is_ready()); + if (IS_ENABLED(CONFIG_BT_CTLR_PROFILE_ISR)) { + LL_ASSERT_MSG(!radio_is_address(), "%s: Radio ISR latency: %u", __func__, + lll_prof_latency_get()); + } else { + LL_ASSERT(!radio_is_address()); + } if (IS_ENABLED(CONFIG_BT_CTLR_PROFILE_ISR)) { lll_prof_cputime_capture(); diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_scan_aux.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_scan_aux.c index 248f609c6943d..1a8aeb536f0cf 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_scan_aux.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_scan_aux.c @@ -356,7 +356,8 @@ void lll_scan_aux_isr_aux_setup(void *param) aux_start_us -= EVENT_JITTER_US; start_us = radio_tmr_start_us(0, aux_start_us); - LL_ASSERT(start_us == (aux_start_us + 1U)); + LL_ASSERT_MSG(start_us == (aux_start_us + 1U), "aux_offset %u us, start_us %u != %u", + aux_offset_us, start_us, (aux_start_us + 1U)); /* Setup header complete timeout */ hcto = start_us; From 4a024d87e073f08c2f248910e8c3ba52a15cb222 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Sat, 30 Aug 2025 07:17:04 +0200 Subject: [PATCH 2/3] samples: Bluetooth: observer with 10 ms continuous scanning Updated observer sample to use 10 ms continuous scanning parameters. Signed-off-by: Vinayak Kariappa Chettimada --- samples/bluetooth/observer/src/observer.c | 5 +++-- .../bsim/bluetooth/host/adv/chain/tests_scripts/adv_chain.sh | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/samples/bluetooth/observer/src/observer.c b/samples/bluetooth/observer/src/observer.c index 12a6c5781b320..ac9a857e1ef7a 100644 --- a/samples/bluetooth/observer/src/observer.c +++ b/samples/bluetooth/observer/src/observer.c @@ -88,10 +88,11 @@ static struct bt_le_scan_cb scan_callbacks = { int observer_start(void) { + /* 30 ms continuous active scanning with duplicate filtering. */ struct bt_le_scan_param scan_param = { - .type = BT_LE_SCAN_TYPE_PASSIVE, + .type = BT_LE_SCAN_TYPE_ACTIVE, .options = BT_LE_SCAN_OPT_FILTER_DUPLICATE, - .interval = BT_GAP_SCAN_FAST_INTERVAL, + .interval = BT_GAP_SCAN_FAST_INTERVAL_MIN, .window = BT_GAP_SCAN_FAST_WINDOW, }; int err; diff --git a/tests/bsim/bluetooth/host/adv/chain/tests_scripts/adv_chain.sh b/tests/bsim/bluetooth/host/adv/chain/tests_scripts/adv_chain.sh index 045b1eba64903..3f1d5c20fb87e 100755 --- a/tests/bsim/bluetooth/host/adv/chain/tests_scripts/adv_chain.sh +++ b/tests/bsim/bluetooth/host/adv/chain/tests_scripts/adv_chain.sh @@ -18,6 +18,6 @@ Execute ./bs_${BOARD_TS}_tests_bsim_bluetooth_host_adv_chain_prj_conf\ -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=scan Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ - -D=2 -sim_length=10e6 $@ + -D=2 -sim_length=11e6 $@ wait_for_background_jobs From 20354b2fb720538ba8fa20cdfd8bdf49f2a9ead6 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Fri, 29 Aug 2025 22:56:27 +0200 Subject: [PATCH 3/3] samples: Bluetooth: observer: Extended Scanning on BBC Micro Bit board Add configuration overlay file to support observer sample with Extended Scanning on BBC Micro Bit board. Due to slow CPU, there will be assertions, and this commit (for now) validates build-only. And the sample may run for a duration until it asserts. Asserts: - ASSERTION FAIL [start_us == (aux_start_us + 1U)] @ WEST_TOPDIR/zephyr/subsys/bluetooth/controller/ll_sw/ nordic/lll/lll_scan_aux.c:359 This will happen for small aux offset value, definitely for the 300 us because CPU usage latency to setup such auxiliary PDU reception on nRF51 is high due to slow CPU. - ASSERTION FAIL [0] @ WEST_TOPDIR/zephyr/subsys/bluetooth/controller/ll_sw/ nordic/lll/lll_scan_aux.c:592 prepare_cb: Actual EVENT_OVERHEAD_START_US = 579 This will happen due to CPU usage latencies scheduling the radio events, due to slow CPU. Signed-off-by: Vinayak Kariappa Chettimada --- samples/bluetooth/observer/README.rst | 17 ++++++ samples/bluetooth/observer/debug.conf | 5 ++ .../observer/dts/arm/nordic/override.dtsi | 7 +++ .../overlay_bbc_microbit-bt_ll_sw_split.conf | 53 +++++++++++++++++++ samples/bluetooth/observer/sample.yaml | 19 +++++-- 5 files changed, 98 insertions(+), 3 deletions(-) create mode 100644 samples/bluetooth/observer/debug.conf create mode 100644 samples/bluetooth/observer/dts/arm/nordic/override.dtsi create mode 100644 samples/bluetooth/observer/overlay_bbc_microbit-bt_ll_sw_split.conf diff --git a/samples/bluetooth/observer/README.rst b/samples/bluetooth/observer/README.rst index 6ef62f3870eb5..32b4a0d9eac45 100644 --- a/samples/bluetooth/observer/README.rst +++ b/samples/bluetooth/observer/README.rst @@ -16,6 +16,23 @@ If the used Bluetooth Low Energy Controller supports Extended Scanning, you may enable :kconfig:option:`CONFIG_BT_EXT_ADV` in the project configuration file. Refer to the project configuration file for further details. +Building Extended Scanning support for BBC Micro Bit board +********************************************************** + +.. code-block:: console + + west build -b bbc_microbit . -- -DCONF_FILE='prj_extended.conf' -DEXTRA_CONF_FILE='overlay_bbc_microbit-bt_ll_sw_split.conf' + +Thread Analysis for BBC Micro Bit board +*************************************** + +Due to resource constraints on the BBC Micro Bit board, thread analysis can be enabled to profile +the RAM usage and thread stack sizes be updated to successfully build and run the sample. + +.. code-block:: console + + west build -b bbc_microbit . -- -DCONF_FILE='prj_extended.conf' -DEXTRA_CONF_FILE='debug.conf;overlay_bbc_microbit-bt_ll_sw_split.conf' + Requirements ************ diff --git a/samples/bluetooth/observer/debug.conf b/samples/bluetooth/observer/debug.conf new file mode 100644 index 0000000000000..11690a66f19bf --- /dev/null +++ b/samples/bluetooth/observer/debug.conf @@ -0,0 +1,5 @@ +# Enable thread analysis +CONFIG_THREAD_ANALYZER=y +CONFIG_THREAD_ANALYZER_AUTO=y +CONFIG_THREAD_ANALYZER_AUTO_INTERVAL=5 +CONFIG_THREAD_NAME=y diff --git a/samples/bluetooth/observer/dts/arm/nordic/override.dtsi b/samples/bluetooth/observer/dts/arm/nordic/override.dtsi new file mode 100644 index 0000000000000..882f70755d59d --- /dev/null +++ b/samples/bluetooth/observer/dts/arm/nordic/override.dtsi @@ -0,0 +1,7 @@ +/* Keep default IRQ priority low for peripherals to reduce Radio ISR latency. + * ARM Cortex-M4 lowest priority value of 5, i.e. considering Zephyr reserved 2 + * levels for Exceptions and ZLI (if enabled). + * ARM Cortex-M0 lowest priority value of 3, i.e. we use it as Zephyr has no + * support for ZLI on Cortex-M0. + */ +#define NRF_DEFAULT_IRQ_PRIORITY 3 diff --git a/samples/bluetooth/observer/overlay_bbc_microbit-bt_ll_sw_split.conf b/samples/bluetooth/observer/overlay_bbc_microbit-bt_ll_sw_split.conf new file mode 100644 index 0000000000000..1df1d076ef5fb --- /dev/null +++ b/samples/bluetooth/observer/overlay_bbc_microbit-bt_ll_sw_split.conf @@ -0,0 +1,53 @@ +# Adjust Stack Sizes for reduce RAM usage +CONFIG_MAIN_STACK_SIZE=1024 +CONFIG_IDLE_STACK_SIZE=128 +CONFIG_ISR_STACK_SIZE=1024 +CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=1024 + +# Enable Extended Scanning +# CONFIG_BT_EXT_ADV=y + +# Set maximum scan data length for Extended Scanning +CONFIG_BT_EXT_SCAN_BUF_SIZE=192 + +# Zephyr Bluetooth LE Controller needs 16 event buffers to generate Extended +# Advertising Report for receiving the complete 1650 bytes of data. +# Use 4 to be able to receive a minimal extended advertising with chains. +CONFIG_BT_BUF_EVT_RX_COUNT=4 + +# Use Zephyr Bluetooth Low Energy Controller implementation +CONFIG_BT_LL_SW_SPLIT=y + +# Set maximum scan data length for Extended Scanning in Bluetooth LE Controller. +CONFIG_BT_CTLR_SCAN_DATA_LEN_MAX=192 + +# Increase Zephyr Bluetooth LE Controller Rx buffer to receive complete chain +# of PDUs. Need 9 for maximum of 1650 bytes, but we use 3 as minimum to receive +# at least a primary PDU, an auxiliary PDU and a chain PDU. +CONFIG_BT_CTLR_RX_BUFFERS=3 + +# Enable advanced features +CONFIG_BT_CTLR_ADVANCED_FEATURES=y + +# Adjust execution context priorities to achieve lower Radio ISR latencies +CONFIG_BT_CTLR_LLL_PRIO=0 +CONFIG_BT_CTLR_ULL_HIGH_PRIO=1 +CONFIG_BT_CTLR_ULL_LOW_PRIO=1 + +# Use just-in-time collision resolution in ticker and LLL pipeline +CONFIG_BT_CTLR_LOW_LAT=n +CONFIG_BT_CTLR_LOW_LAT_ULL_DONE=n +CONFIG_BT_TICKER_LOW_LAT=n + +# Increase the below to receive interleaved advertising chains +CONFIG_BT_CTLR_SCAN_AUX_SET=3 +CONFIG_BT_CTLR_LOW_LAT_ULL=y +# CONFIG_BT_CTLR_SCAN_AUX_USE_CHAINS=y +# CONFIG_BT_CTLR_SCAN_AUX_CHAIN_COUNT=3 + +# Use unreserved timespace scanning +CONFIG_BT_CTLR_SCAN_UNRESERVED=y + +# Code size reduction +CONFIG_ISR_TABLES_LOCAL_DECLARATION=y +CONFIG_LTO=y diff --git a/samples/bluetooth/observer/sample.yaml b/samples/bluetooth/observer/sample.yaml index b60ccc9fe8ed3..c568dc74e7f8c 100644 --- a/samples/bluetooth/observer/sample.yaml +++ b/samples/bluetooth/observer/sample.yaml @@ -3,20 +3,33 @@ sample: tests: sample.bluetooth.observer: harness: bluetooth + tags: bluetooth platform_allow: - qemu_cortex_m3 - qemu_x86 - nrf52840dk/nrf52840 integration_platforms: - qemu_cortex_m3 - tags: bluetooth + - nrf52840dk/nrf52840 sample.bluetooth.observer.extended: harness: bluetooth - extra_args: CONF_FILE="prj_extended.conf" + tags: bluetooth + extra_args: + - CONF_FILE="prj_extended.conf" platform_allow: - qemu_cortex_m3 - qemu_x86 - nrf52840dk/nrf52840 - tags: bluetooth integration_platforms: - qemu_cortex_m3 + - nrf52840dk/nrf52840 + sample.bluetooth.observer.extended.bbc_microbit.bt_ll_sw_split: + harness: bluetooth + tags: bluetooth + extra_args: + - CONF_FILE="prj_extended.conf" + - EXTRA_CONF_FILE="debug.conf;overlay_bbc_microbit-bt_ll_sw_split.conf" + platform_allow: + - bbc_microbit + integration_platforms: + - bbc_microbit