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.

    If you have installed the nRF Connect SDK using the Toolchain manager, click Open IDE next to the version you installed to start SES. If you have installed SES manually, run 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.

    If you have installed the nRF Connect SDK using the Toolchain manager, click the down arrow next to the version you installed and select Open bash.

  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

The following tables lists all boards and build targets for Nordic Semiconductor’s hardware platforms.

Boards included in sdk-zephyr

The following boards are defined in the zephyr/boards/arm/ folder. Also see the Supported Boards section in the Zephyr documentation.

Hardware platform

PCA number

Board name

Build target

nRF52 DK (nRF52832)

PCA10040

nrf52dk_nrf52832

nrf52dk_nrf52832

nrf52dk_nrf52810

nrf52dk_nrf52810

nRF52833 DK

PCA10100

nrf52833dk_nrf52833

nrf52833dk_nrf52833

nrf52833dk_nrf52820

nrf52833dk_nrf52820

nRF52840 DK

PCA10056

nrf52840dk_nrf52840

nrf52840dk_nrf52840

nrf52840dk_nrf52811

nrf52840dk_nrf52811

nRF52840 Dongle

PCA10059

nrf52840dongle_nrf52840

nrf52840dongle_nrf52840

Thingy:52

PCA20020

thingy52_nrf52832

thingy52_nrf52832

nRF5340 PDK

PCA10095

nrf5340pdk_nrf5340

nrf5340pdk_nrf5340_cpunet

nrf5340pdk_nrf5340_cpuapp

nrf5340pdk_nrf5340_cpuappns

nRF9160 DK

PCA10090

nrf9160dk_nrf9160

nrf9160dk_nrf9160

nrf9160dk_nrf9160ns

nrf9160dk_nrf52840

nrf9160dk_nrf52840

Boards included in sdk-nrf

The following boards are defined in the nrf/boards/arm/ folder.

Hardware platform

PCA number

Board name

Build target

nRF Desktop Gaming Mouse

PCA20041

nrf52840gmouse_nrf52840

nrf52840gmouse_nrf52840

nRF Desktop Mouse

PCA20044

nrf52dmouse_nrf52832

nrf52dmouse_nrf52832

nRF Desktop Mouse

PCA20045

nrf52810dmouse_nrf52810

nrf52810dmouse_nrf52810

nRF Desktop Keyboard

PCA20037

nrf52kbd_nrf52832

nrf52kbd_nrf52832

nRF Desktop Dongle

PCA10111

nrf52833dongle_nrf52833

nrf52833dongle_nrf52833

nRF Desktop Dongle

PCA10114

nrf52820dongle_nrf52820

nrf52820dongle_nrf52820

Thingy:91

PCA20035

thingy91_nrf9160

thingy91_nrf9160

thingy91_nrf9160ns

thingy91_nrf52840

thingy91_nrf52840