Integrating NFC Reader Library in a KW3x Bluetooth Low Energy application

Showing results for 
Search instead for 
Did you mean: 

Integrating NFC Reader Library in a KW3x Bluetooth Low Energy application

No ratings

Integrating NFC Reader Library in a KW3x Bluetooth Low Energy application

1.    Introduction


1.1 Document Purpose

This post entry provides a detailed description of how to integrate the NFC Reader Library to a KW3x Bluetooth Low Energy application.


1.2 Audience

The goal of this post is to serve as a guide for software developers who want to use, adapt and integrate the NFC Reader Library to an SDK wireless connectivity example.


1.3 References and Resources

- NFC Reader Library:
- NCF3320: 
- CLRC663 plus:
- FRDM-KW36 board:
- KW35/KW36 SDK:
- MCUXpresso IDE: MCUXpresso-IDE


2. NFC Reader Library Overview


The NXP NFC Reader Library is a modular software library written in C language, which provides an API that enables customers to create their own software stack and applications for the NXP contactless reader ICs:
- PN512;
- CLRC633 family;
- PN7462 family;
- PN5180;
This API facilitates the most common operations required in NFC applications such as:
- reading or writing data into contactless cards or tags;
- exchanging data with other NFC-enabled devices;
- allowing NFC reader ICs to emulate cards.
The NFC Reader Library is designed in a way to be easily portable to many different microcontrollers with a multi-layered architecture:



As main blocks, we have:
- Application Layer (AL) - implements the command sets to interact with MIFARE cards and NFC tags.
- NFC activity - implements a configurable Discovery loop for the detection of contactless cards, NFC tags or other NFC devices.
- HCE and P2P components, for the emulation of Type 4 tags and P2P data exchange respectively.
- Protocol abstraction layer (PAL) - contains the RF protocol implementation of the ISO14443, Felica, vicinity and NFC standards.
- Hardware abstraction layer (HAL) - implements the drivers for controlling the NFC frontends RF interface and capabilities.
- Driver Abstraction Layer (DAL) - implements the GPIO pinning, the timer configuration and the physical interface (BAL) between the host MCU and the reader IC.
- OSAL module, in charge of abstracting the OS or RTOS specifics (tasks events, semaphores, and threads)


3. The KW3x Wireless Microcontroller Overview

