NFC: System OFF
The NFC System OFF sample shows how to make the NFC Tag device wake up from the System OFF mode when it detects the NFC field. The sample uses the NFC Data Exchange Format (NDEF).
Requirements
The sample supports the following development kits:
Hardware platforms |
PCA |
Board name |
Board target |
---|---|---|---|
PCA10156 |
|
||
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 a smartphone or tablet with the NFC feature.
Overview
The sample starts with the initialization of the NFC Tag device. The device then attempts to detect an external NFC field. If the field is not detected within three seconds, the device goes into the System OFF mode.
The device wakes up from the System OFF mode when an NFC field is detected. The system is started and the NFC Tag device is reinitialized. The tag can be read afterwards.
When the NFC field is not within range anymore, the device goes back to the System OFF mode.
You do not necessarily need a fully working NFC Tag for the wake-up. You can use the NFCT peripheral registers directly. In this case, the reader cannot read anything, but it can wake up the system.
When using the registers to wake up the device, replace start_nfc()
with the following function:
void field_sens_start(void)
{
int key = irq_lock();
/* First check if NFCT is not already sensing. */
if ((NRF_NFCT->NFCTAGSTATE & NFCT_NFCTAGSTATE_NFCTAGSTATE_Msk)
== NFCT_NFCTAGSTATE_NFCTAGSTATE_Disabled) {
NRF_NFCT->TASKS_SENSE = 1;
}
irq_unlock(key);
}
See the System OFF mode page in the nRF52840 Product Specification for more information.
User interface
- LED 1:
Lit when an NFC field is present within range.
- LED 2:
Lit when the system is on.
- LED 0:
Lit when an NFC field is present within range.
- LED 1:
Lit when the system is on.
Building and running
This sample can be found under samples/nfc/system_off
in the nRF Connect SDK folder structure.
When built as firmware image for a board target with the */ns
variant, the sample has Cortex-M Security Extensions (CMSE) enabled and separates the firmware between Non-Secure Processing Environment (NSPE) and Secure Processing Environment (SPE).
Because of this, it automatically includes the Trusted Firmware-M (TF-M).
To read more about CMSE, see Processing environments.
To build the sample, follow the instructions in Configuring and 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:
Observe that LED 2 on the Tag device turns off three seconds after the programming has completed. This indicates that the system is in the System OFF mode.
Make sure that the NFC feature is activated on the smartphone or tablet. Check the device documentation on how to enable the NFC feature.
With the smartphone or tablet, touch the NFC antenna of the NFC Tag device.
Observe that LED 2 on the Tag device is lit, followed by LED 1 shortly after that. Also a “Hello World!” notification appears on the smartphone or tablet. The notification text is obtained from NFC.
Move the smartphone or tablet away from the NFC antenna. LED 1 turns off.
Observe that LED 2 on the Tag device turns off after three seconds. This indicates that system is in the System OFF mode again.
Observe that LED 1 on the Tag device turns off three seconds after the programming has completed. This indicates that the system is in the System OFF mode.
Make sure that the NFC feature is activated on the smartphone or tablet. Check the device documentation on how to enable the NFC feature.
With the smartphone or tablet, touch the NFC antenna of the NFC Tag device.
Observe that LED 1 on the Tag device is lit, followed by LED 0 shortly after that. Also a “Hello World!” notification appears on the smartphone or tablet. The notification text is obtained from NFC.
Move the smartphone or tablet away from the NFC antenna. LED 0 turns off.
Observe that LED 1 on the Tag device turns off after three seconds. This indicates that system is in the System OFF mode again.
Dependencies
This sample uses the following nRF Connect SDK libraries:
In addition, it uses the Type 2 Tag library from sdk-nrfxlib:
The sample uses the following Zephyr libraries:
include/zephyr.h
include/device.h
include/power/power.h
The sample also uses the following secure firmware component: