7
32
Fork
You've already forked blackmagic
23

Program crashes with SIGSEGV when connecting to BLE while monitor rtt is enabled #2089

Open
opened 2025年03月05日 13:33:20 +01:00 by kat-brickxter · 8 comments
kat-brickxter commented 2025年03月05日 13:33:20 +01:00 (Migrated from github.com)
Copy link

The program crashes on my nrf52840 when I connect to Bluetooth LE with "Program received signal SIGSEGV, Segmentation fault." It only crashes when I start the program from the blackmagic probe and when monitor rtt is enabled. When monitor rtt is disabled or I read the RTT messages with a JLink device, the program works without problems.

Image
Image

The program crashes on my nrf52840 when I connect to Bluetooth LE with "Program received signal SIGSEGV, Segmentation fault." It only crashes when I start the program from the blackmagic probe and when monitor rtt is enabled. When monitor rtt is disabled or I read the RTT messages with a JLink device, the program works without problems. ![Image](https://github.com/user-attachments/assets/4d79e70a-9696-4e15-af1b-8cb2e4f24f27) ![Image](https://github.com/user-attachments/assets/746e5686-4b32-4dbd-ae4c-66bee2c62221)

What version of BMD are you running (mon ver to check), and what are the steps to reproduce? If you're using the "SoftDevice" block from Nordic then this is known to have problems running under debug, especially if halting is involved in any way.

BMD v2.0, for now, has to halt the target to do RTT things as we don't know for certain if there aren't side-effects to accessing memory without halting (nobody has yet documented if it causes cycle stealing either from the core or from the bus matrix so we can lay out the limitations of doing this) and before blanket enabling this for this target (note: it cannot be done for all Cortex-M targets, not all support reading without halting! Eg, TM4C123 parts give garbage back if you don't halt first) we want to get these limitations documented so we can have some place to point to when people find it doesn't work quite how they thought it would (if it turns out there is cycle stealing going on).

What version of BMD are you running (`mon ver` to check), and what are the steps to reproduce? If you're using the "SoftDevice" block from Nordic then this is known to have problems running under debug, especially if halting is involved in any way. BMD v2.0, for now, has to halt the target to do RTT things as we don't know for certain if there aren't side-effects to accessing memory without halting (nobody has yet documented if it causes cycle stealing either from the core or from the bus matrix so we can lay out the limitations of doing this) and before blanket enabling this for this target (note: it cannot be done for all Cortex-M targets, not all support reading without halting! Eg, TM4C123 parts give garbage back if you don't halt first) we want to get these limitations documented so we can have some place to point to when people find it doesn't work quite how they thought it would (if it turns out there is cycle stealing going on).
kat-brickxter commented 2025年03月05日 13:53:44 +01:00 (Migrated from github.com)
Copy link

I used 1.10.2, however I just updated to 2.0.0-rc2 and found the same behavior.
I use the nRF Connect SDK with the SoftDevice controller.

Steps:

  1. I open gdb with arm-none-eabi-gdb -ex "target extended-remote /dev/ttyACM0" -ex "monitor swd_scan" -ex "attach 1"
    GNU gdb (GDB) 15.2
  2. monitor rtt
  3. r
  4. program runs and RTT messages are shown in the minicom
  5. I try to connect to the μC with my phone via BLE
  6. The program crashes with SIGSEGV as shown above

Second scenario:

  1. I open gdb with arm-none-eabi-gdb -ex "target extended-remote /dev/ttyACM0" -ex "monitor swd_scan" -ex "attach 1" GNU gdb (GDB) 15.2
  2. monitor rtt disable
  3. r
  4. program runs
  5. I connect to the μC with my phone and start receiving data without a crash

JLink:

  1. The programm is already running on its own on the μC
  2. I connect and open the RTT terminal in VSCode via the Nordic VS Code Plugin
  3. I can read the RTT messages
  4. I can connect with my phone via BLE and the program doesn't crash

It seems like the halting really is the issue as you describe it. It sounds like the JLink is able to access the data without halting as I can just connect it and open the RTT terminal without going into a debug mode or restarting the firmware.

I used 1.10.2, however I just updated to 2.0.0-rc2 and found the same behavior. I use the nRF Connect SDK with the SoftDevice controller. Steps: 1. I open gdb with arm-none-eabi-gdb -ex "target extended-remote /dev/ttyACM0" -ex "monitor swd_scan" -ex "attach 1" GNU gdb (GDB) 15.2 2. monitor rtt 3. r 4. program runs and RTT messages are shown in the minicom 5. I try to connect to the μC with my phone via BLE 6. The program crashes with SIGSEGV as shown above Second scenario: 1. I open gdb with arm-none-eabi-gdb -ex "target extended-remote /dev/ttyACM0" -ex "monitor swd_scan" -ex "attach 1" GNU gdb (GDB) 15.2 2. monitor rtt disable 3. r 4. program runs 5. I connect to the μC with my phone and start receiving data without a crash JLink: 1. The programm is already running on its own on the μC 2. I connect and open the RTT terminal in VSCode via the Nordic VS Code Plugin 3. I can read the RTT messages 4. I can connect with my phone via BLE and the program doesn't crash It seems like the halting really is the issue as you describe it. It sounds like the JLink is able to access the data without halting as I can just connect it and open the RTT terminal without going into a debug mode or restarting the firmware.
sidprice commented 2025年03月05日 16:27:26 +01:00 (Migrated from github.com)
Copy link

@dragonmux @kat-brickxter I have seen a very similar behavior when debugging a Bluetooth application on nRF5340 using a JLink when a breakpoint is hit, i.e. the DUT is halted. In my opinion, the BT stack and/or the Soft Device just falls apart when the MCU is halted. To date I have not found any work-around for this.

I have seen it using CortexDebug in VSCode and also with Ozone, the Segger debugger.

@dragonmux @kat-brickxter I have seen a very similar behavior when debugging a Bluetooth application on nRF5340 using a JLink when a breakpoint is hit, i.e. the DUT is halted. In my opinion, the BT stack and/or the Soft Device just falls apart when the MCU is halted. To date I have not found any work-around for this. I have seen it using CortexDebug in VSCode and also with Ozone, the Segger debugger.
ALTracer commented 2025年03月05日 16:46:17 +01:00 (Migrated from github.com)
Copy link

There is PR2037 from 2 months ago which closes this issue if you just need to continue working/debugging with BMP, please give that unmerged branch a try. Ping me if I should rebase it into recently tagged v2.0.0-rc2. However, I did not dedicate any time to documenting the amount of bus cycle stealing.

There is PR2037 from 2 months ago which closes this issue if you just need to continue working/debugging with BMP, please give that unmerged branch a try. Ping me if I should rebase it into recently tagged v2.0.0-rc2. However, I did not dedicate any time to documenting the amount of bus cycle stealing.
sidprice commented 2025年03月05日 17:33:38 +01:00 (Migrated from github.com)
Copy link

@ALTracer Thanks, that may help the OP's issue.

@ALTracer Thanks, that may help the OP's issue.
kat-brickxter commented 2025年03月06日 10:04:49 +01:00 (Migrated from github.com)
Copy link

@ALTracer Thank you! PR2037 fixed the issue for me. RTT and BLE now work at the same time. Merging the branch would be greatly appreciated.

@ALTracer Thank you! PR2037 fixed the issue for me. RTT and BLE now work at the same time. Merging the branch would be greatly appreciated.

As mentioned on that PR too.. until we can document what the drawbacks are for hard real-time operations by having someone with one of the parts check for CPU freezes (detectable from SysTick halts while idle) or bus freezes (DMA halts, or, depending on access priority, CPU to peripheral access stutters) on access by the debugger, there are too many possible side-effects that #1532 made it extremely clear would be unacceptable for hard real-time usage. This is why this must happen first so there are no nasty surprises and we can have a table people can refer to that documents what happens on various parts with the TOPT enabled.

As mentioned on that PR too.. until we can document what the drawbacks are for hard real-time operations by having someone with one of the parts check for CPU freezes (detectable from SysTick halts while idle) or bus freezes (DMA halts, or, depending on access priority, CPU to peripheral access stutters) on access by the debugger, there are too many possible side-effects that #1532 made it extremely clear would be unacceptable for hard real-time usage. This is why this must happen first so there are no nasty surprises and we can have a table people can refer to that documents what happens on various parts with the TOPT enabled.
kat-brickxter commented 2025年03月06日 11:57:43 +01:00 (Migrated from github.com)
Copy link

I understand that there are a lot of potential side-effects. However I think a flag which is clearly labeled as experimental within the configuration of native.ini would be a good solution until the full documentation is completed. I think that using RTT during time critical applications such as BLE isn't a complete edge-case and therefore this could be interesting for a lot of people at their own risk.

I understand that there are a lot of potential side-effects. However I think a flag which is clearly labeled as experimental within the configuration of native.ini would be a good solution until the full documentation is completed. I think that using RTT during time critical applications such as BLE isn't a complete edge-case and therefore this could be interesting for a lot of people at their own risk.
Sign in to join this conversation.
No Branch/Tag specified
main
fix/pre-bmp-v3-cross-file-cleanup
feature/bmda-remote-comms
ALTracer/feature/aarch64-ident
feature/better-meson-optimisation-handling
feature/am335x-support
feature/esp32-c3-support
feature/cortex-ar-software-breakpoints
feature/unit-testing
feature/windows-usb-serial-interface-naming
fix/bmp-external-spi
ALTracer/feature/bluepillplus-platform
ALTracer/feature/at32f43x-unrdp
feature/const-correctness
ALTracer/feature/fault_handlers
ALTracer/feature/hazard3-ice40-support
fix/ci-cleanup
ALTracer/fix/gdb-10-12-thread
ALTracer/feature/blackpill-f4-adc
ALTracer/fix/cortex-desc-allocfail-report
ALTracer/feature/spi-perf
ALTracer/feature/calibrate_swd
ALTracer/feature/blank-check
feature/avr
v2.0
v1.9
v1.10
v1.8
v2.1.0-rc1
v2.0.0
v2.0.0-rc2
v2.0.0-rc1
v1.9.3
v1.10.2
v1.10.1
v1.10.0
v1.10.0-rc1
v1.10.0-rc0
v1.9.2
v1.8.3
v1.9.1
v1.9.0
v1.9.0-rc1
v1.9.0-rc0
v1.8.2
v1.8.1
v1.8.0
v1.7.1
v1.7
v1.6.2-rc1
1.6.2-rc0
v1.6.1
v1.6
v1.6-rc1
v1.6-rc0
production_01
production_00
Labels
Clear labels
BMD App
Black Magic Debug App (aka. PC hosted) (not firmware)
BMP Firmware
Black Magic Probe Firmware (not PC hosted software)
Bug
Confirmed bug
Build system
Build system
Can't reproduce
Maintainers can't reproduce this problem
CI
Continuous Integration System
Contribution wanted
User contributions welcome
Documentation
Project documentation
Draft
Work in progress draft
Duplicate
This issue or pull request already exists
Enhancement
General project improvement
Feedback wanted
Requires additional submitter feedback
Foreign Host Board
Non Native hardware to runing Black Magic firmware on
GDB
Issue/PR related to GDB
Good first issue
Good for newcommers
HwIssue Mitigation
Solving or mitigating a Hardware issue in Software
Information Needed
Maintainers need more information
NativeHardware
Official Black Magic Debug Hardware
New Host Board
New hardware to run Black Magic firmware on
New Target
New debug target
Off Topic
Something that does not involve the project in any way
Potential Bug
A potential, unconfirmed or very special circumstance bug
Regression
Bug caused by a regression
User Interest Needed
More user interest required before consideration
User Testing Needed
Looking for user testing reports
Won't fix
Outside of the project scope or works as intended
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
blackmagic-debug/blackmagic#2089
Reference in a new issue
blackmagic-debug/blackmagic
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?