Skip to content

Conversation

cvinayak
Copy link
Contributor

@cvinayak cvinayak commented May 26, 2025

Introduce development and fatal assertion classification in the Controller implementation.

Reduce Controller assertion check code size for ARM Cortex-M CPUs by raising undefined instruction exception or use faulting instruction address in the HCI vendor-specific h/w error event.

hci_ipc for nRF5340 Audio DK with nRF21540 FEM:

cmake -GNinja -DBOARD=nrf5340_audio_dk/nrf5340/cpunet -DCONF_FILE="nrf5340_cpunet_iso-bt_ll_sw_split.conf" -DEXTRA_CONF_FILE="overlay-nrf5340_cpunet_iso_nrf21540_ek-bt_ll_sw_split.conf" -DDTC_OVERLAY_FILE="boards/nrf5340_audio_dk_nrf5340_cpunet_nrf21540_ek.overlay" -DSNIPPET="bt-ll-sw-split" ../../samples/bluetooth/hci_ipc

Upstream memory use:

Memory region         Used Size  Region Size  %age Used
           FLASH:      248176 B       256 KB     94.67%
             RAM:       64016 B        64 KB     97.68%
           SRAM1:          0 GB        64 KB      0.00%
        IDT_LIST:          0 GB        32 KB      0.00%

PR memory use when Controller assertion check use ARM Cortex-M faulting instruction address (and weirdly enabling HCI vendor-specific error event reduces ~8KB):

Memory region         Used Size  Region Size  %age Used
           FLASH:      213980 B       256 KB     81.63%
             RAM:       64340 B        64 KB     98.18%
           SRAM1:          0 GB        64 KB      0.00%
        IDT_LIST:          0 GB        32 KB      0.00%

33.39 KB or ~ 13.78% reduction in code size.

Test/example Controller assertion:

> HCI Event: Vendor (0xff) plen 38
        01 24 00 00 00 01 1e 00 00 00 01 00 00 00 00 00  .$..............
        00 00 0c bc 0a 00 14 37 00 00 a1 8b 01 00 ae 8b  .......7........
        01 00 9a 00 00 81                                ......          

where ae 8b 01 00 is the program counter register value in little-endian octets.
or

***** USAGE FAULT *****
  Attempt to execute undefined instruction
r0/a1:  0x00000029  r1/a2:  0x00000001  r2/a3:  0x00000000
r3/a4:  0x00000745 r12/ip:  0x00000003 r14/lr:  0x00008b71
 xpsr:  0x8100009a
Faulting instruction address (r15/pc): 0x00008b80

Commandline to use to get details:

arm-none-eabi-addr2line -e <elf file path> <faulting instruction address>

Example:

$ arm-none-eabi-addr2line -e zephyr/zephyr.elf 0x00008b80
/home/jack/workspace/zephyrproject/zephyr/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_scan_aux.c:233 (discriminator 1)

When using LTO, arm-none-eabi-addr2line is not able to fetch the source file and line number. With LTO, .lst file has to be used to look up the faulting instruction address. Hence, enable CONFIG_OUTPUT_DISASSEMBLY=y to get the .lst generated for the sample.

Minimal peripheral_hr:

cmake -GNinja -DBOARD=nrf54l15dk/nrf54l15/cpuapp -DCONF_FILE=prj_minimal.conf -DEXTRA_CONF_FILE=overlay-bt_ll_sw_split-minimal.conf ../../samples/bluetooth/peripheral_hr
Memory region         Used Size  Region Size  %age Used
           FLASH:       96860 B      1428 KB      6.62%
             RAM:       17744 B       188 KB      9.22%
        IDT_LIST:          0 GB        32 KB      0.00%

This is an increase for the minimal, with this PR assertion checks are not removed in the minimal sample where as before it was removed when logging/console/serial was not included.

@cvinayak cvinayak force-pushed the github_ll_assert_dbg branch 4 times, most recently from d9e0e27 to 4ff5213 Compare May 26, 2025 18:57
@cvinayak cvinayak changed the title Bluetooth: Controller: Introduce LL_ASSERT_DBG/ERR RFC: Bluetooth: Controller: Introduce LL_ASSERT_DBG/ERR Jun 5, 2025
@cvinayak cvinayak marked this pull request as ready for review June 5, 2025 13:17
@cvinayak cvinayak force-pushed the github_ll_assert_dbg branch from 4ff5213 to 61f7bbb Compare June 5, 2025 13:21
Copy link

