Debugging nRF52840 DK in VS Code

I am trying to debug an application in VS Code for the nRF52840 DK in the nRF Connect SDK. 

After starting debugging, I immediately get this error: "Exception has occurred. Debugger was unable to continue the process".

This occurs at line 951 of cmsis_gcc.h:

Fullscreen
1
2
3
4
__STATIC_FORCEINLINE void __enable_irq(void)
{
__ASM volatile ("cpsie i" : : : "memory");
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

When a breakpoint is placed before __enable_irq(void) is called, the above error occurs at line 73 in reset.S instead:

Fullscreen
1
2
3
#if defined(CONFIG_DEBUG_THREAD_INFO)
/* Clear z_sys_post_kernel flag for RTOS aware debuggers */
movs.n r0, #0
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

This is the prj.conf for the non-debug build.

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
CONFIG_LOG=y
CONFIG_ADC=y
# Bluetooth LE
CONFIG_BT=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_DEVICE_NAME="ABC"
CONFIG_BT_SMP=y
CONFIG_BT_GATT_CLIENT=y
CONFIG_BT_GATT_DM=y
CONFIG_BT_DIS=n
CONFIG_BT_DIS_PNP=n
CONFIG_BT_GATT_DM_LOG_LEVEL_DBG=y
# CTS
CONFIG_BT_CTS_CLIENT=y
# config_bt_settings dependencies
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

The .conf file for the debug build is the same as above, but with the following additions:

Fullscreen
1
2
3
4
5
#debugging options
CONFIG_DEBUG_OPTIMIZATIONS=y
CONFIG_DEBUG_THREAD_INFO=y
CONFIG_CORTEX_M_DEBUG_MONITOR_HOOK=y
CONFIG_SEGGER_DEBUGMON=y
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

When the application is compiled without the debug options enabled, the build is flashed successfully and behaves as expected. 

The Blinky and Central-and-Peripheral-HRS samples can be debugged as normal, so I think there's an issue with my application.

I have tried reinstalling the JLink driver, switching cables, switching ports and switching DK boards but none of these have resolved the issue.

SDK Version: v2.8.0

JLink Version: v7.94i

Parents Reply Children
  • Hi Sigurd, here is the call stack when the exception happens:

  • Do you get anything printed in the log (either UART or RTT) about this exception ?

  • The debug console says:

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    JLinkGDBServerCLexe: SEGGER J-Link GDB Server V7.94i Command Line Version
    JLinkGDBServerCLexe:
    JLinkGDBServerCLexe: JLinkARM.dll V7.94i (DLL compiled Feb 7 2024 17:05:53)
    JLinkGDBServerCLexe:
    JLinkGDBServerCLexe: -----GDB Server start settings-----
    JLinkGDBServerCLexe: GDBInit file: none
    JLinkGDBServerCLexe: GDB Server Listening port: 57549
    JLinkGDBServerCLexe: SWO raw output listening port: 2332
    JLinkGDBServerCLexe: Terminal I/O port: 2333
    JLinkGDBServerCLexe: Accept remote connection: yes
    JLinkGDBServerCLexe: Generate logfile: off
    JLinkGDBServerCLexe: Verify download: off
    JLinkGDBServerCLexe: Init regs on start: off
    JLinkGDBServerCLexe: Silent mode: on
    JLinkGDBServerCLexe: Single run mode: on
    JLinkGDBServerCLexe: Target connection timeout: 0 ms
    JLinkGDBServerCLexe: ------J-Link related settings------
    JLinkGDBServerCLexe: J-Link Host interface: USB
    JLinkGDBServerCLexe: J-Link script: none
    JLinkGDBServerCLexe: J-Link settings file: none
    JLinkGDBServerCLexe: ------Target related settings------
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    The output says:

    Fullscreen
    1
    2
    [15:24:13] west flash -d /Users/student/abc/build_debug --domain central_unit --dev-id 1050291687 --no-reset
    [15:24:52] Success.
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    and there is no abnormal output on the Serial port.