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
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.
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 |
The imported projects will appear in the Project Explorer of the workspace.
Download and install the K64F SDK from the SDK Builder.
Import the hello_world example and click on Finish.
Then we rename the project to frdm_k64f_basic_discovery_loop.
Over this project we are going to apply the changes
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.
We add the DAL, NxpNfcRdLib, phOsal and intfs folders from NfcrdlibEx1_BasicDiscoveryLoop project to thefrdm_k64f_basic_discovery_loop project.
The same procedure has to be done with the DAL, phOsal and intfs folders.
The project should appear with the following structure:
We need to change the compiler preprocessor configuration.
The actual symbols are related with the board, but we need to add the related with the Reader Library.
After that we add the paths of the folders we recently linked:
The Include paths should be listed like this:
Then we add the root folder to the Path and Symbols:
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.
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.
Then we add the K64 option to the BoardSelection.h header.
#ifdef PHDRIVER_FRDM_K64FRC663_BOARD
# include <Board_FRDM_K64FRc663.h>
#endif
#if defined(PHDRIVER_LPC1769RC663_BOARD) \
|| defined(PHDRIVER_FRDM_K82FRC663_BOARD) \
|| defined(PHDRIVER_FRDM_K64FRC663_BOARD)
# define NXPBUILD__PHHAL_HW_RC663
#endif
/* Check for K64 controller based boards. */
#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 /* PHDRIVER_KINETIS_K82 */
#include <stdio.h>
#define DEBUG_PRINTF(...) printf(__VA_ARGS__); fflush(stdout)
#endif /* PHDRIVER_KINETIS_K82 */
#else /* DEBUG */
#define DEBUG_PRINTF(...)
#endif /* DEBUG */
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 /* PHDRIVER_KINETIS_K64 */
#ifdef PHDRIVER_KINETIS_K64
static void phApp_K64_Init(void);
#endif /* PHDRIVER_KINETIS_K64 */
#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 /* PHDRIVER_KINETIS_K64 */
#elif defined(PHDRIVER_KINETIS_K64)
phApp_K64_Init();
The hello_world example does not use SPI and PIT drivers, we need to add these drivers to our project:
With all these changes, now we can run the Basic Discovery Loop with the FRDM_K64F and the CLRC663.