VSCode Plugin Erase and Flash without erasing external flash. west flash --erase without erasing QSPI flash

Since a while back (github.com/.../999b6a14a4556f16d2f535207a84ceb2cca54f8a) the west flash command with --erase was changed so that --erase would also erase external flash. It adds options to override that also by adding new arguments --erase-mode and --ext-erase-mode

There are two issues.

1. (Bug) Combining those two only works on nRF54L15, which is a bug, as that should be allowed on other MCUs also, such as nRF5340 and others, just no one thought of this use case I think. 

west flash -d my_build_dir --erase-mode=all --ext-erase-mode=none

FATAL ERROR: Option --erase-mode can only be used with the nRF54L family.

2. (Feature request) There is no way in VSCode Plugin to in a generic way add this. (when above is fixed)

I want to use the vscode task type "nrf-connect-flash" as it automatically knows the active app, build dir. etc. So as far as I know there is not way to manually create shell command that calls west flash manually with those arguments that work for any application in the plugin.

This is what I want:

{
"type": "nrf-connect-flash",
"label": "Custom Flash with Erase",
"config": "${activeConfig}",
"erase": true,
"softreset": false,
"args": ["-erase-mode=all", "--ext-erase-mode=none"], //<- Appends extra args to west flash, not supported by plugin today
"problemMatcher": []
}

Alternatively adding the external flash config to the VSCode Plugin such as "erase" and "softreset" already are. Probably the better way.

The reason this is important i that for us is we want to flash with --erase as it's much faster as we use pretty much whole nRF5340 flash. Doing a sector erase is much slower ~30 seconds compare to chip erase ~few seconds only. So without --erase each flash during development adds like ~25 seconds. 

Now since the change (commit referenced earlier) --erase also wipes the full external flash, which takes 2 minutes for us and also all content is gone. We save resources on external flash that takes ~60 seconds to upload there. 

Parents
  • Hello,

    Until the upcoming release, a possible workaround is to create a task of type nrf-connect-shell instead of nrf-connect-flash, specify the full west flash command with the required arguments, and then bind that task to the build configuration.

    {
       "label": "My Custom Flash Task",
       "command": "west flash --erase-mode=all --ext-erase-mode=none",
       "type": "nrf-connect-shell"
    }

    "nrf-connect.taskBindings": {
          "flash": [
            {
              "taskName": "My Custom Flash Task",
              "buildConfigs": ["${workspaceFolder}/build"]
            }
          ]
        }

    Kind Regards,

    Abhijith

Reply
  • Hello,

    Until the upcoming release, a possible workaround is to create a task of type nrf-connect-shell instead of nrf-connect-flash, specify the full west flash command with the required arguments, and then bind that task to the build configuration.

    {
       "label": "My Custom Flash Task",
       "command": "west flash --erase-mode=all --ext-erase-mode=none",
       "type": "nrf-connect-shell"
    }

    "nrf-connect.taskBindings": {
          "flash": [
            {
              "taskName": "My Custom Flash Task",
              "buildConfigs": ["${workspaceFolder}/build"]
            }
          ]
        }

    Kind Regards,

    Abhijith

Children
  • Hi, yes this I tried before, but AFAIK I can't get the actual selected build folder there hence not a good solution.
    I need to dynamically the folder and device id like this, I do not want to hard code it.
    west flash -d build_folder --dev-id dev_id_corresponding_to_this_build_folder

    Anyway I patched Zephyr to not do erase of external flash for now so we are good until both VSCode (1. (Bug)) and west flash (2. (Feature request)) are fixed.

  • Not sure if useful to you, but due to the extreme flakiness of flashing and debugging in the nrf connect VS Code extension, I wrote a few lines to allow use of custom build & flash etc scripts:

    ...
    
    "nrf-connect.taskBindings": {
             "eraseAndFlash": [
                {
                   "taskName": "Monkey Script"
                }
             ]
          }
       },
       "tasks": {
          "version": "2.0.0",
          "tasks": [
             {
                "type": "nrf-connect-shell",
                "label": "Monkey Script",
                "command": "base=$(cygpath '${workspaceFolder}') && bash \"${base}/z-prod-utils/scripts/monkey_flash.bash\"",
                "cwd": "${activeConfig}",
                "problemMatcher": []
             }
          ]
       },

    and then in the script (just a bash script) - you can do whatever the hell you like. 

    ## Get 
    build_folder=$(dirname $(pwd))
    domain_name=$(basename $(pwd))
    build_folder_name=$(basename ${build_folder})
    
    
    echo "========================================="
    echo "Monkey Flash Script"
    echo "========================================="
    echo ""
    echo "App build Location  : $(pwd)"
    echo "App domain_name     : ${domain_name}"
    echo "build_folder        : ${build_folder_name}"
    echo ""
    
    
    echo "========================================="
    echo "Flashing to nRF9151DK"
    echo "========================================="
    echo "std command = west flash -d ${build_folder} --domain ${domain_name} --dev-id 1051278334"
    echo "========================================="
    echo ""
    echo "our command = west flash -d ${build_folder} --domain ${domain_name} --recover"
    echo "========================================="
    echo ""
    west flash -d ${build_folder} --domain ${domain_name} --recover
    echo ""

Related