Nrf52840 Dongle programming with the NRF52840 DK - Using the SWD

Hello

I am new to the NRF Connect and NRF board development. I was trying to run a blinky code on the nrf 52840 dongle using the nrf52840dk. I was referencing the following two docs:

https://docs.nordicsemi.com/bundle/ug_nrf5340_dk/page/UG/dk/ext_programming_support_P20.html
https://docs.nordicsemi.com/bundle/ug_nrf52840_dongle/page/UG/nrf52840_Dongle/hw_swd_if.html

However, when I run the code the led does not blink

I took the following steps:
1. I made sure to connect the dongle the way the schematic is shown, although instead if Vtg pin being present on P20, there is a SWD Sel pin on my board, so for one test I did not connect that and for the other I connected it to the Vdd as shown in the diagram
2. I added a build configuration for nrf52840 Dongle on the NRF Connect in the VS Code
3. I clicked Build and then Flash and no errors were shown, but the led does not blink. 

4. Since it was not showing, I rebuild the code and then ran a debug (without the vtg connection since there is not vtg on my side):

JLinkGDBServerCL: SEGGER J-Link GDB Server V7.94e Command Line Version
JLinkGDBServerCL:
JLinkGDBServerCL: JLinkARM.dll V7.94e (DLL compiled Jan 15 2024 15:18:46)
JLinkGDBServerCL:
JLinkGDBServerCL: -----GDB Server start settings-----
JLinkGDBServerCL: GDBInit file: none
JLinkGDBServerCL: GDB Server Listening port: 50631
JLinkGDBServerCL: SWO raw output listening port: 2332
JLinkGDBServerCL: Terminal I/O port: 2333
JLinkGDBServerCL: Accept remote connection: localhost only
JLinkGDBServerCL: Generate logfile: off
JLinkGDBServerCL: Verify download: off
JLinkGDBServerCL: Init regs on start: off
JLinkGDBServerCL: Silent mode: on
JLinkGDBServerCL: Single run mode: on
JLinkGDBServerCL: Target connection timeout: 0 ms
JLinkGDBServerCL: ------J-Link related settings------
JLinkGDBServerCL: J-Link Host interface: USB
JLinkGDBServerCL: J-Link script: none
JLinkGDBServerCL: J-Link settings file: none
JLinkGDBServerCL: ------Target related settings------
JLinkGDBServerCL: Target device: nRF52840_xxAA
JLinkGDBServerCL: Target device parameters: none
JLinkGDBServerCL: Target interface: SWD
JLinkGDBServerCL: Target interface speed: 12000kHz
JLinkGDBServerCL: Target endian: little
JLinkGDBServerCL:
=thread-group-added,id="i1"
=cmd-param-changed,param="pagination",value="off"
0xfffffffe in ?? ()

Program received signal SIGTRAP, Trace/breakpoint trap.
0x00000578 in ?? ()



But when I do connect the SWC Sel to the vdd as shown in the diagram I get the following debug message:

-- west flash: using runner nrfjprog
-- runners.nrfjprog: Flashing file: c:\Users\zuran\Desktop\Nordic_Course\Blinky\build_1\zephyr\zephyr.hex
[error] [ Client] - Encountered error -102: Command read_device_info executed for 139 milliseconds with result -102
[error] [ Worker] - An unknown error.
[error] [ Client] - Encountered error -102: Command read_memory_descriptors executed for 32 milliseconds with result -102
Failed to read device memories.
[error] [ Worker] - An unknown error.
ERROR: JLinkARM DLL reported an error. Try again. If error condition
ERROR: persists, run the same command again with argument --log, contact Nordic
ERROR: Semiconductor and provide the generated log.log file to them.
NOTE: For additional output, try running again with logging enabled (--log).
NOTE: Any generated log error messages will be displayed.
FATAL ERROR: command exited with status 33: nrfjprog --program 'c:\Users\zuran\Desktop\Nordic_Course\Blinky\build_1\zephyr\zephyr.hex' --sectoranduicrerase --verify -f NRF52 --snr 1050268299


And here is the normal blinky script. I did not change it: 

#include <stdio.h>
#include <zephyr/kernel.h>
#include <zephyr/drivers/gpio.h>

/* 1000 msec = 1 sec */
#define SLEEP_TIME_MS   500

/* The devicetree node identifier for the "led0" alias. */
#define LED0_NODE DT_ALIAS(led0)

/*
 * A build error on this line means your board is unsupported.
 * See the sample documentation for information on how to fix this.
 */
static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios);

int main(void)
{
    int ret;
    bool led_state = true;

    if (!gpio_is_ready_dt(&led)) {
        return 0;
    }

    ret = gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE);
    if (ret < 0) {
        return 0;
    }

    while (1) {
        ret = gpio_pin_toggle_dt(&led);
        if (ret < 0) {
            return 0;
        }

        led_state = !led_state;
        printf("LED state: %s\n", led_state ? "ON" : "OFF");
        k_msleep(SLEEP_TIME_MS);
    }
    return 0;
}



  • Hi

    I think it would be easier just to program the nRF52840 Dongle with the nRF Connect Programmer app for Desktop if possible. You can see the Dongle Programming tutorial available here for details on how to do so. Note that the "adapt a BLE example" sections are currently outdated, and it should be sufficient just to build the sample with the nRF52840 Dongle as a build target in VS Code. Then you can flash the .hex file onto the Dongle with the Programmer app by just plugging it into the computer and connecting to it from there.

    You can also check out the Using an external debugger section in the tutorial for an in-depth explanation on how to connect it to your DK:  nRF52840 Dongle Programming Tutorial 

    Best regards,

    Simon

Related