BKPT is an Arm breakpoint instruction. With a debugger connected, it can halt a Cortex-M core at a precise point so you can inspect registers, memory, and peripheral state. This is useful when a source-level breakpoint does not map to the instruction boundary you need. section 5.5.2
Pause from Rust
Use the cortex-m intrinsic instead of writing inline assembly: `unsafe { cortex_m::asm::bkpt(); }`. Place the call where you want to inspect the machine state under a connected debugger. section 5.5.2 section 5.6
Semihosting uses `BKPT 0xAB` to trap execution and ask the attached debugger to service a request. For example, `cortex_m_semihosting::hprintln!` lets no_std firmware ask the host to print formatted text. The target pauses during the exchange and resumes after the debugger handles it. section 6.2.1
#![no_std]
#![no_main]
use cortex_m_rt::entry;
use cortex_m_semihosting::hprintln;
use panic_halt as _;
#[entry]
fn main() -> ! {
hprintln!("Hello from semihosting");
loop {}
}
This no_std example uses hprintln! to send a message through semihosting. section 6.2.1
OpenOCD must have semihosting enabled to intercept these traps. From GDB, run `monitor arm semihosting enable`; the `monitor` prefix passes the command to OpenOCD. Alternatively, enable it when starting OpenOCD. section 6.2.1
Do not leave semihosting calls enabled blindly in standalone firmware. On Cortex-M0, M0+, and M23, a BKPT executed without a debugger escalates directly to HardFault. On v7-M cores, firmware can install a DebugMonitor handler to absorb stray semihosting calls. For release builds, the cortex-m-semihosting `no-semihosting` feature compiles the macros out. section 6.2.1
