Exercise 2 – Build and flash your first nRF Connect SDK application
Build and flash your first nRF Connect SDK application
In this exercise, we will program a simple application based on the blinky sample to toggle an LED on our board. Again, any supported Nordic Semiconductor development board will work (nRF54, nRF53, nRF52, nRF70, or nRF91 Series). The idea is to make sure that all the tools needed to build and flash a sample are set up correctly. The focus is to learn how to create an application from a template “Copy a sample”, build the application, and flash it on a Nordic-powered board.
Basically, we will walk you through the three bullet points below:
Create a new application based on a template(sample).
Build an application.
Flash an application to a board.
Exercise steps
1. Create a folder close to your root directory. This will hold all the exercises that we will be working on throughout this course.
We will create that folder on the C drive in C:\myfw\ncsfund. Avoid storing your applications in locations with long paths, as the build system might fail on some operating systems (Windows) if the application path is too long. Also, avoid using whitespaces and special characters in the path.
2. In VS Code, click on the nRF Connect Extension icon. In the WELCOME View, click on Create a new application.
3. In the Create new application, select Copy a sample . Then select the SDK version you plan to use.
In the Create new application, you will be presented with three options: Create a blank application , which will create a blank application with an empty main() function. While the Copy a sample will present you all the templates “samples” that come from the different modules in nRF Connect SDK and enable you to create an application based on a template. Note that if you have multiple SDK versions installed on your machine, you will be prompted to select which SDK version to copy a sample from. The Browse nRF Connect SDK Add-on index (out of scope for this course) is to copy a revision of an existing out-of-tree application compatible with the nRF Connect SDK from the online application index and set up a west workspace repository around it.
Definition
The SDK contains a rich set of templates. In the context of templates:
Samples are simple and showcase a single feature or library (e.g. SHA256 sample, UART sample, PWM sample, blinky sample, etc..)
Applications are complex and include a variety of libraries to implement a specific use case (e.g. Asset tracker application, Keyboard application, Mouse application).
3.1 Type blinky in the search field and select the second Blinky sample (with the path zephyr/samples/basic/blinky) like below.
The Blinky sample blinks LED1 (LED0 on nRF54 DKs) on your board indefinitely.
nRF Connect for VS Code: Create a New Application from Sample – Select Template
We will base our first application on the Blinky sample. The Blinky sample comes from the Zephyr module in nRF Connect SDK, which is why you see the zephyr name in the sample path: zephyr\samples\basic\blinky .
Through the icons , we can access the in-tree sample (inside the SDK installation directory), online documentation of the sample, and the GitHub of the sample, respectively.
Through the icons , we can filter samples/applications based on the module they come from (nrf, zephyr ,etc..) and supported hardware. Note that the supported hardware is not always accurate as it relies on samples explicitly listing the supported hardware, which is not the case for all samples.
3.2 Input the full path for where you want the application to be stored.
1. Select where you want to store your application. Input the directory you created in step 1 (for example: C:\myfw\ncsfund\).
2. Name your application l1_e2. This is the naming convention we will use for exercises throughout this course. Note that this will create a folder for your application called l1_e2.
When you have input the full path, press enter.
VS Code will ask if you want to open the application in the same VS Code instance or open a new VS Code instance. Select Open to open the application in the same VS Code instance.
This will make a copy of the template selected “Blinky sample”, store it in the application directory you specified, and add an unbuilt application to VS Code as shown below:
Note
nRF Connect for VS Code might show error squiggles indicating header files not found for an unbuilt application. These usually appear in the PROBLEMS tab. Please ignore these error squiggles at this stage. These errors will automatically be resolved once you add and build a configuration (next step).
4. Add a build configuration.
One of the many advantages of the nRF Connect SDK is the high decoupling between the application source code and the software configuration/hardware description, making it extremely easy to switch the build for a new hardware or software configuration.
This step will specify which development board or custom board (hardware) we want to build the application for. We will also select the software configuration (*.conf and possible devicetree overlays) to be used in the build.
What you set in the Add Build configuration controls what is passed to the underlying command-line tool, west.
In the APPLICATIONS view, click on Add Build Configuration under the application name.
This will open the Add Build Configuration window shown below:
The first thing to notice is that the GUI will inform you about the SDK/toolchain version that will be used to build the application. Ensure it corresponds to the SDK/toolchain you intend to use, along with the SDK version from which you copied the sample from. If it doesn’t, click the arrow to select the correct version.
4.1. Using the Board target, choose the board you want to flash your application to. See the table below for an overview of board targets for Nordic devices.
*The nRF54LM20 DK is supported in nRF Connect SDK v3.1.1 and higher.
*The nRF54LS05 DK is supported in nRF Connect SDK v3.3.0 preview2 and higher.
*The nRF54L15 DK and the Thingy:91 X are supported in nRF Connect SDK v2.8.0 and higher.
*The nRF7002 DK and nRF9161 DK are supported in nRF Connect SDK v2.5.0 and higher.
*The nRF9151 DK is supported in nRF Connect SDK v2.6.0 and higher.
In the screenshot, we chose the nRF54L15 DK by specifying its board target, nrf54l15dk/nrf54l15/cpuapp/ns
4.2. The board Revision is usually written on a sticker on the board with the format X.X.X. However, this field is optional and only applicable if the board has multiple revisions (like the nRF9160 DK). By setting it to blank, the build system selects the default version set in the board definition.
We will keep the default build configuration for the rest. However, it’s important to understand the role of each of these configurations.
4.3. The Base configuration files. Depending on the template you chose in Step 3, you will be presented with at least one base application configuration file prj.conf. Some templates contain more than one application configuration file (eg: prj.conf, prj_minimal.conf, prj_cdc.conf). These different configurations, if found in the template, are explained in the template documentation. The blinky template has only one option. This is equivalent to FILE_SUFFIX(and CONF_FILE) in west . prj.conf will be selected by default
4.4. The Extra Kconfig fragments field will list the Kconfig fragments available in the template or added to the application folder. These are modifiers to the application configuration file (covered in Lesson 3). The blinky template has none. This is equivalent to EXTRA_CONF_FILEin west .
4.5. TheBase Devicetree overlays field will list the Devicetree overlays that are available in the template or have been added to the application folder. These are modifiers to your hardware description (covered in Lesson 3). The blinky template has none. This is equivalent to DTC_OVERLAY_FILEin west .
4.6. The Extra Devicetree overlays. It provides additional, custom devicetree overlay files to be “mixed in” with the base devicetree overlay file This is equivalent to EXTRA_DTC_OVERLAY_FILEin west .
4.7 The Snippets. Snippets combine both software configuration (Kconfig) and hardware configuration (Devicetree) in one bundle. There are several snippets in the SDK.
4.8 Optimization level(size, speed, or debugging). We have four options here.
Use project default: Use the project default settings set in the application configuration file (prj.conf) , the application configuration file is covered in Lesson 3.
Optimize for debugging (-Og): This is important to set if you plan to debug your application and use the RTOS-aware debugger in nRF Connect for VS Code. Selecting this option in the GUI will pass the following Kconfig symbol to the build system CONFIG_DEBUG_OPTIMIZATIONS="y"
The Include debug thread information when checked will pass the CONFIG_DEBUG_THREAD_INFO to the build system. You can see thread information in the Debugger Thread Viewer, but only if you also select the Optimize for debugging(-Og) optimization level.
4.9. TheExtra CMake arguments field allows you to pass arguments to the build system if needed. We will leave that blank for this demo.
4.10 The Build directory name field gives you the option to manually name the build directory where the final binary files and temporary build files will be stored. We will leave this to be the default name specified by the tool, which is build or build_1 if you have already built one application before.
In this exercise, we will leave the option to Use project default. However, it’s important to remember to use Optimize for debugging (-Og) if you plan to debug your application.
Leave the Generate only option disabled to trigger the build process after clicking the Build Configuration button.
4.11 Starting from nRF Connect SDK v2.8.0, Sysbuild is enabled by default. Sysbuild is of importance when your application has multiple images. Leave this option to the default value of Build system default
4.12 Click the Generate and Build button to create the configuration and initiate the build process.
The build process will take some time to finish. Open the nRF Connect Terminal (View->Terminal) to see the progress of the build.
A successful build is indicated by displaying the application’s memory usage, as shown in the screenshot above.
More on this
A key component in the build process is west, which is a core command-line utility in nRF Connect SDK/Zephyr.
west provides several services like repository management, building applications, and flashing, and is internally invoked by nRF Connect for VS Code. You can also issue these commands manually in the command line prompt if you prefer to work in the terminal
Make sure to select nRF Connect Terminal, as shown in the screenshot below as this is the terminal where the toolchain is sourced. Step 1 – Open nRF Connect Terminal, Step 2 – Type west help if you are interested in learning how to use the command-line interface with the nRF Connect SDK.
Note that the nRF Connect Terminal will open for the active toolchain/SDK used to build the application. You can also open nRF Connect Terminal from the Manage toolchains -> Open Terminal Profile.
Alternatively, you can checkout this short video or read the documentation of west available here.
If you switch to the Explorer in VS Code or browse to the application directory, you will notice that there is a new sub-directory created from the build process called build . This folder contains the build output including the binary file that we will flash on the board in the next step.
5. Make sure that your development kit is connected to your computer and that it is switched on. It should be listed in the Connected Devices View in the nRF Connect for VS Code extension.
Important
If you are using a Thingy (Thingy:53, Thingy:91 X, or Thingy:91), they do not have an onboard debugger) so the flash procedure is different, and the device will not show up under Connected Devices View in the nRF Connect for VS Code extension. Skip steps 5 and 6, and please go through the flash procedure for the Thingy:53 here and for the Thingy:91 X or Thingy:91 here.
If you don’t see your board listed, press the Refresh Connected Devices icon in the Connected Devices View.
6. From the Actions View, click Flashto flash the application to the board. You can open the Terminal Panel to see the progress of the flashing, as shown below.
Note
The difference between Flash and Erase And Flash To Board is that the latter erases the whole device, including all data the application has saved.
For example, if the device is added to a mesh network, Erase And Flash To Board will make the device forget this.
LED1 (LED0 on nRF54 DKs) on your board should be blinking now in one second intervals.
Note
On the nRF54L Series DK, the board’s LEDs are labeled with PCB labels (PCB silkscreen) that start with 0 (LED0-LED3). In previous-generation development kits, the indexing starts with 1 (LED1-LED4). So, running the above sample on the nRF54L Series DK will make LED0 blink.
Note
If you have an nRF54LM20 DK revision <0.5.0, you will need to go to the Board Configurator application in nRF Connect for Desktop and set VDD_NRF and VDDIO to less than 2.7 V. LEDs on the DK stop functioning if the value for VDD_NRF and VDDIO is set to more than 2.7 V.
7. Just for the sake of this demonstration, let’s change the LED blink rate.
Locate the main.c file in Source Files->Applications or through the Explorer View of Visual Studio Code. On line 11, change the value of the SLEEP_TIME_MS from 1000 to 100. This will change the interval at which the LED is blinking.
Copy
#define SLEEP_TIME_MS 100
C
8. Rebuild and re-flash the application on your board. You should observe that the LED is now blinking at a higher frequency.
In Lesson 2, we will take an in-depth look at the source code of this application to understand how it works.
Nordic Developer Academy Privacy Policy
1. Introduction
In this Privacy Policy you will find information on Nordic Semiconductor ASA (“Nordic Semiconductor”) processes your personal data when you use the Nordic Developer Academy.
References to “we” and “us” in this document refers to Nordic Semiconductor.
2. Our processing of personal data when you use the Nordic Developer Academy
2.1 Nordic Developer Academy
Nordic Semiconductor processes personal data in order to provide you with the features and functionality of the Nordic Developer Academy. Creating a user account is optional, but required if you want to track you progress and view your completed courses and obtained certificates. If you choose to create a user account, we will process the following categories of personal data:
Email
Name
Password (encrypted)
Course progression (e.g. which course you have completely or partly completed)
Certificate information, which consists of name of completed course and the validity of the certificate
Course results
During your use of the Nordic Developer Academy, you may also be asked if you want to provide feedback. If you choose to respond to any such surveys, we will also process the personal data in your responses in that survey.
The legal basis for this processing is GDPR article 6 (1) b. The processing is necessary for Nordic Semiconductor to provide the Nordic Developer Academy under the Terms of Service.
2.2 Analytics
If you consent to analytics, Nordic Semiconductor will use Google Analytics to obtain statistics about how the Nordic Developer Academy is used. This includes collecting information on for example what pages are viewed, the duration of the visit, the way in which the pages are maneuvered, what links are clicked, technical information about your equipment. The information is used to learn how Nordic Developer Academy is used and how the user experience can be further developed.
2.2 Newsletter
You can consent to receive newsletters from Nordic from within the Nordic Developer Academy. How your personal data is processed when you sign up for our newsletters is described in the Nordic Semiconductor Privacy Policy.
3. Retention period
We will store your personal data for as long you use the Nordic Developer Academy. If our systems register that you have not used your account for 36 months, your account will be deleted.
4. Additional information
Additional information on how we process personal data can be found in the Nordic Semiconductor Privacy Policy and Cookie Policy.
Nordic Developer Academy Terms of Service
1. Introduction
These terms and conditions (“Terms of Use”) apply to the use of the Nordic Developer Academy, provided by Nordic Semiconductor ASA, org. nr. 966 011 726, a public limited liability company registered in Norway (“Nordic Semiconductor”).
Nordic Developer Academy allows the user to take technical courses related to Nordic Semiconductor products, software and services, and obtain a certificate certifying completion of these courses. By completing the registration process for the Nordic Developer Academy, you are agreeing to be bound by these Terms of Use.
These Terms of Use are applicable as long as you have a user account giving you access to Nordic Developer Academy.
2. Access to and use of Nordic Developer Academy
Upon acceptance of these Terms of Use you are granted a non-exclusive right of access to, and use of Nordic Developer Academy, as it is provided to you at any time. Nordic Semiconductor provides Nordic Developer Academy to you free of charge, subject to the provisions of these Terms of Use and the Nordic Developer Academy Privacy Policy.
To access select features of Nordic Developer Academy, you need to create a user account. You are solely responsible for the security associated with your user account, including always keeping your login details safe.
You will able to receive an electronic certificate from Nordic Developer Academy upon completion of courses. By issuing you such a certificate, Nordic Semiconductor certifies that you have completed the applicable course, but does not provide any further warrants or endorsements for any particular skills or professional qualifications.
Nordic Semiconductor will continuously develop Nordic Developer Academy with new features and functionality, but reserves the right to remove or alter any existing functions without notice.
3. Acceptable use
You undertake that you will use Nordic Developer Academy in accordance with applicable law and regulations, and in accordance with these Terms of Use. You must not modify, adapt, or hack Nordic Developer Academy or modify another website so as to falsely imply that it is associated with Nordic Developer Academy, Nordic Semiconductor, or any other Nordic Semiconductor product, software or service.
You agree not to reproduce, duplicate, copy, sell, resell or in any other way exploit any portion of Nordic Developer Academy, use of Nordic Developer Academy, or access to Nordic Developer Academy without the express written permission by Nordic Semiconductor. You must not upload, post, host, or transmit unsolicited email, SMS, or \”spam\” messages.
You are responsible for ensuring that the information you post and the content you share does not;
contain false, misleading or otherwise erroneous information
infringe someone else’s copyrights or other intellectual property rights
contain sensitive personal data or
contain information that might be received as offensive or insulting.
Such information may be removed without prior notice.
Nordic Semiconductor reserves the right to at any time determine whether a use of Nordic Developer Academy is in violation of its requirements for acceptable use.
Violation of the at any time applicable requirements for acceptable use may result in termination of your account. We will take reasonable steps to notify you and state the reason for termination in such cases.
4. Routines for planned maintenance
Certain types of maintenance may imply a stop or reduction in availability of Nordic Developer Academy. Nordic Semiconductor does not warrant any level of service availability but will provide its best effort to limit the impact of any planned maintenance on the availability of Nordic Developer Academy.
5. Intellectual property rights
Nordic Semiconductor retains all rights to all elements of Nordic Developer Academy. This includes, but is not limited to, the concept, design, trademarks, know-how, trade secrets, copyrights and all other intellectual property rights.
Nordic Semiconductor receives all rights to all content uploaded or created in Nordic Developer Academy. You do not receive any license or usage rights to Nordic Developer Academy beyond what is explicitly stated in this Agreement.
6. Liability and damages
Nothing within these Terms of Use is intended to limit your statutory data privacy rights as a data subject, as described in the Nordic Developer Academy Privacy Policy. You acknowledge that errors might occur from time to time and waive any right to claim for compensation as a result of errors in Nordic Developer Academy. When an error occurs, you shall notify Nordic Semiconductor of the error and provide a description of the error situation.
You agree to indemnify Nordic Semiconductor for any loss, including indirect loss, arising out of or in connection with your use of Nordic Developer Academy or violations of these Terms of Use. Nordic Semiconductor shall not be held liable for, and does not warrant that (i) Nordic Developer Academy will meet your specific requirements, (ii) Nordic Developer Academy will be uninterrupted, timely, secure, or error-free, (iii) the results that may be obtained from the use of Nordic Developer Academy will be accurate or reliable, (iv) the quality of any products, services, information, or other material purchased or obtained by you through Nordic Developer Academy will meet your expectations, or that (v) any errors in Nordic Developer Academy will be corrected.
You accept that this is a service provided to you without any payment and hence you accept that Nordic Semiconductor will not be held responsible, or liable, for any breaches of these Terms of Use or any loss connected to your use of Nordic Developer Academy. Unless otherwise follows from mandatory law, Nordic Semiconductor will not accept any such responsibility or liability.
7. Change of terms
Nordic Semiconductor may update and change the Terms of Use from time to time. Nordic Semiconductor will seek to notify you about significant changes before such changes come into force and give you a possibility to evaluate the effects of proposed changes. Continued use of Nordic Developer Academy after any such changes shall constitute your acceptance of such changes. You can review the current version of the Terms of Use at any time at https://academy.nordicsemi.com/terms-of-service/
8. Transfer of rights
Nordic Semiconductor is entitled to transfer its rights and obligation pursuant to these Terms of Use to a third party as part of a merger or acquisition process, or as a result of other organizational changes.
9. Third Party Services
To the extent Nordic Developer Academy facilitates access to services provided by a third party, you agree to comply with the terms governing such third party services. Nordic Semiconductor shall not be held liable for any errors, omissions, inaccuracies, etc. related to such third party services.
10. Dispute resolution
The Terms of Use and any other legally binding agreement between yourself and Nordic Semiconductor shall be subject to Norwegian law and Norwegian courts’ exclusive jurisdiction.
Switch language?
Progress is tracked separately for each language. Switching will continue from your progress in that language or start fresh if you haven't begun.
Your current progress is saved, and you can switch back anytime.
•Support for nRF54LS05 DK (Available through the early access sampling program) •Support for the nRF54LM20B with Axon NPU for Edge AI applications
Bluetooth LE updates
•Quality of Service module is now production-ready. •New experimental features for RF testing (Direct Test Mode) and low-latency packet handling (LE Flushable ACL).
MCUboot & Partition Manager
•Single-Slot DFU and RAM Load mode are both promoted to fully supported •Partition Manager is officially deprecated in favor of Zephyr's devicetree-based partitioning.
General updates
•Added comprehensive support for the nRF54L Series. •Bug fixes and improvements. •Hardware model v1, which was deprecated in nRF Connect SDK 2.7.0, has now been removed. •Multi-image builds functionality (parent-child images), which was deprecated in nRF Connect SDK v2.7.0 has now been removed.
Bluetooth LE updates
•Added support for Bluetooth Core version 6.2. •Added support for Bluetooth LE Shorter Connection Intervals. •Added support for Bluetooth LE Channel Sounding.
Bootloader updates
•Support for MCUboot image compression. •Single slot DFU support for the nRF54L Series. •Encrypted DFU support using ECIES on the nRF54L15, nRF54LM20, and nRF54LV10 SoCs.