This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

ARM bkpt instruction w/o debugger hard faults on Cortext M0?

I have __asm("BKPT #0\n") in my code. When running without a debugger, it seems to generate a hard fault exception (which I can tell because I have a hard fault handler that writes to a flag in flash.)

At answers.launchpad.net/.../248410 it says: "For a Cortex-M0/M0+ processor when running without debugger control a "BKPT 0" instruction will cause a HardFault exception."

But the ARM docs seem to say that that the processor should enter DEBUG mode and the cpu halt. (Doesn't seem to say a hard fault exception is generated first.)

Can anyone confirm, for the NRF51? And how is the behaviour different on the NRF52?

Its just a curiousity. Once my app reaches a BKPT, all hope is lost so it doesn't really matter what happens. I won't leave a BKPT in the final code.

Parents
  • The bkpt instruction generates what the ARM documentation calls a "debug event". What this does depends on the current configuration that is set in the debug configuration registers. See the following from the ARMv7-M Architecture Reference Manual, section C1.5:

    An event triggered for debug reasons is known as a debug event. A debug event will cause one of the following to occur:

    • Entry to Debug state. If halting debug is enabled (C_DEBUGEN in the DHCSR, Table C1-9 on page C1-20, is set), captured events will halt the processor in Debug state. See Table B1-9 on page B1-40 for a comprehensive application level fault table.
    • A DebugMonitor exception. If halting debug is disabled (C_DEBUGEN is cleared) and the debug monitor is enabled (MON_EN in the DEMCR, Table C1-12 on page C1-24, is set), a debug event will cause a DebugMonitor exception when the group priority of DebugMonitor is higher than the current active group priority. If the DebugMonitor group priority is less than or equal to the current active group priority, a BKPT instruction will escalate to a HardFault and other debug events (watchpoints and external debug requests) are ignored. Note Software can put the DebugMonitor exception into the Pending state under this condition, and when the DebugMonitor exception is disabled.
    • A HardFault exception. If both halting debug and the monitor are disabled, a BKPT instruction will escalate to a HardFault and other debug events (watchpoints and external debug requests) are ignored.

    Basically bkpt will generate a HardFault if debugging is disabled, or if it is configured to generate a DebugMonitor exception but this exception has a lower priority than the currently executing one.

Reply
  • The bkpt instruction generates what the ARM documentation calls a "debug event". What this does depends on the current configuration that is set in the debug configuration registers. See the following from the ARMv7-M Architecture Reference Manual, section C1.5:

    An event triggered for debug reasons is known as a debug event. A debug event will cause one of the following to occur:

    • Entry to Debug state. If halting debug is enabled (C_DEBUGEN in the DHCSR, Table C1-9 on page C1-20, is set), captured events will halt the processor in Debug state. See Table B1-9 on page B1-40 for a comprehensive application level fault table.
    • A DebugMonitor exception. If halting debug is disabled (C_DEBUGEN is cleared) and the debug monitor is enabled (MON_EN in the DEMCR, Table C1-12 on page C1-24, is set), a debug event will cause a DebugMonitor exception when the group priority of DebugMonitor is higher than the current active group priority. If the DebugMonitor group priority is less than or equal to the current active group priority, a BKPT instruction will escalate to a HardFault and other debug events (watchpoints and external debug requests) are ignored. Note Software can put the DebugMonitor exception into the Pending state under this condition, and when the DebugMonitor exception is disabled.
    • A HardFault exception. If both halting debug and the monitor are disabled, a BKPT instruction will escalate to a HardFault and other debug events (watchpoints and external debug requests) are ignored.

    Basically bkpt will generate a HardFault if debugging is disabled, or if it is configured to generate a DebugMonitor exception but this exception has a lower priority than the currently executing one.

Children
No Data
Related