"ERROR: Failed when selecting coprocessor APPLICATION" when attempting to flash blinky sample app on NRF5340

I created a new application using the "Create a new application" > "Copy a sample" > "zephyr/samples/basic/blinky" option in vscode. And I added a new build configuration using the default settings except for changing the board to "nrf5340dk_nrf5340_cpuapp". After building, I pressed the flash button in the actions panel to flash it to my NRF5340 DK. It executes the following command (without --log), which I also tried running manually:

Desktop nrfjprog --program /opt/nordic/ncs/v2.6.1/nrf/applications/nrf5340dk_nrf5340_cpuapp/blinky/build/zephyr/zephyr.hex --chiperase --verify -f NRF53 --coprocessor CP_APPLICATION --snr 1050303214 --log
[error] [ Client] - Encountered error -5: Command select_coprocessor executed for 6 milliseconds with result -5
ERROR: Failed when selecting coprocessor APPLICATION
[error] [ Worker] - Encountered unexpected debug port ID 2, expected 6
ERROR: The --family option given with the command (or the default from
ERROR: nrfjprog.ini) does not match the device connected.

Why isn't it able to recognize the coprocessor when flashing? The computer (and jlink) is able to recognize my development kit just fine. I have tried everything from selecting all the other nrf5340dk boards in the board configuration settings and rebuilding/reflashing, to running "nrfjprog --recover" and "nrfjprog --eraseall" to reset everything. Why is it so hard to get a blinky app to work? Seems so basic, yet I've been trying for 2 days and still haven't gotten anywhere. I have two NRF 5340 DK boards and they both do the same thing. I attached the logs that I generated from running the command to flash.

