Programming an application
For simplicity, this guide will refer to both samples and applications as “applications”.
To program the output build files to your device, which in most of the cases will be zephyr.hex
or merged.hex
, use the steps for the development environment.
Before you program a device in the nRF Connect for VS Code extension, you need to set up a build configuration, which is part of Configuring and building an application.
Complete the following steps to program the application:
Connect the development kit to your PC using a USB cable.
Power on the development kit.
Make sure you are familiar with Hardware-specific programming steps.
Open the nRF Connect extension in Visual Studio Code by clicking its icon in the Activity Bar.
In the extension’s Actions View, click on Flash.
For instructions about programming with the nRF Connect for VS Code extension, see How to flash an application.
If you want to program with custom options or scripts, read about Binding custom tasks to actions in the extension documentation.
For information about how to flash and erase in the nRF Connect for VS Code extension, read about the Application-specific flash options.
Complete the following steps to program the application:
Connect the development kit to your PC using a USB cable.
Power on the development kit.
Make sure you are familiar with Hardware-specific programming steps.
Program the application to the kit using the following command:
west flash --erase
This command erases the full flash memory before programming, which is the recommended approach. If the application depends on other flash memory areas (for example, if it uses the Settings partition where bonding information is stored), erasing the full kit before programming ensures that these areas are updated with the new content. You can also program without erasing.
The west flash
command automatically resets the kit and starts the application.
For more information on programming using the command line, see Flashing in the Zephyr documentation.
The flash command programs all cores by default, both in the nRF Connect for VS Code extension and on the command line.
If you want to program only one selected core, use west flash
on the command line and specify the domain.
Hardware-specific programming steps
Some hardware has platform-specific requirements that must be met before you program the device. For additional information, check the user guide for the hardware platform that you are using.
For example, if you are working with an nRF9160 DK, you need to select the correct position of the board controller switch SW10 before you program the application to your development kit. Programming to Thingy:91 also requires a similar step, but using a different switch (SW2).
- Programming the nRF52840 Dongle
To program the nRF52840 Dongle instead of a development kit, follow the programming instructions in nRF52840 Dongle or use the nRF Connect Programmer app.
Optional programming parameters
You can customize the basic west flash
command in a variety of ways.
The following are most common in the nRF Connect SDK.
For more options, see Zephyr’s Flashing: west flash.
- Programming without
--erase
As an alternative to the recommended
west flash --erase
, you can also clear only those flash memory pages that are to be overwritten with the new application. With such approach, the old data in other areas will be retained.To erase only the areas of flash memory that are required for programming the new application, use the following command:
west flash
- Programming with
--recover
Several Nordic Semiconductor SoCs or SiPs supported in the nRF Connect SDK offer an implementation of the Access port protection mechanism (AP-Protect), a form of readback protection. To disable the AP-Protect, you must recover your device. This is particularly important for multi-core devices.
Use the following command:
west flash --recover
This command uses
nrfjprog --recover
command in the background. It erases all user available non-volatile memory and disables the readback protection mechanism if enabled.