The NFC Reader Library is a complete software support library for NFC Frontend ICs. Designed to give developers a faster and simpler way to deliver NFC-enabled products. This multi-layer library, written in C, makes it easy to create NFC based applications.
The NFC Reader Library includes a package for K82F. This package can be download from this page. The version used is 05.22.01 - NFC Reader Library for FRDM F82K
HW Changes
The CLEV6630B board has the CLRC663 connected with LPC1760 MCU via SPI. The design of the CLEV6630B makes it very easy to use another MCU, which is what we need to do.
To have direct access from FRDM_K64F to CLRC663, this change is needed: the six resistors marked by red squares need to be removed to obtain proper decoupling of the LPC1769 MCU from the CLEV6630B board.

Connecting FRDM_K64F to CLEV6630B
These are the connections required for this porting:
| FRDM_K64F pin | Connection | CLEV6630B pin |
|---|
| J2-8 / PTD2 | MOSI | MOSI |
| J2-10 / PTD3 | MISO | MISO |
| J2-12 / PTD1 | SCK | SCK |
| J2-6 / PTD0 | SSEL | SSEL |
| J1-2 / PTC16 | IFSEL0 | IF0 |
| J1-4 / PTC17 | IFSEL1 | IF1 |
| J1-11 / PTC0 | IRQ | IRQ |
| J1-5 / PTC1 | RESET | CLRC_NRST |
| J2-14 / GND | GND | GND |

Import into MCUXpresso
- In the Quickstart Panel, click on Import project(s) from file system…
- Browse the project archive (zip) from your file system.

- Click Next to select the projects needed (In this example, is just imported the Basic Discovery Loop example).

- Click on Finish to import the selected ones.
The imported projects will appear in the Project Explorer of the workspace.

SW Changes (FRDM_K64F)
Download and install the K64F SDK from the SDK Builder.
Import the hello_world_demo_apps example
- Click on Import SDK example(s)...
- Select the frdmk64f.



Over this project we are going to apply the changes

Add the source code Basic Discovery Loop Example
Copy the NfcrdlibEx1_BasicDiscoveryLoop.c to our K64 project.


Also copy from the src folder the phApp_Init.c file from NfcrdlibEx1_BasicDiscoveryLoop to frdm_k64f_basic_discovery_loop source folder.
Link the NFC Reader Library
We add the DAL, NxpNfcRdLib, phOsal and intfs folders from NfcrdlibEx1_BasicDiscoveryLoop project to thefrdm_k64f_basic_discovery_loop project.
- Right click on the frdm_k64f_basic_discovery_loop project, click on New>Folder:
- Click on Advanced, and select Link to alternate location (Link Folder).

- Click on Browse… browse to your workspace and choose the NxpNfcRdLib folder.

The same procedure has to be done with the DAL, phOsal and intfs folders.
The project should appear with the following structure:

Define FRDM_K64F SDK preprocessor symbols
We need to change the compiler preprocessor configuration.
- Right click on the frdm_k64f_basic_discovery_loop Project.
- Click on Properties..
- Go to C/C++ Build>Settings>Tool Settings>MCU C Compiler>Preprocessor
The actual symbols are related with the board, but we need to add the related with the Reader Library.

- These are the symbols we need to add:
- PHDRIVER_FRDM_K64FRC663_BOARD
- PH_OSAL_NULLOS
- NXPBUILD_CUSTOMER_HEADER_INCLUDED
- Then click on Apply and Close, and Yes.

Add include paths
After that we add the paths of the folders we recently linked:
- Right click on the frdm_k64f_basic_discovery_loop Project.
- Click on Properties..
- Go to C/C++ Build>Settings>Tool Settings>MCU C Compiler>Includes

The Include paths should be listed like this:

Add folder to Source Location
Then we add the root folder to the Path and Symbols:
- Right click on the frdm_k64f_basic_discovery_loop Project.
- Click on Properties..
- Go to C/C++ General>Path and Symbols>Source Location

Files Modifications
phDriver_KinetisSDK.c
We need to change some lines in the DAL>KinetisSDK>phDriver_KinetisSDK.c file:

GPIO_PortClearInterruptFlags((GPIO_Type *)pGpiosBaseAddr[bPortGpio], bPinNum);

bValue = (uint8_t)((GPIO_PortGetInterruptFlags((GPIO_Type *)pGpiosBaseAddr[bGpioNum]) >> bPinNum) & 0x01);
bValue = (uint8_t)GPIO_PinRead((GPIO_Type *)pGpiosBaseAddr[bGpioNum], bPinNum);

GPIO_PinWrite((GPIO_Type *)pGpiosBaseAddr[bGpioNum], bPinNum, bValue);

GPIO_PortClearInterruptFlags((GPIO_Type *)pGpiosBaseAddr[bGpioNum], (1<<bPinNum));
These changes are related to the names of the functions in our SDK version (2.7.0).
We can erase the Linux, LPCOpen and PN74xxxx folders, we don’t need them for this migration. frdm_k64f_basic_discovery_loop>DAL>src

Also, to avoid multiple definitions issues, we erase the phOsal>src>NullOS>portalble>psOsal_Port_CM3.c file.

Board_FRDM_K64FRc663.h
The architecture of the NFC Reader Library makes it very simple to be able to use other MCU’s, since you only need to adapt the configuration of the peripheral drivers. To do this, there are some changes required in the DAL (Driver Abstraction Layer) of the Reader Library.
In frdm_k64f_basic_discovery_loop>DAL>boards folder, are some header files with the information of different MCU’s and Readers. We need to add our header file: Board_FRDM_K64FRc663.h
We can copy the Board_FRDM_K82FRc663.h, rename and make the needed modifications.




BoardSelection.h
Then we add the K64 option to the BoardSelection.h header.

#ifdef PHDRIVER_FRDM_K64FRC663_BOARD
# include <Board_FRDM_K64FRc663.h>
#endif
ph_NxpBuild_App.h

#if defined(PHDRIVER_LPC1769RC663_BOARD) \
|| defined(PHDRIVER_FRDM_K82FRC663_BOARD) \
|| defined(PHDRIVER_FRDM_K64FRC663_BOARD)
# define NXPBUILD__PHHAL_HW_RC663
#endif
phApp_Init.h

#if defined(PHDRIVER_FRDM_K64FRC663_BOARD)
#define PHDRIVER_KINETIS_K64
#endif

#ifdef PHDRIVER_KINETIS_K64
# include <fsl_debug_console.h>
# include <stdio.h>
#endif
#ifdef DEBUG
#if defined(PHDRIVER_KINETIS_K82) || defined (PHDRIVER_KINETIS_K64)
#if SDK_DEBUGCONSOLE==1
#define DEBUG_PRINTF DbgConsole_Printf
#else
#define DEBUG_PRINTF(...) printf(__VA_ARGS__);
#endif
#else
#include <stdio.h>
#define DEBUG_PRINTF(...) printf(__VA_ARGS__); fflush(stdout)
#endif
#else
#define DEBUG_PRINTF(...)
#endif
phApp_Init.c
Also we to add the FRDM_K64F CPU initialization in phApp_Init.c:

#ifdef PHDRIVER_KINETIS_K64
#include <fsl_port.h>
#include <fsl_pit.h>
#ifdef DEBUG
#include <fsl_clock.h>
#endif
#endif

#ifdef PHDRIVER_KINETIS_K64
static void phApp_K64_Init(void);
#endif

#ifdef PHDRIVER_KINETIS_K64
static void phApp_K64_Init(void)
{
pit_config_t pitConfig;
BOARD_BootClockRUN();
SystemCoreClockUpdate();
PIT_GetDefaultConfig(&pitConfig);
PIT_Init(PIT, &pitConfig);
BOARD_InitPins();
}
#endif

#elif defined(PHDRIVER_KINETIS_K64)
phApp_K64_Init();
K64 Drivers
The hello_world example does not use SPI and PIT drivers, we need to add these drivers to our project:
- Right click on the frdm_k64f_basic_discovery_loop Project.
- Click on SDK Management>Manage SDK Components

- And we add the dspi and pit drivers:

Demonstration
With all these changes, now we can run the Basic Discovery Loop with the FRDM_K64F and the CLRC663.