[2024-May-04 16:51:44] [debug] --------------------------------------------------------------------------------
[2024-May-04 16:51:44] [debug] nrfjprog --program /opt/nordic/ncs/v2.6.1/nrf/applications/nrf5340dk_nrf5340_cpuapp/blinky/build/zephyr/zephyr.hex --chiperase --verify -f NRF53 --coprocessor CP_APPLICATION --snr 1050303214 --log 
[2024-May-04 16:51:44] [debug] nrfjprog version 10.24.2 external
[2024-May-04 16:51:44] [debug] --------------------------------------------------------------------------------
[2024-May-04 16:51:44] [ info] Load library at /Applications/Nordic Semiconductor/lib/libnrfjprogdll.dylib.
[2024-May-04 16:51:44] [ info] Library loaded, loading member functions.
[2024-May-04 16:51:44] [ info] Member functions succesfully loaded.
[2024-May-04 16:51:44] [debug] [ Client] - open
[2024-May-04 16:51:44] [debug] [ Client] - start
[2024-May-04 16:51:44] [ info] [ Client] - stdout: Jlinkarm nRF Worker ready. Handling sequence ae2c3880-cbd9-4ec7-8f44-4343bef59c0a.
[2024-May-04 16:51:44] [debug] [SeggerBackend] - Logger sink registered in Segger backend logger
[2024-May-04 16:51:44] [debug] [  JLink] - Logger sink registered in JLink logger
[2024-May-04 16:51:44] [debug] [  nRF53] - open
[2024-May-04 16:51:44] [debug] [  nRF53] - just_check_family
[2024-May-04 16:51:44] [debug] [SeggerBackend] - open_dll
[2024-May-04 16:51:44] [debug] [SeggerBackend] - No J-Link DLL path was provided. Attempting to auto detect.
[2024-May-04 16:51:44] [ info] [SeggerBackend] - Load library at /Applications/SEGGER/JLink/libjlinkarm.dylib.
[2024-May-04 16:51:44] [trace] [ Client] - Command open executed for 49 milliseconds with result 0
[2024-May-04 16:51:44] [debug] [ Client] - config
[2024-May-04 16:51:44] [ info] [SeggerBackend] - Library loaded, loading member functions.
[2024-May-04 16:51:44] [ info] [SeggerBackend] - Member functions succesfully loaded.
[2024-May-04 16:51:44] [debug] [SeggerBackend] - Set batch mode
[2024-May-04 16:51:44] [debug] [SeggerBackend] - dll_version
[2024-May-04 16:51:44] [ info] [SeggerBackend] - Segger dll version 7.94.e loaded.
[2024-May-04 16:51:44] [trace] [ Worker] - Command open executed for 29 milliseconds with result 0
[2024-May-04 16:51:44] [debug] [  nRF53] - config
[2024-May-04 16:51:44] [trace] [ Client] - Command config executed for 12 milliseconds with result 0
[2024-May-04 16:51:44] [debug] [ Client] - enum_emu_snr
[2024-May-04 16:51:44] [trace] [ Client] - Command enum_emu_con_info executed for 6 milliseconds with result 0
[2024-May-04 16:51:44] [debug] [ Client] - connect_to_emu_with_snr
[2024-May-04 16:51:44] [debug] [SeggerBackend] - enum_emu_snr
[2024-May-04 16:51:44] [trace] [ Worker] - Command config executed for 4 milliseconds with result 0
[2024-May-04 16:51:44] [debug] [  nRF53] - enum_emu_con_info
[2024-May-04 16:51:44] [debug] [SeggerBackend] - is_connected_to_emu
[2024-May-04 16:51:44] [debug] [SeggerBackend] - enum_emu_con_info
[2024-May-04 16:51:44] [debug] [SeggerBackend] - is_connected_to_emu
[2024-May-04 16:51:44] [trace] [ Worker] - Command enum_emu_con_info executed for 0 milliseconds with result 0
[2024-May-04 16:51:44] [debug] [  nRF53] - connect_to_emu_with_snr
[2024-May-04 16:51:44] [debug] [SeggerBackend] - is_connected_to_emu
[2024-May-04 16:51:44] [debug] [SeggerBackend] - connect_to_emu_with_snr
[2024-May-04 16:51:44] [debug] [SeggerBackend] - is_connected_to_emu
[2024-May-04 16:51:44] [debug] [SeggerBackend] - ---just_enum_emu_snr
[2024-May-04 16:51:44] [debug] [SeggerBackend] - ---just_get_num_emus
[2024-May-04 16:51:44] [debug] [SeggerBackend] - ---just_connect_to_emu_with_snr
[2024-May-04 16:51:44] [debug] [SeggerBackend] - ---just_connect_to_emu_without_snr
[2024-May-04 16:51:44] [debug] [SeggerBackend] - Segger logging enabled.
[2024-May-04 16:51:44] [trace] [  JLink] - Firmware: J-Link OB-nRF5340-NordicSemi compiled Oct 30 2023 12:13:06
[2024-May-04 16:51:44] [trace] [  JLink] - Firmware: J-Link OB-nRF5340-NordicSemi compiled Oct 30 2023 12:13:06
[2024-May-04 16:51:44] [trace] [  JLink] - Hardware: V1.00
[2024-May-04 16:51:44] [trace] [  JLink] - S/N: 1050303214
[2024-May-04 16:51:44] [trace] [  JLink] - OEM: SEGGER
[2024-May-04 16:51:44] [trace] [  JLink] - Feature(s): RDI, FlashBP, FlashDL, JFlash, GDB
[2024-May-04 16:51:44] [trace] [  JLink] - Bootloader: 2021 May 18
[2024-May-04 16:51:44] [trace] [  JLink] - USB speed mode: Full speed (12 MBit/s)
[2024-May-04 16:51:44] [trace] [  JLink] - TELNET listener socket opened on port 19021
[2024-May-04 16:51:44] [trace] [  JLink] - WEBSRV WEBSRV_Init(): Starting webserver thread(s)
[2024-May-04 16:51:44] [trace] [  JLink] - WEBSRV Webserver running on local port 19080
[2024-May-04 16:51:44] [trace] [  JLink] - Looking for J-Link GUI Server exe at: /Applications/SEGGER/JLink_V794e/JLinkGUIServerExe 
[2024-May-04 16:51:44] [trace] [  JLink] - Forking J-Link GUI Server: /Applications/SEGGER/JLink_V794e/JLinkGUIServerExe 
[2024-May-04 16:51:44] [trace] [  JLink] - J-Link GUI Server info: "J-Link GUI server V7.94e " 
[2024-May-04 16:51:44] [trace] [ Client] - Command connect_to_emu_with_snr executed for 402 milliseconds with result 0
[2024-May-04 16:51:44] [debug] [ Client] - read_connected_emu_snr
[2024-May-04 16:51:44] [trace] [ Client] - Command read_connected_emu_snr executed for 6 milliseconds with result 0
[2024-May-04 16:51:44] [debug] [ Client] - enable_coprocessor
[2024-May-04 16:51:44] [trace] [  JLink] - - 366.159ms returns "O.K."  
[2024-May-04 16:51:44] [trace] [  JLink] - JLINK_HasError()  
[2024-May-04 16:51:44] [trace] [  JLink] - JLINK_Lock()  
[2024-May-04 16:51:44] [trace] [  JLink] - JLINK_ExecCommand("SetRestartOnClose = 0", ...).   
[2024-May-04 16:51:44] [trace] [  JLink] - - 0.133ms returns 0x01  
[2024-May-04 16:51:44] [trace] [  JLink] - JLINK_HasError()  
[2024-May-04 16:51:44] [trace] [  JLink] - JLINK_ExecCommand("DisableFlashDL", ...).   
[2024-May-04 16:51:44] [trace] [  JLink] - - 0.001ms returns 0x00  
[2024-May-04 16:51:44] [trace] [  JLink] - JLINK_HasError()  
[2024-May-04 16:51:44] [trace] [  JLink] - JLINK_ExecCommand("ExcludeFlashCacheRange 0x0-0xFFFFFFFF", ...).   
[2024-May-04 16:51:44] [trace] [  JLink] - - 0.116ms returns 0x00  
[2024-May-04 16:51:44] [trace] [  JLink] - JLINK_HasError()  
[2024-May-04 16:51:44] [trace] [  JLink] - JLINK_SetHookUnsecureDialog  
[2024-May-04 16:51:44] [trace] [  JLink] - JLINK_SetHookUnsecureDialog(...)
[2024-May-04 16:51:44] [trace] [  JLink] - - 0.003ms returns 0  
[2024-May-04 16:51:44] [trace] [  JLink] - JLINK_HasError()  
[2024-May-04 16:51:44] [trace] [  JLink] - JLINK_TIF_Select(JLINKARM_TIF_SWD)  
[2024-May-04 16:51:44] [trace] [  JLink] - - 1.623ms returns 0x00  
[2024-May-04 16:51:44] [trace] [  JLink] - JLINK_HasError()  
[2024-May-04 16:51:44] [trace] [  JLink] - JLINK_GetSpeedInfo()  
[2024-May-04 16:51:44] [trace] [  JLink] - 128000000 Hz / n, n >= 64
[2024-May-04 16:51:44] [trace] [  JLink] - - 0.003ms  
[2024-May-04 16:51:44] [trace] [  JLink] - JLINK_HasError()  
[2024-May-04 16:51:44] [debug] [SeggerBackend] - Connected emulator supports SWD speeds up to 2000kHz
[2024-May-04 16:51:44] [trace] [  JLink] - JLINK_SetSpeed(2000)  
[2024-May-04 16:51:44] [trace] [  JLink] - - 0.284ms  
[2024-May-04 16:51:44] [trace] [  JLink] - JLINK_HasError()  
[2024-May-04 16:51:44] [trace] [  JLink] - JLINK_GetSpeed()  
[2024-May-04 16:51:44] [trace] [  JLink] - - 0.001ms returns 2000  
[2024-May-04 16:51:44] [trace] [  JLink] - JLINK_HasError()  
[2024-May-04 16:51:44] [debug] [SeggerBackend] - SWD clock set to 2000kHz
[2024-May-04 16:51:44] [trace] [  JLink] - JLINK_GetSN()  
[2024-May-04 16:51:44] [trace] [  JLink] - - 0.001ms returns 1050303214  
[2024-May-04 16:51:44] [trace] [  JLink] - JLINK_HasError()  
[2024-May-04 16:51:44] [trace] [  JLink] - - 0.002ms  
[2024-May-04 16:51:44] [debug] [  nRF53] - read_device_family
[2024-May-04 16:51:44] [trace] [ Worker] - Command connect_to_emu_with_snr executed for 395 milliseconds with result 0
[2024-May-04 16:51:44] [debug] [  nRF53] - read_connected_emu_snr
[2024-May-04 16:51:44] [debug] [SeggerBackend] - is_connected_to_emu
[2024-May-04 16:51:44] [trace] [  JLink] - JLINK_IsOpen()  
[2024-May-04 16:51:44] [trace] [  JLink] - - 0.002ms returns 0x01  
[2024-May-04 16:51:44] [trace] [  JLink] - JLINK_HasError()  
[2024-May-04 16:51:44] [trace] [  JLink] - JLINK_Lock()  
[2024-May-04 16:51:44] [debug] [SeggerBackend] - read_connected_emu_snr
[2024-May-04 16:51:44] [trace] [  JLink] - - 0.001ms  
[2024-May-04 16:51:44] [trace] [ Worker] - Command read_connected_emu_snr executed for 0 milliseconds with result 0
[2024-May-04 16:51:44] [trace] [ Client] - Command enable_coprocessor executed for 12 milliseconds with result 0
[2024-May-04 16:51:44] [debug] [ Client] - select_coprocessor
[2024-May-04 16:51:44] [debug] [  nRF53] - enable_coprocessor
[2024-May-04 16:51:44] [debug] [SeggerBackend] - is_connected_to_emu
[2024-May-04 16:51:44] [trace] [  JLink] - JLINK_IsOpen()  
[2024-May-04 16:51:44] [trace] [  JLink] - - 0.007ms returns 0x01  
[2024-May-04 16:51:44] [trace] [  JLink] - JLINK_HasError()  
[2024-May-04 16:51:44] [trace] [  JLink] - JLINK_Lock()  
[2024-May-04 16:51:44] [debug] [  nRF53] - Just_enable_coprocessor
[2024-May-04 16:51:44] [trace] [  JLink] - - 0.035ms  
[2024-May-04 16:51:44] [trace] [ Worker] - Command enable_coprocessor executed for 0 milliseconds with result 0
[2024-May-04 16:51:44] [debug] [  nRF53] - select_coprocessor
[2024-May-04 16:51:44] [debug] [SeggerBackend] - is_connected_to_emu
[2024-May-04 16:51:44] [trace] [  JLink] - JLINK_IsOpen()  
[2024-May-04 16:51:44] [trace] [  JLink] - - 0.003ms returns 0x01  
[2024-May-04 16:51:44] [trace] [  JLink] - JLINK_HasError()  
[2024-May-04 16:51:44] [trace] [  JLink] - JLINK_Lock()  
[2024-May-04 16:51:44] [debug] [SeggerBackend] - is_connected_to_device
[2024-May-04 16:51:44] [debug] [SeggerBackend] - is_connected_to_device
[2024-May-04 16:51:44] [trace] [  JLink] - JLINK_IsConnected()  
[2024-May-04 16:51:44] [trace] [  JLink] - - 0.001ms returns FALSE  
[2024-May-04 16:51:44] [trace] [  JLink] - JLINK_HasError()  
[2024-May-04 16:51:44] [debug] [  nRF53] - Just_select_coprocessor
[2024-May-04 16:51:44] [ info] [  nRF53] - Loading new coprocessor data.
[2024-May-04 16:51:44] [debug] [  nRF53] - Just_load_coprocessor_data
[2024-May-04 16:51:44] [debug] [SeggerBackend] - set_core_data
[2024-May-04 16:51:44] [debug] [SeggerBackend] - Set core data:
[2024-May-04 16:51:44] [debug] [SeggerBackend] -   Device ID: Cortex-M33
[2024-May-04 16:51:44] [debug] [SeggerBackend] -   Expected core: 235012351
[2024-May-04 16:51:44] [debug] [SeggerBackend] -   Existing Expected core: 235012351
[2024-May-04 16:51:44] [debug] [SeggerBackend] -   Coprocessor: APPLICATION
[2024-May-04 16:51:44] [debug] [SeggerBackend] -   AHB AP index: 0
[2024-May-04 16:51:44] [debug] [SeggerBackend] -   Core base address: 4294967295
[2024-May-04 16:51:44] [debug] [  nRF53] - Just_readback_status
[2024-May-04 16:51:44] [debug] [SeggerBackend] - read_access_port_register
[2024-May-04 16:51:44] [debug] [SeggerBackend] - ---just_read_access_port_register
[2024-May-04 16:51:44] [debug] [SeggerBackend] - coresight_configure
[2024-May-04 16:51:44] [trace] [  JLink] - JLINK_GetHWStatus(...)  
[2024-May-04 16:51:44] [trace] [  JLink] - - 0.442ms returns 0  
[2024-May-04 16:51:44] [trace] [  JLink] - JLINK_HasError()  
[2024-May-04 16:51:44] [trace] [  JLink] - JLINK_CORESIGHT_Configure()  
[2024-May-04 16:51:44] [trace] [  JLink] - - 0.419ms returns 0  
[2024-May-04 16:51:44] [trace] [  JLink] - JLINK_HasError()  
[2024-May-04 16:51:44] [debug] [SeggerBackend] - read_debug_port_idr
[2024-May-04 16:51:44] [debug] [SeggerBackend] - read_debug_port_register
[2024-May-04 16:51:44] [debug] [SeggerBackend] - ---just_read_debug_port_register
[2024-May-04 16:51:44] [debug] [SeggerBackend] - ---just_select_debug_port_register
[2024-May-04 16:51:44] [debug] [SeggerBackend] - Select AP 255, DP Bank 0, AP Bank 255
[2024-May-04 16:51:44] [trace] [  JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x02, 0x00000000)  
[2024-May-04 16:51:44] [trace] [  JLink] - - 1.127ms returns 0  
[2024-May-04 16:51:44] [trace] [  JLink] - JLINK_HasError()  
[2024-May-04 16:51:44] [trace] [  JLink] - JLINK_CORESIGHT_ReadAPDPReg(DP reg 0x00)  
[2024-May-04 16:51:44] [trace] [  JLink] - Value=0x2BA01477
[2024-May-04 16:51:44] [trace] [  JLink] - - 0.407ms returns 0  
[2024-May-04 16:51:44] [trace] [  JLink] - JLINK_HasError()  
[2024-May-04 16:51:44] [error] [ Client] - Encountered error -5: Command select_coprocessor executed for 6 milliseconds with result -5
[2024-May-04 16:51:44] [trace] [  JLink] - - 0.878ms  
[2024-May-04 16:51:44] [error] [ Worker] - Encountered unexpected debug port ID 2, expected 6
[2024-May-04 16:51:44] [trace] [ Worker] - Command select_coprocessor executed for 3 milliseconds with result -5
[2024-May-04 16:51:44] [debug] [  nRF53] - close
[2024-May-04 16:51:44] [debug] [SeggerBackend] - is_connected_to_emu
[2024-May-04 16:51:44] [trace] [  JLink] - JLINK_IsOpen()  
[2024-May-04 16:51:44] [trace] [  JLink] - - 0.004ms returns 0x01  
[2024-May-04 16:51:44] [trace] [  JLink] - JLINK_HasError()  
[2024-May-04 16:51:44] [trace] [  JLink] - JLINK_Lock()  
[2024-May-04 16:51:44] [debug] [SeggerBackend] - close
[2024-May-04 16:51:44] [debug] [SeggerBackend] - disconnect_from_emu
[2024-May-04 16:51:44] [debug] [SeggerBackend] - ---just_disconnect_from_emu
[2024-May-04 16:51:44] [debug] [SeggerBackend] - is_connected_to_device
[2024-May-04 16:51:44] [trace] [  JLink] - JLINK_IsConnected()  
[2024-May-04 16:51:44] [trace] [  JLink] - - 0.001ms returns FALSE  
[2024-May-04 16:51:44] [trace] [  JLink] - JLINK_HasError()  
[2024-May-04 16:51:44] [debug] [SeggerBackend] - ---just_is_debug_region_powered
[2024-May-04 16:51:44] [debug] [SeggerBackend] - ---just_read_debug_port_register
[2024-May-04 16:51:44] [debug] [SeggerBackend] - ---just_select_debug_port_register
[2024-May-04 16:51:44] [debug] [SeggerBackend] - Select AP 255, DP Bank 0, AP Bank 255
[2024-May-04 16:51:44] [trace] [  JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x02, 0x00000000)  
[2024-May-04 16:51:44] [trace] [  JLink] - - 0.210ms returns 0  
[2024-May-04 16:51:44] [trace] [  JLink] - JLINK_HasError()  
[2024-May-04 16:51:44] [trace] [  JLink] - JLINK_CORESIGHT_ReadAPDPReg(DP reg 0x01)  
[2024-May-04 16:51:44] [trace] [  JLink] - Value=0xF0000040
[2024-May-04 16:51:44] [trace] [  JLink] - - 0.417ms returns 0  
[2024-May-04 16:51:44] [trace] [  JLink] - JLINK_HasError()  
[2024-May-04 16:51:44] [debug] [SeggerBackend] - unpower_debug_and_system_regions
[2024-May-04 16:51:44] [debug] [SeggerBackend] - ---just_write_debug_port_register
[2024-May-04 16:51:44] [debug] [SeggerBackend] - ---just_select_debug_port_register
[2024-May-04 16:51:44] [trace] [  JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x01, 0x00000000)  
[2024-May-04 16:51:44] [trace] [  JLink] - - 0.411ms returns 0  
[2024-May-04 16:51:44] [trace] [  JLink] - JLINK_HasError()  
[2024-May-04 16:51:44] [debug] [SeggerBackend] - ---just_is_debug_region_powered
[2024-May-04 16:51:44] [debug] [SeggerBackend] - ---just_read_debug_port_register
[2024-May-04 16:51:44] [debug] [SeggerBackend] - ---just_select_debug_port_register
[2024-May-04 16:51:44] [trace] [  JLink] - JLINK_CORESIGHT_ReadAPDPReg(DP reg 0x01)  
[2024-May-04 16:51:44] [trace] [  JLink] - Value=0x00000040
[2024-May-04 16:51:44] [trace] [  JLink] - - 0.887ms returns 0  
[2024-May-04 16:51:44] [trace] [  JLink] - JLINK_HasError()  
[2024-May-04 16:51:44] [trace] [  JLink] - - 0.006ms  
[2024-May-04 16:51:44] [trace] [  JLink] - JLINK_Close()  
[2024-May-04 16:51:44] [debug] [SeggerBackend] - Segger Backend closed.
[2024-May-04 16:51:44] [debug] [  nRF53] - nRF family DLL closed
[2024-May-04 16:51:44] [trace] [ Client] - Command close executed for 48 milliseconds with result 0
[2024-May-04 16:51:44] [debug] [ Client] - terminate
[2024-May-04 16:51:44] [trace] [ Client] - Command terminate executed for 6 milliseconds with result 0
[2024-May-04 16:51:44] [trace] [ Worker] - Command close executed for 43 milliseconds with result 0
[2024-May-04 16:51:44] [trace] [ Worker] - Command terminate executed for 0 milliseconds with result 0
[2024-May-04 16:51:44] [trace] [ Worker] - Executed 9 commands for 474 milliseconds
[2024-May-04 16:51:44] [debug]

Related