Building and programming a sample application

The recommended way of building and programming an nRF Connect SDK sample is to use the Nordic Edition of the SEGGER Embedded Studio (SES) IDE.

Note

See Programming precompiled firmware images and Building and programming from the source code for information about programming a Thingy:91.

Building with SES

Complete the following steps to build nRF Connect SDK projects with SES after installing SEGGER Embedded Studio and completing the first time setup:

  1. Start SEGGER Embedded Studio by running bin/emStudio.

  2. Select File -> Open nRF Connect SDK Project.

    Open nRF Connect SDK Project menu

    Open nRF Connect SDK Project menu

  3. To import a project into SES, you must specify the following information:

    • CMakeLists.txt - the location of the CMakeLists.txt project file of the sample that you want to work with

    • Board Directory - the location of the board description of the board for which to build the project

    • Board Name - the board name (select from the list that is populated based on the board directory)

    • Build Directory - the folder in which to run the build (automatically filled based on the board name, but you can specify a different directory)

    • Delete Existing CMakeCache.txt - select this option to ensure that you are not building with an outdated build cache

  1. Click OK to import the project into SES. You can now work with the project in the IDE.

  1. Build and program your project.

    The required steps differ depending on if you build a single application or a multi-image project (such as the nRF9160 samples, which include SPM).

    Important

    If you are working with an nRF9160 DK, make sure to select the correct controller before you program the application to your board.

    Put the SW5 switch (marked debug/prog) in the NRF91 position to program the main controller, or in the NRF52 position to program the board controller. See the Device programming section in the nRF9160 DK User Guide for more information.

    To build and program an application:

    1. Select your project in the Project Explorer.

    2. From the menu, select Build -> Build Solution.

    3. When the build completes, you can program the sample to a connected board:

      • For a single-image application, select Target -> Download zephyr/zephyr.elf.

      • For a multi-image application, select Target -> Download zephyr/merged.hex.

    Note

    Alternatively, choose the Build and Debug option. Build and Debug will build the application and program it when the build completes.

  2. To inspect the details of the code that was programmed and the memory usage, click Debug -> Go.

    Note

    In a multi-image build, this allows you to debug the source code of your application only.

If you get an error that a tool or command cannot be found, first make sure that the tool is installed. If it is installed, verify that its location is correct in the PATH variable or, if applicable, in the SES settings.

Building on the command line

Complete the following steps to build nRF Connect SDK projects on the command line after completing the command-line build setup.

  1. Open a terminal window.

  2. Go to the specific sample or application directory. For example, to build the nRF9160: AT Client sample, run the following command to navigate to the sample directory:

    cd nrf/samples/nRF9160/at_client
    
  3. Build the sample or application using the west command. The development board is specified by the parameter board_name in the west command as follows:

    west build -b board_name

    Note

    To build from a directory other than the sample or application directory, run the west build command with an additional parameter directory_name, specifying the sample or application directory.

    See Board names for more information on the development boards. To reuse an existing build directory for building another sample or application for another board, pass -p=auto to west build.

    If you want to configure your application, run the following west command:

    west build -t menuconfig
    

    See Configuring your application for additional information about configuring an application.

    After running the west build command, the build files can be found in build/zephyr. For more information on the contents of the build directory, see the Build Directory Contents section in the Zephyr documentation on Building an Application.

    Important

    If you are working with an nRF9160 DK, make sure to select the correct controller before you program the application to your board.

    Put the SW5 switch (marked debug/prog) in the NRF91 position to program the main controller, or in the NRF52 position to program the board controller. See the Device programming section in the nRF9160 DK User Guide for more information.

  4. Connect the development board to your PC using a USB cable.

  5. Power on the development board.

  6. Program the sample or application to the board using the following command:

    west flash
    

    To fully erase the board before programming the new sample or application, use the command:

    west flash --erase
    

    The west flash command automatically resets the board and starts the sample or application.

For more information on building and programming using the command line, see the Zephyr documentation on Building, Flashing and Debugging.

Board names

You can find the board names for the different development boards in the Supported Boards section in the Zephyr documentation. For your convenience, the following table lists the board names for Nordic Semiconductor’s development kits.

Development kits

Board names

nRF51 DK board (PCA10028)

nrf51_pca10028

nRF52 DK board (PCA10040)

nrf52_pca10040

nRF52840 DK board (PCA10056)

nrf52840_pca10056

nRF5340 PDK board (PCA10095)

nrf5340_dk_nrf5340_cpunet (for the network sample)

nrf5340_dk_nrf5340_cpuapp (for the application sample)

nRF9160 DK board (PCA10090)

nrf9160_pca10090 (for the secure version)

nrf9160_pca10090ns (for the non-secure version)