Trouble Connecting to nRF5340 via nRFConnect Extension (WSL Environment)

Hi all,

I've been using the nRFConnect extension without any issues, successfully connecting to my nRF5340 board via JLink, flashing firmware, and receiving printed messages using the RTT extension. However, I encountered a problem today: I can no longer connect or upload firmware to the board.

Here’s the error message I received:

FATAL ERROR: command exited with status 33: nrfjprog --recover -f NRF53 --coprocessor CP_NETWORK --snr 260116832

I use WSL and rely on tools like USBPID to enable USB connections from my hardware to the Linux environment. In my debugging attempts, I searched for similar issues and encountered this thread. Following its suggestions, I tested the RTT connection, and while the RTT interface connected, it didn’t function as expected.

These are the screenshots of what I got from the Jlinkexe and RTTClient:

I couldn't find any similar issues in this forum and wanted to know if this was a known issue or how to troubleshoot and get more information about the source of the problem itself. Thank you in advance for any help!

  • Hi,

    I haven't tested using the linux version of nrfjprog, jlinkexe etc. in WSL with USBPID. Instead when using WSL I have replaced the executables for nrfjprog and JLinkExe in /usr/bin with scripts that instead use the windows versions of the tools from within WSL. This has the benefit of not needing to pass the USB device over to the linux environment to connect to them.

    Here's the scripts for replacing nrfjprog and JLinkExe with the windows tools:

    /usr/bin/JLinkExe:

    #!/bin/bash
     
    ARGS=("$@")
    JLINKEXE='/mnt/c/Program Files/SEGGER/JLink/JLink.exe'
    WSLROOT='\\wsl$\Ubuntu'
     
    for IDX in ${!ARGS[*]}; do
            ARG=${ARGS[$IDX]}
            case "$ARG" in
            -*)
                    ;;
            *)
                    if [ -e "$ARG" ]; then
                            NEW=$(wslpath -aw "$ARG" 2>/dev/null) || \
                            NEW="$WSLROOT"$(readlink -f "$ARG" | sed 's@/@\\@g')
                            ARGS[$IDX]=$NEW
                    fi
                    ;;
            esac
    done
     
    exec "$JLINKEXE" "${ARGS[@]}"

    /usr/bin/nrfjprog:

    #!/bin/bash
     
    ARGS=("$@")
    NRFJPROG='/mnt/c/Program Files/Nordic Semiconductor/nrf-command-line-tools/bin/nrfjprog.exe'
    WSLROOT='\\wsl$\Ubuntu'
     
    for IDX in ${!ARGS[*]}; do
            ARG=${ARGS[$IDX]}
            case "$ARG" in
            -*)
                    ;;
            *)
                    if [ -e "$ARG" ]; then
                            NEW=$(wslpath -aw "$ARG" 2>/dev/null) || \
                            NEW="$WSLROOT"$(readlink -f "$ARG" | sed 's@/@\\@g')
                            ARGS[$IDX]=$NEW
                    fi
                    ;;
            esac
    done
     
    exec "$NRFJPROG" "${ARGS[@]}"
    

     

    The scrips need to be set as a executable using chmod +x /usr/bin/nrfjprog /usr/bin/JLinkExe

    I also recommend to rename the existing executables before replacing them, incase you need to revert the changes.

    It should be possible to do the same for other CLI tools, but these are the only ones I have tested.

    This approach requires nRF-Command-Line-Tools and SEGGER JLink to be installed on the host windows system.

     

    Best regards,

    Bendik

Related