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:

__STATIC_FORCEINLINE void __enable_irq(void)
{
  __ASM volatile ("cpsie i" : : : "memory");
}

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

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

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

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
CONFIG_SETTINGS=y
CONFIG_BT_HCI=y

# BT Bonding
CONFIG_BT_SETTINGS=y
CONFIG_BT_SETTINGS_LOG_LEVEL_DBG=y
CONFIG_FLASH=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_FLASH_MAP=y

CONFIG_BT_KEYS_LOG_LEVEL_DBG=y

CONFIG_SETTINGS_NVS=y
CONFIG_NVS=y
CONFIG_MPU_ALLOW_FLASH_WRITE=y
CONFIG_NVS_LOG_LEVEL_DBG=y

CONFIG_HEAP_MEM_POOL_SIZE=1024

#so sniffer can decode encrypted packets
CONFIG_BT_LOG_SNIFFER_INFO=y 

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

#debugging options
CONFIG_DEBUG_OPTIMIZATIONS=y
CONFIG_DEBUG_THREAD_INFO=y
CONFIG_CORTEX_M_DEBUG_MONITOR_HOOK=y
CONFIG_SEGGER_DEBUGMON=y

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

  • 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:

    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------
    JLinkGDBServerCLexe: Target device:                 nRF52840_xxAA
    JLinkGDBServerCLexe: Target device parameters:      none
    JLinkGDBServerCLexe: Target interface:              SWD
    JLinkGDBServerCLexe: Target interface speed:        12000kHz
    JLinkGDBServerCLexe: Target endian:                 little
    JLinkGDBServerCLexe: 
    =thread-group-added,id="i1"
    =cmd-param-changed,param="pagination",value="off"
    __enable_irq () at /opt/nordic/ncs/v2.8.0/modules/hal/cmsis/CMSIS/Core/Include/cmsis_gcc.h:951
    951	  __ASM volatile ("cpsie i" : : : "memory");
    [New Thread 536899472]
    [New Thread 536880040]
    [New Thread 536899256]
    [New Thread 536899840]
    [New Thread 536890528]
    [New Thread 536890744]
    [New Thread 536890960]
    [New Thread 536899072]
    ERROR: Command aborted. See the output window for additional details.

    The output says:

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

    and there is no abnormal output on the Serial port.

Related