Hello community:
This document shows how to integrate a basic NFC (Near Field Communication) library to a KSDK project and explain its use with a simple demo project.
INTEGRATING NFC CONTROLLER LIBRARY
These instructions are based in the files usually present in a KSDK project. If your project has a custom source file structure, just add the referenced code accordingly.
1- Open the file gpio_pins.c and add 2 pin configurations: 1 input pin called NFCCirqPin and 1 output pin called NFCCvenPin:
gpio_input_pin_user_config_t NFCCirqPin =
{
.pinName = kGpioNFCCirq,
.config.isPullEnable = false,
.config.pullSelect = kPortPullUp,
.config.isPassiveFilterEnabled = false,
.config.interrupt = kPortIntDisabled,
};
gpio_output_pin_user_config_t NFCCvenPin =
{
.pinName = kGpioNFCCven,
.config.outputLogic = 1,
.config.slewRate = kPortSlowSlewRate,
.config.driveStrength = kPortLowDriveStrength,
};
2- In the file gpio_pins.h add 2 extra elements to the gpio enumeration. Also add extern declarations for the 2 pins defined in the previous step.
NOTE: In this example the selected pins are PTB16 as IRQ and PTB17 as VEN. The pins depend on your routing from the Kinetis MCU to the NFC Controller board.
enum _gpio_pins
{
kGpioLED1 = GPIO_MAKE_PIN(GPIOD_IDX, 5),
kGpioLED2 = GPIO_MAKE_PIN(GPIOE_IDX, 31),
kGpioSW1 = GPIO_MAKE_PIN(GPIOA_IDX, 4),
kGpioSW3 = GPIO_MAKE_PIN(GPIOC_IDX, 3),
kGpioNFCCirq = GPIO_MAKE_PIN(GPIOB_IDX, 16),
kGpioNFCCven = GPIO_MAKE_PIN(GPIOB_IDX, 17),
};
extern gpio_input_pin_user_config_t NFCCirqPin;
extern gpio_output_pin_user_config_t NFCCvenPin;
3- In the file pin_mux.c define a function to configure the MUX setting of the required GPIO and I2C pins to interface with the NFC controller.
NOTE: The configured pins must correspond to the routing from the Kinetis MCU to the NFC controller board. In this case PTB16/PTB17 are set as GPIOs while PTE0/PTE1 are configured for I2C functionality. For I2C pins also check the MUX number in the device's Reference Manual (e.g. PTE0/PTE1 in KL43 have the I2C function in ALT6.
void configure_nfcc_pins(void)
{
PORT_HAL_SetMuxMode(PORTE,0u,kPortMuxAlt6);
PORT_HAL_SetMuxMode(PORTE,1u,kPortMuxAlt6);
PORT_HAL_SetMuxMode(PORTB,16u,kPortMuxAsGpio);
PORT_HAL_SetMuxMode(PORTB,17u,kPortMuxAsGpio);
}
4- Add the prototype of the function to header file pin_mux.h.
void configure_nfcc_pins(void);
5- Add the NfcLibrary and TML folders with all its subfolders and files to your project's tree, so the library is part of the build. Also add the include paths to your compiler for the inc folders. Below an example with Kinetis Design Studio:



- Now the project is ready to use the NFC controller library. The library uses the next conditional compilation macros, add or remove these symbols from the compiler's preprocessor settings as required:
CARDEMU_SUPPORT: The NFC Controller host (MCU) emulates a contactless card which can be accessed by an external Reader/Writter.
P2P_SUPPORT: The host MCU can establish a 2-way communication accesing to or sending information to an external Reader/Writter.
RW_SUPPORT: With this mode the host can access a remote contactless tag/card via the NFC Controller.
NCI_DEBUG: If defined, all information transfered between the host MCU and the NFC Controller Interface (commands, responses, notifications, data) is echoed to console for debug purposes.
DEMO PROJECT
The attached project is based on the application note AN11658 NXP-NCI NullOS integration example. So you can refer to the appnote for detailed information.
Software
The project was developed with the next software versions:
- KSDK v1.3
- KDS v3.0.0
:smileyinfo: NOTES:
-The KSDK platform library for the KL43 must be built before the example project. Otherwise the build fails due to library file missing (libksdk_platform.a).
- Once the example project is imported please verify that the build variable PROJECT_KSDK_PATH is pointing to your KSDK v1.3 installation path.
Hardware
- For the NFC part, I used the NFC Controller board from the OM5577, which is a demonstration kit for the PN7120 NFC controller Interface chip.
- To interface with the NFC Contoller I used a FRDM-KL43Z Freedom board.


How to use the demo
R/W mode:
- Placing a tag with a single text, URI or vCard NDEF record next to the NFC reader. Examples:



P2P mode:
- Bring an android phone with NFC enabled close to the NFC controller antenna and use the "beaming" feature. In the case below the NXP home page is "beamed" from the adroid phone's explorer:




CARD EMULATION mode
For this mode it is required to remove the P2P_SUPPORT macro and rebuild/reprogram the project.
- Bringing an android phone set to read a NFC tag close to the NFC controller board:


I hope you like this document. Any questions or doubts please let me know in the comments.
Jorge Gonzalez
NXP Technical Support