Cannot flash using NCS 2.9 toolchain in VS Code

OS: Ubuntu 20.04.6 LTS

IDE: Visual Studio Code v1.97.2 and v1.93.0

nRF Connect for VS Code: v2025.1.127

SDK: NCS v2.9

Sample Application: Peripheral_LBS (not ble_peripheral_lbs_coex)

Hardware: nRF52833 and nRF54L15

OS Global python version: 3.8.10

ToolChain Manager: v1.5.3

The specific issue I am encountering seems to be a problem within the NCS v2.9 toolchain that only materializes when attempting to flash my application to a device. After some investigation, I believe the issue is the flashing script using my global python3.8 instead of the python3.12 back-end that should be included within the toolchain. The error output is posted below.

west flash: using runner nrfutil

-- runners.nrfutil: reset after flashing requested

-- runners.nrfutil: Flashing file: /home/kyle/Desktop/peripheral_lbs_1/build_3/merged.hex

Fatal Python error: init_sys_streams: can't initialize sys standard streams

Python runtime state: core initialized

Traceback (most recent call last):

File "/home/***/ncs/toolchains/b77d8c1312/usr/local/lib/python3.12/io.py", line 55, in <module>

ImportError: cannot import name 'text_encoding' from 'io' (unknown location)

-- runners.nrfutil: Board with serial number 1057761682 flashed successfully.

* Terminal will be reused by tasks, press any key to close it.

Background: This project was started a few weeks ago when the NCS v2.9 sdk was originally installed. This initial download of the sdk was able to build and flash without issue, however during development some sdk files were unintentionally modified. In order to revert those changes, the toolchain manager was used to remove and then re-install the sdk on Feb 19th. After the re-install any attempt to flash the application to a device resulted in the python import error.

Setup: Download the NCS 2.9 sdk and toolchain using the toolchain manager as well as the VS Code IDE on a device running Ubuntu 20.04LTS. Install the nRF Connect extension for VS Code and navigate to the nRF Connect tab. Select “Create a new application” and copy the Peripheral_LBS example as the base. Setup the build configuration to use the NCS 2.9 sdk and v2.9 toolchain with an nRF52833dk or nRF54l15dk as the board target. Build the application, which should run without issue, then attempt to flash the application to the device. On flash, the error should be seen.

Resolution Attempts: I have tried re-installing NCS 2.9, re-installing the NCS toolchain, re-installing VS Code, updating VS Code, changing the VS Code python interperter, as well as attempting to flash the application to a nRF54l15dk and a nRF52833dk with the same error encountered on each attempt. I have also attempted to setup NCS 2.9 and VS Code on a second computer also running Ubuntu 20.04 as a fresh install, but the same error was encountered on first flash attempt.

One debugging step that successfully flashed the application to the device was flashing the sample application to the nRF52833dk using the NCS 2.9 sdk and the NCS 2.7 toolchain.

Parents
  • Hi

    Could you generate the support information in vscode also? I will investigate regarding the issue

    Regards

    Runar

  • I believe this is the info you were asking for. If there is anything else that would be helpful, just let me know.

  • Sorry Kyle, I was a bit unclear in my instruction. There is a button to generate support information in the NCS extension. 

    I can't really see any reason why this should fail for you. But just to be sure. You have installed Command line tool, udevrules and nrfutil? 

    Does it work to flash from the command line?

    Regards

    Runar

  • Hi Runar,

    Below is the contents of the generated support file. Command line tool, udevrules, and nrfutil should all be installed.

    {
      "platform": {
        "os": "linux",
        "osVersion": "#99~20.04.1-Ubuntu SMP Thu Nov 2 15:16:47 UTC 2023",
        "osKernel": "5.15.0-89-generic",
        "vscode": "1.97.2",
        "electron": "32.2.7",
        "node": "v20.18.1",
        "name": "Ubuntu",
        "id": "ubuntu",
        "version": "20.04.6 LTS (Focal Fossa)",
        "versionId": "20.04"
      },
      "system": {
        "date": "2025-02-24T16:31:59.397Z",
        "vscodeRoot": "/usr/share/code/resources/app",
        "nrfConnectForDesktopInstalled": "unknown",
        "vscodeUptime": "01:21:09",
        "osUptime": "01:22:41",
        "cpu": "11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz"
      },
      "workspace": {
        "name": "peripheral_lbs_1",
        "workspaceFile": null,
        "folders": [
          "/home/kyle/Desktop/peripheral_lbs_1"
        ]
      },
      "sdks": [
        {
          "version": "v2.9.0",
          "path": "/home/kyle/ncs/v2.9.0"
        },
        {
          "version": "v2.7.0",
          "path": "/home/kyle/ncs/v2.7.0"
        }
      ],
      "activeBuild": "/home/kyle/Desktop/peripheral_lbs_1/build_3",
      "apps": [
        {
          "workspace": "/home/kyle/Desktop/peripheral_lbs_1",
          "uri": "/home/kyle/Desktop/peripheral_lbs_1",
          "buildConfigurations": [
            {
              "id": "/home/kyle/Desktop/peripheral_lbs_1/build_3",
              "name": "build_3",
              "boardId": "nrf54l15dk/nrf54l15/cpuapp",
              "type": "Sysbuild",
              "isChild": false,
              "isStale": false,
              "taskBindings": {
                "build": [],
                "pristineBuild": [],
                "flash": [],
                "eraseAndFlash": []
              },
              "sdk": "/home/kyle/ncs/v2.9.0",
              "toolchain": "nRF Connect SDK Toolchain v2.9.0"
            }
          ]
        }
      ],
      "toolchains": [
        {
          "version": "2.9.0",
          "path": "/home/kyle/ncs/toolchains/b77d8c1312"
        },
        {
          "version": "2.7.0",
          "path": "/home/kyle/ncs/toolchains/e9dba88316"
        }
      ],
      "connectedDevices": [
        {
          "serialNumber": "001057761682"
        }
      ],
      "tools": {
        "/home/kyle/ncs/toolchains/b77d8c1312/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc": "0.17.0",
        "/opt/SEGGER/JLink/JLinkExe": "7.88c",
        "/usr/local/bin/nrfjprog": "10.21.0",
        "/usr/local/bin/nrfutil": null,
        "/home/kyle/ncs/toolchains/b77d8c1312/usr/local/bin/cmake": "3.21.0",
        "/home/kyle/ncs/toolchains/b77d8c1312/usr/local/bin/west": "1.2.0",
        "/home/kyle/ncs/toolchains/b77d8c1312/usr/local/bin/python3": "3.12.4",
        "/home/kyle/ncs/toolchains/b77d8c1312/usr/local/bin/ninja": "1.10.2",
        "/home/kyle/ncs/toolchains/b77d8c1312/usr/bin/gperf": "3.1",
        "/home/kyle/ncs/toolchains/b77d8c1312/usr/bin/dtc": "1.5.0",
        "/home/kyle/ncs/toolchains/b77d8c1312/opt/bin/gn": "2132",
        "/home/kyle/ncs/toolchains/b77d8c1312/usr/local/bin/git": "2.37.3",
        "arm-gdbPath": "/home/kyle/ncs/toolchains/b77d8c1312/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gdb",
        "riscv-gdbPath": "/home/kyle/ncs/toolchains/b77d8c1312/opt/zephyr-sdk/riscv64-zephyr-elf/bin/riscv64-zephyr-elf-gdb"
      },
      "nrfutil": {
        "nrfutil-device": {
          "version": "2.7.9",
          "binPath": "/home/kyle/.vscode/extensions/nordic-semiconductor.nrf-connect-2025.1.127-linux-x64/platform/nrfutil/bin/nrfutil-device",
          "jlinkInfo": {
            "description": "This version of SEGGER J-Link is different from the J-Link version that was used to test nrfutil device commands",
            "expectedVersion": {
              "version": "JLink_V7.94i",
              "versionFormat": "string"
            },
            "name": "JlinkARM",
            "version": "JLink_V7.88c",
            "versionFormat": "string"
          }
        },
        "nrfutil-toolchain-manager": {
          "version": "0.14.4",
          "binPath": "/home/kyle/.vscode/extensions/nordic-semiconductor.nrf-connect-2025.1.127-linux-x64/platform/nrfutil/bin/nrfutil-toolchain-manager"
        }
      },
      "environment": {
        "westEnv": {
          "GIT_EXEC_PATH": "/home/kyle/ncs/toolchains/b77d8c1312/usr/local/libexec/git-core",
          "HOME": "/home/kyle",
          "PATH": "/home/kyle/ncs/toolchains/b77d8c1312/usr/bin:/home/kyle/ncs/toolchains/b77d8c1312/usr/bin:/home/kyle/ncs/toolchains/b77d8c1312/usr/local/bin:/home/kyle/ncs/toolchains/b77d8c1312/opt/bin:/home/kyle/ncs/toolchains/b77d8c1312/opt/nanopb/generator-bin:/home/kyle/ncs/toolchains/b77d8c1312/opt/zephyr-sdk/arm-zephyr-eabi/bin:/home/kyle/ncs/toolchains/b77d8c1312/opt/zephyr-sdk/riscv64-zephyr-elf/bin:/home/kyle/.local/bin:/home/kyle/anaconda3/bin:/home/kyle/anaconda3/condabin:/home/kyle/Desktop/Workspace/Repos/DevOps/bin:/home/kyle/.local/bin:/home/kyle/Desktop/Workspace/Repos/DevOps/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/kyle/Desktop/Workspace/Repos/DevOps/bin:/home/kyle/.local/bin:/home/kyle/anaconda3/bin:/home/kyle/anaconda3/condabin:/home/kyle/Desktop/Workspace/Repos/DevOps/bin:/home/kyle/.local/bin:/home/kyle/Desktop/Workspace/Repos/DevOps/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin",
          "ZEPHYR_BASE": "/home/kyle/ncs/v2.7.0/zephyr",
          "ZEPHYR_TOOLCHAIN_VARIANT": "zephyr",
          "ZEPHYR_SDK_INSTALL_DIR": "/home/kyle/ncs/toolchains/b77d8c1312/opt/zephyr-sdk",
          "PYTHONPATH": "/home/kyle/ncs/toolchains/b77d8c1312/usr/local/lib/python3.12:/home/kyle/ncs/toolchains/b77d8c1312/usr/local/lib/python3.12/site-packages",
          "USER": "kyle"
        },
        "inherited": {
          "ELECTRON_RUN_AS_NODE": "1",
          "HOME": "/home/kyle",
          "PATH": "/home/kyle/.local/bin:/home/kyle/anaconda3/bin:/home/kyle/anaconda3/condabin:/home/kyle/Desktop/Workspace/Repos/DevOps/bin:/home/kyle/.local/bin:/home/kyle/Desktop/Workspace/Repos/DevOps/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin",
          "USER": "kyle"
        }
      },
      "terminal": {
        "defaultProfile": null
      },
      "config": {
        "nordic-semiconductor.nrf-connect": {
          "topdir": "",
          "toolchain": {
            "path": ""
          },
          "ozonePath": "",
          "applications": [],
          "applicationOptions": {},
          "kconfig": {
            "interface": "kconfig"
          },
          "west": {
            "env": {
              "$base": "terminal"
            }
          },
          "boardRoots": [],
          "taskBindings": {},
          "buildTerminal": {
            "condensedProgress": true
          },
          "debugging": {
            "flash": true,
            "bindings": {},
            "justMyCode": false
          },
          "activeAppFollowActiveEditor": true,
          "flash": {
            "softreset": false,
            "erase": false,
            "recover": false
          },
          "enableTelemetry": false,
          "thirdpartyIntegration": {},
          "toolchainManager": {
            "indexURL": null,
            "installDirectory": null
          },
          "nrfutil": {
            "home": null
          },
          "defaultOpenAction": "ask",
          "terminalProfile": {
            "shell": null
          }
        },
        "nordic-semiconductor.nrf-terminal": {
          "terminalMode": "character"
        }
      },
      "extensions": {
        "internal": {
          "nordic-semiconductor.nrf-connect": {
            "version": "2025.1.127",
            "path": "/home/kyle/.vscode/extensions/nordic-semiconductor.nrf-connect-2025.1.127-linux-x64",
            "isActive": true
          },
          "nordic-semiconductor.nrf-terminal": {
            "version": "2024.9.14",
            "path": "/home/kyle/.vscode/extensions/nordic-semiconductor.nrf-terminal-2024.9.14",
            "isActive": true
          },
          "nordic-semiconductor.nrf-devicetree": {
            "version": "2024.12.15",
            "path": "/home/kyle/.vscode/extensions/nordic-semiconductor.nrf-devicetree-2024.12.15",
            "isActive": true
          },
          "nordic-semiconductor.nrf-kconfig": {
            "version": "2024.12.13",
            "path": "/home/kyle/.vscode/extensions/nordic-semiconductor.nrf-kconfig-2024.12.13",
            "isActive": true
          }
        },
        "external": {
          "marus25.cortex-debug": null,
          "ms-vscode.cpptools": "1.23.6",
          "ms-vscode.js-debug": "1.97.1",
          "ms-vscode.js-debug-companion": "1.1.3",
          "ms-vscode.vscode-js-profile-table": "1.0.10",
          "GitHub.copilot": "1.272.0",
          "GitHub.copilot-chat": "0.24.1",
          "ms-python.debugpy": "2025.0.1",
          "ms-python.python": "2025.0.0",
          "ms-python.vscode-pylance": "2025.2.1",
          "ms-vscode.makefile-tools": "0.11.13",
          "trond-snekvik.gnu-mapfiles": "1.1.0"
        }
      }
    }

  • Thank you for the log. I have asked internally and will update when I hear back from them

    Regards

    Runar

  • Thanks, I just got a question forwarded. When toolchain manager" is mentioned is it the nRF Connect application or the nrfUtil CLI?

    Regards

    Runar

Reply Children
Related