AN4989 Rev 3
59/118
AN4989
Exception handling
117
In order to trap the exception, a hardware or a software breakpoint can be set in the IDE or
directly programmed in the source code using Arm
®
instruction BKPT.
Caution:
BKPT is not tolerated if no debugger is connected (refer to
microcontroller debugging on page 92
). it is advised to set it under
#ifdef
statement.
In-line insertion of assembly instruction in application C code depends on the IDE.
•
IAR™ EWARM and STM32CubeIDE
void NMI_Handler(void)
{
#ifdef DEBUG
asm ("BKPT 0");
#endif
}
•
Keil
®
void NMI_Handler(void)
{
#ifdef DEBUG
__asm
{
BKPT 0
}
#endif
}
For each IDE, it is also possible to use the abstraction function defined in the CMSIS library
and provided in STM32Cube software pack.
void NMI_Handler(void)
{
#ifdef DEBUG
__BKPT(0);
#endif
}
In all cases, the Halt Debug-Mode is entered; it allows to investigate the issue by inspecting
Call Stack and Registers content.
Tip:
On Keil
®
MDK-Arm µVISION, the caller code is not directly accessible in the Call
Stack Window. Right clicking "Show Caller Code" as in
faulty line.