sonarqubecloud bot commented Jun 5, 2025

@github-actions github-actions bot added the Stale label Aug 5, 2025
@github-actions github-actions bot closed this Aug 20, 2025
@cvinayak cvinayak reopened this Sep 6, 2025
@zephyrbot zephyrbot requested a review from ppryga September 6, 2025 04:29
@cvinayak cvinayak force-pushed the github_ll_assert_dbg branch 2 times, most recently from a11a45e to 1c6db0b Compare September 6, 2025 05:26
@cvinayak cvinayak changed the title RFC: Bluetooth: Controller: Introduce LL_ASSERT_DBG/ERR Bluetooth: Controller: Introduce LL_ASSERT_DBG/ERR Sep 6, 2025
@zephyrproject-rtos zephyrproject-rtos deleted a comment from github-actions bot Sep 6, 2025
@cvinayak cvinayak changed the title Bluetooth: Controller: Introduce LL_ASSERT_DBG/ERR Bluetooth: Controller: Reduce assertion check code size Sep 6, 2025
@cvinayak cvinayak requested a review from Copilot September 6, 2025 05:50
Copilot

This comment was marked as outdated.

@github-actions github-actions bot removed the Stale label Sep 7, 2025
@cvinayak cvinayak requested a review from Thalley September 7, 2025 08:46
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 78 out of 78 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (14)

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@zephyrbot zephyrbot added the area: Tests Issues related to a particular existing or missing test label Oct 8, 2025
@cvinayak cvinayak force-pushed the github_ll_assert_dbg branch 3 times, most recently from 5f4ddf4 to 6fc003d Compare October 9, 2025 08:28
@zephyrbot zephyrbot added the Release Notes To be mentioned in the release notes label Oct 9, 2025
@cvinayak cvinayak requested a review from Thalley October 9, 2025 09:06
Comment on lines +146 to +148
* :c:struct:`bt_hci_vs_fata_error_cpu_data_cortex_m` to
:c:struct:`bt_hci_vs_fatal_error_cpu_data_cortex_m` and now contains the program counter
value.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "title" for this "section" is

* The following Kconfig option have been renamed:

Suggest to either start a new list, or modify the "title"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch... I only read renamed and appended the new entry!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is it with the bt_hci_vs - Are they considered stable APIs and must go through the deprecation process? Or is this good enough?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The whole Zephyr Vendor-Specific is so just between Zephyr Host and Zephyr Controller :-) .... not sure if this ever considered stable/unstable! Atleast, definitely the error event if generated makes the device/application unstable ;-)

I will not go with deprecation process for literal renames, these changes are caught straight at compile time, mandating a immediate migration task.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably consider documenting how the hci headers should in general be considered in terms of public/internal APIs :D

@cvinayak cvinayak force-pushed the github_ll_assert_dbg branch from 6fc003d to 89f2101 Compare October 9, 2025 13:00
Thalley
Thalley previously approved these changes Oct 9, 2025
Introduce development and fatal assertion classification
in the Controller implementation.

Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 78 out of 78 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (4)

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Reduce Controller assertion check code size for ARM Cortex-M
CPUs by using the undefined instruction exception.

`arm-none-eabi-addr2line` commandline can be used to get the
source file and line number.

Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
Make overlay-all-bt_ll_sw_split configs consistent with the
one used in hci_ipc for nRF5340 SoC.

Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
Reuse hci_vs_err_assert implementation to generate the HCI
vendor-specific hardware error event.

Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
Enable HCI vendor-specific h/w error event generation in
samples and tests.

Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
Enable OUTPUT_DISASSEMBLY_WITH_SOURCE when using LTO to help
find the assertion check in the source code corresponding to
the faulting instruction address.

arm-none-eabi-addr2line tool is not able to resolve the
source file and line number when using LTO.

Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
@cvinayak cvinayak force-pushed the github_ll_assert_dbg branch from 67896b4 to bc187a3 Compare October 10, 2025 06:32
@cvinayak cvinayak requested a review from Copilot October 10, 2025 06:32
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 79 out of 79 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (4)

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Bluetooth Controller area: Bluetooth HCI Bluetooth HCI Driver area: Bluetooth Host Bluetooth Host (excluding BR/EDR) area: Bluetooth area: Samples Samples area: Tests Issues related to a particular existing or missing test Enhancement Changes/Updates/Additions to existing features Release Notes To be mentioned in the release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants