-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cpu/cortexm: rework bkpt instruction call on panic #20616
cpu/cortexm: rework bkpt instruction call on panic #20616
Conversation
I like this idea! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, thx. Please squash the nitpicks right away.
When you have the file open anyway, care to sneak in a style fix as separate commit in line 30?
- if(ipsr) {
+ if (ipsr) {
Only call this instruction if a debug session is active otherwise it will trigger a hardfault Signed-off-by: Dylan Laduranty <dylan.laduranty@mesotic.com>
Signed-off-by: Dylan Laduranty <dylan.laduranty@mesotic.com>
679536e
to
e784794
Compare
@maribu I've addressed your comments and squashed. |
Thanks! |
Thx for the enhancement :) It will be a real quality of life improvement when the MCU no longer gets locked up :) |
Contribution description
Rework the way
bkpt
instruction is call on panic for Cortex-M MCU.Currently, this instruction is called everytime on panic. However, when a debug session is not active (no GDB running), and if a panic occured, the
bkpt
instruction will either escalate the current fault to hardfault or the CPU will enter LOCKUP state (it may reset automatically depending on how vendors handle this signal internally).To mitigate this issue, one can check the
C_DEBUGEN
inCoreDebug->DHCSR
. If this bit is set, it means a debug session is running, thusbkpt
instruction can be used safely. Otherwise, skip this instruction. The execution will then continue untilpm_off()
orwhile(1) {}
is called.However, this bit is NOT accessible by the CPU on CortexM0+ (Only accessible by GDB). So the
bkpt
instruction is completely skip for this one.Testing procedure
Trigger a fault on any cortexm-based board
for instance
Such code will trigger a hardfault (technically a busfault for ARMv7-M or ARMv8-M Mainline, but it escalates to hardfault as the busfault is currently not enable).
On panic, if GDB is NOT used, the execution will 'stop' on the
bkpt
instruction. On nRF5340DK, a reset is issued (Probably because the processor enters LOCKUP state). Nevertheless, the execution should continue up to here.Issues/PRs references
None.