NFC Reader Library Porting FRDM_K64F

Document created by Ricardo Zamora Employee on May 29, 2020Last modified by Ricardo Zamora Employee on May 29, 2020
Version 9Show Document
  • View in full screen mode

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 pinConnectionCLEV6630B pin
J2-8 / PTD2MOSIMOSI
J2-10 / PTD3MISOMISO
J2-12 / PTD1SCKSCK
J2-6 / PTD0SSELSSEL
J1-2 / PTC16IFSEL0IF0
J1-4 / PTC17IFSEL1IF1
J1-11 / PTC0IRQIRQ
J1-5 / PTC1RESETCLRC_NRST
J2-14 / GNDGNDGND

 

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.

 

  • 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


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.

 

 

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.

 

  • Click on Finish.

 

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

 

/* 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 */

 

 

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 /* 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();

 

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.

3 people found this helpful

Attachments

    Outcomes