The KW3x wireless microcontrollers (MCU are highly integrated single-chip devices that enable Bluetooth Low Energy (Bluetooth LE) and Generic FSK connectivity for automotive, industrial and medical/healthcare embedded systems.


The KW36/35 Wireless MCU integrates an Arm® Cortex®-M0+ CPU with up to 512 KB flash and 64 KB SRAM and a 2.4 GHz radio that supports Bluetooth LE 5.0 and Generic FSK modulations. The Bluetooth LE radio supports up to 8 simultaneous connections in any master/slave combination. The KW36A/36Z includes an integrated FlexCAN module enabling seamless integration into an automotive or industrial CAN communication network, enabling communication with external control and sensor monitoring devices over Bluetooth LE.


For more details please refer to the NXP website information:


4. NFC Reader Library – integration with FRDM-KW36

The current NFC Reader Library v5.21.01 is not containing support for Kinetis KW3x MCU. We will use a reference the K82 NFC Reader Library package:

The steps required to integrate the library are:
- Hardware preparation (the connection between FRDM-KW36 and NFC reader board);
- Setting up the development environment (SDK download, workspace);
- Preparing adaptation files for FRDM-KW3x board;
- Integrating NFC application to Wireless_UART Bluetooth LE example;
- Running the demo;


4.1 Hardware preparation

Hardware required:
- NCF3320 Antenna v1.0 board as an NFC transceiver;
- FRDM-KW36 board as host MCU, used to load and run the Bluetooth Low Energy Stack and NFC application logic;



The communication between the boards will be via the SPI communication using the following pin configuration:


Master board (FRDM-KW36)         Connects to            Slave board (NCF3320 Antenna v1.0)          


PTB0  (J2-pin10)                                      -                    IRQ

PTB1  (J2-pin9)                                         -                    Reset

PTA16 (J2-pin1 - SPI1_Sout)                   -                    MOSI

PTA17 (J1-pin5 - SPI1_Sin)                     -                    MISO

PTA18 (J1-pin7 - SPI1_SCK)                   -                    SCK

PTA19 (J2-pin3 - SPI1_CS)                     -                    CS

GND   (J3-pin7)                                        -                    GND



4.2 Setting up the development environment


Install MCUXpresso IDE (for this example we are using v10.2.0 build 759)


- Go to MCUXpresso-IDE webpage and download the latest version of IDE: MCUXpresso-IDE.
- Install the IDE;




Get the latest NFC Reader Library release (for this example we are using v5.21.00)

- Go to NXP NFC Reader Library webpage (
- Go to the Downloads tab and click on the download button
- Download the NFC Reader Library for Kinetis K82F package:




Generate a downloadable SDK package for FRDM-KW36 board (SDK_2.2.1_FRDM-KW36)

- Navigate to and select FRDM-KW36 board;
- Select Build MCUXpresso SDK.
- As toolchain, please make sure that the MCUXpresso IDE is selected.
- Use Download SDK button to start downloading SDK package:



Create MCUXpresso workspace

- Open MCUXpresso IDE and create a workspace;
- Drag and drop the SDK_2.2.1_FRDM-KW36 into the installed SDKs tab of the MCUXpresso IDE;



- Import Wireless_Uart Example to the current workspace:




4.3 Preparing adaptation files for FRDM-KW3x board

This chapter describes the Driver Abstraction Layer (DAL) changes required for FRDM-KW36:
- unzip the NFC Reader Library and navigate to boards folder:



- Create an equivalent file for FRDM-KW36 (Board_FRDM_KW36FRc663.h) by setting the right configuration for GPIOs and handlers;
- Below are the differences required for FRDM-KW36 board in comparation with a FRDM-K82F board:



- Add the FRMD-KW36 to …DAL\cfg\BoardSelection.h file:


#include <Board_FRDM_KW36FRc663.h>


- In KinetisSDK folder, update the following dependencies:
o PIT Driver IRQ name:



o Open drain and pin lock configuration:
- phDriver_KinetisSDK.c:



- phbalReg_KinetisSpi.c:



- add PHDRIVER_FRDM_KW36FRC663_BOARD define to …\NxpNfcRdLib\types\ph_NxpBuild_Platform.h file to enable the right NFC transceiver:




4.4  Integrating NFC application to Wireless_UART Bluetooth LE example

In this chapter we will integrate the BasicDiscoveryLoop NFC example to Wireless_UART Bluetooth LE application.
For this, the following steps are required:
- On the wireless_uart project location create an “nfc” folder:



- Copy from modified NFC Reader Library the DAL, NxpNfcRdLib and phOsal folders:



- On the wireless_uart project location, “source” folder create a new “nfc” subfolder to integrate the BasicDiscovery loop files:



- Some changes will be required on the BasicDiscoveryLoop files:
o Main function renamed to NFC_BasicDiscoveryLoop_Start;
o Removed drivers/OS initialization;
(all the changes can be observed in the attachment)
- Update MCUXpresso workspace by pressing F5 to see the latest changes:



- Update the linker information (Project Properties -> C/C++ Build -> Settings) and preprocessor defines (Project Properties -> C/C++ Build -> Preprocessor):




- Add dependencies:
o PIT module/ PIT module initialization;
o Update LED, SW configuration;
o Increase heap size (gTotalHeapSize_c);
o Add functionality for NFC in wireless_uart.c application;
(all the changes can be observed in the attachment);


Considering the attached ZIP archive, we can be easily dragged and drop, file, to the MCUXpresso workspace:






4.5 Running the demo

- Create hardware connection based on chapter 4.1;
- Open a serial terminal on the corresponding COM port for FRDM-KW36 board. The BaudRate used is 115200.
- Press SW2 on FRDM-KW36 to start advertising.

- Open Mobile APP - IOT toolbox - Wirreless UART.  The FDRM-KW36 board will be listed as NXP_WU:



- Create Bluetooth LE connection. The serial log will contain the log for Bluetooth LE operations:




- Use NFC Cards close to NCF3320 Antenna v1.0 board to initiate discovery demo.
- Once the card is detected, an event is sent to the mobile application including technology and UUID of the card:



This video is currently being processed. Please try again in a few minutes.
(view in My Videos)


Attached is the source code for this example application (frdmkw36_w_uart_ncf3320_basic_discovery).

Version history
Revision #:
2 of 2
Last update:
‎10-18-2021 01:13 AM
Updated by: