NFC: Shell
This sample demonstrates the NFC transport feature for a shell interface. It runs the shell interface with the NFC T4T ISO-DEP transport layer. It uses the NFC shell transport library.
Requirements
The sample supports the following development kits:
Hardware platforms |
PCA |
Board name |
Board target |
---|---|---|---|
PCA10156 |
|
||
nRF54L15 DK |
PCA10156 |
|
|
PCA10175 |
|
||
PCA10095 |
|
||
PCA10040 |
|
||
PCA10056 |
|
When built for a board target with the */ns
variant, the sample is configured to compile and run as a non-secure application with Cortex-M Security Extensions enabled.
Therefore, it automatically includes Trusted Firmware-M that prepares the required peripherals and secure services to be available for the application.
The sample also requires the polling device with support for raw ISO-DEP (ISO14443-4A) protocol. The polling device must follow data exchange mechanism described in the NFC shell transport library.
Overview
This sample presents one of possible ways to run shell through the NFC T4T transport layer. This is not a common use case for NFC as an NFC tag is a passive device. However, this feature can be useful, for example, for devices provisioning on the production line. This sample runs a shell over the NFC transport and implements two shell commands that control the LED.
You can use the following commands:
The
led on
command lits LED 2.The
led off
command dims LED 2.
The
led on
command lits LED 1.The
led off
command dims LED 1.
User interface
- LED 1:
Blinks, toggling on/off every second, when the main loop is running.
- LED 2:
Lits or dims when user issues the shell commands that control the LED.
- LED 0:
Blinks, toggling on/off every second, when the main loop is running.
- LED 1:
Lits or dims when user issues the shell commands that control the LED.
Building and running
This sample can be found under samples/nfc/shell
in the nRF Connect SDK folder structure.
To build the sample, follow the instructions in Building an application for your preferred building environment. See also Programming an application for programming steps and Testing and optimization for general information about testing and debugging in the nRF Connect SDK.
Note
When building repository applications in the SDK repositories, building with sysbuild is enabled by default.
If you work with out-of-tree freestanding applications, you need to manually pass the --sysbuild
parameter to every build command or configure west to always use it.
Note
Programming the nRF54H20 SoC can sometimes fail due to conflicts in the resource configuration. This can happen if, for example, an application programmed to the nRF54H20 SoC configured the UICRs for one or more cores in a way that is incompatible with the configuration required by the application you are trying to program on the SoC.
To fix this error and erase the UICR for the application core, run the following command:
nrfutil device recover --core Application
If your sample also uses the radio core, you must also erase the UICRs for the radio core. To erase the UICR for the radio core, run the following command:
nrfutil device recover --core Network
For more information on the command, run:
nrfutil device recover --help
You can then run west flash
to program your application.
Note
If you are using debug messages in the NFCT driver, the driver might not be working properly if you have CONFIG_LOG_MODE_IMMEDIATE
enabled.
The NFCT driver is part of the nrfx driver package.
For more information about this driver, see the NFCT driver page in the nrfx repository.
Testing
After programming the sample to your development kit, complete the following steps to test it:
Open a serial port connection to the kit using a terminal emulator that supports VT100/ANSI escape characters (for example, nRF Connect Serial Terminal). See Testing and optimization for the required settings and steps.
Reset your development kit.
Observe that the sample starts.
Touch the NFC antenna with the polling device.
Observe that the shell prompt appears on the terminal.
Keep the NFC antenna in the polling device field range.
Issue the
led on
command through the terminal.Observe that the LED 2 lits.
Issue the
led off
command through the terminal.Observe that the LED 2 dims.
You can play with other build-in shell commands.
Open a serial port connection to the kit using a terminal emulator that supports VT100/ANSI escape characters (for example, nRF Connect Serial Terminal). See Testing and optimization for the required settings and steps.
Reset your development kit.
Observe that the sample starts.
Touch the NFC antenna with the polling device.
Observe that the shell prompt appears on the terminal.
Keep the NFC antenna in the polling device field range.
Issue the
led on
command through the terminal.Observe that the LED 1 lits.
Issue the
led off
command through the terminal.Observe that the LED 1 dims.
You can play with other build-in shell commands.
Dependencies
This sample uses the following nRF Connect SDK libraries:
It uses the following Zephyr libraries:
include/zephyr/kernel.h
zephyr/shell/shell.h