Integrating NFC Reader Library in a KW3x Bluetooth Low Energy application

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Integrating NFC Reader Library in a KW3x Bluetooth Low Energy application

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:  nxp.com/pages/:NFC-READER-LIBRARY
- NCF3320: nxp.com/products/:NCx3320 
- CLRC663 plus: nxp.com/products/:CLRC66303HN
- FRDM-KW36 board: nxp.com/demoboard/FRDM-KW36
- KW35/KW36 SDK: https://mcuxpresso.nxp.com/en/select
- MCUXpresso IDE: nxp.com/products/: 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:

ovidiu_usturoi_0-1634544489146.png

 

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: https://www.nxp.com/products/wireless/bluetooth-low-energy:BLUETOOTH-LOW-ENERGY-BLE.

 

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: www.nxp.com/pages/:NFC-READER-LIBRARY.


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;

ovidiu_usturoi_1-1634544515364.png

 

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: www.nxp.com/products/: MCUXpresso-IDE.
- Install the IDE;

ovidiu_usturoi_2-1634544533444.png

 

 

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

- Go to NXP NFC Reader Library webpage (www.nxp.com/pages/:NFC-READER-LIBRARY)
- Go to the Downloads tab and click on the download button
- Download the NFC Reader Library for Kinetis K82F package:

ovidiu_usturoi_3-1634544544130.png

 

 

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

- Navigate to https://mcuxpresso.nxp.com/en/select 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:

ovidiu_usturoi_4-1634544557889.png

 

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;

ovidiu_usturoi_5-1634544569351.png

 

- Import Wireless_Uart Example to the current workspace:

ovidiu_usturoi_6-1634544577143.png

 

 

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:

ovidiu_usturoi_7-1634544586677.png

 

- 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:

ovidiu_usturoi_8-1634544596418.png

 

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

 

#ifdef PHDRIVER_FRDM_KW36FRC663_BOARD
#include <Board_FRDM_KW36FRc663.h>
#endif

 

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

ovidiu_usturoi_9-1634544611347.png

 

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

ovidiu_usturoi_10-1634544620640.png

 

- phbalReg_KinetisSpi.c:

ovidiu_usturoi_11-1634544629359.png

 

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

ovidiu_usturoi_12-1634544639188.png

 

 

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:

ovidiu_usturoi_13-1634544648316.png

 

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

ovidiu_usturoi_14-1634544656960.png

 

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

ovidiu_usturoi_15-1634544667149.png

 

- 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:

ovidiu_usturoi_16-1634544677214.png

 

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

 

ovidiu_usturoi_17-1634544685939.png

 

- 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, frdmkw36_w_uart_ncf3320_basic_discovery.zip file, to the MCUXpresso workspace:

ovidiu_usturoi_18-1634544695541.png

 

ovidiu_usturoi_19-1634544706596.png

 

 

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:

ovidiu_usturoi_20-1634544719550.png

 

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

ovidiu_usturoi_21-1634544726419.png

 

 

- 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:

(https://www.youtube.com/watch?v=wCCz5zDIwHE&feature=youtu.be)

 

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).

Attachments
No ratings
Version history
Last update:
‎10-18-2021 01:13 AM
Updated by: