NFC PN7120 on the  i.MX6Q

Document created by alejandrolozano Employee on Jan 29, 2016
Version 1Show Document
  • View in full screen mode
  1. INTRODUCTION
  2. REQUIREMENTS
  3. KERNEL DRIVER
  4. DEVICE NODE
  5. NFC LIBRARY
  6. TESTING NFC READER
  7. REFERENCES

 

 

 

1. INTRODUCTION

 

This document is a step by step guide of the AN11697 PN7120 Linux Software Stack Integration Guidelines application note that can be downloaded from http://www.nxp.com/documents/application_note/AN11697.pdf . It explains how to add the PN7120 driver and NFC libraries to a Linux OS running in the i.MX6Q.

 

2. REQUIREMENTS

 

 

3. KERNEL DRIVER

 

According to the AN11697.pdf we must follow the below steps:

 

  1. From the Linux source directory:

    $ cd drivers/misc
    $ git clone https://github.com/NXPNFCLinux/nxp-pn5xx.git
  2. Add the below line in the Makefile of the current directory

    obj-y += nxp-pn5xx/
  3. Include the driver config in the drivers/misc/Kconfig file

    source "drivers/misc/nxp-pn5xx/Kconfig"
  4. Export the environment variables

    $ source source /opt/poky/1.7/environment-setup-cortexa9hf-vfp-neon-poky-linux-gnueabi
    $ export ARCH=arm
    $ export CROSS_COMPILE=$TARGET_PREFIX
    $ make imx_v7_defconfig
  5. Using menuconfig include the driver as module (<M>). 



  6. Compile the modules and install the .ko files into the target rootfs.

    $ make  modules
  7. You can send the .ko files with scp
    $ make  INSTALL_MOD_PATH=~/Desktop/modules modules_install
    $ cd ~/Desktop/modules
    $ sudo scp -r lib/modules/3.14.28+g91cf351/kernel root@<board_ip>:/lib/modules/3.14.28+g91cf351/

 

4. DEVICE NODE

 

The PN7120 interfaces with an MCU or MPU via I2C interface, therefore the device must be described into a i2c node. The signals used in the PN7120 are shown below:

 

 

As you can see besides power, ground and I2C lines, an IRQ and Reset pins are needed. These pins must be configured as GPIO and one must generate an interrupt to the iMX6Q.

The chosen connection is shown below:

 

To achieve the above configuration, the device tree must be changed. The changes consist on adding a device node in the corresponding I2C bus, describing the PN7120.

 

 

&i2c1 {
        clock-frequency = <100000>;
        pinctrl-names = "default";
        pinctrl-0 = <&pinctrl_i2c1>;
        status = "okay";

        pn547: pn547@28 {
                compatible = "nxp,pn547";
                reg = <0x28>;
                clock-frequency = <400000>;
                interrupt-parent = <&gpio6>;
                interrupt-gpios = <&gpio6 2 0>;
                enable-gpios = <&gpio5 22 0>;
        };


};

The pinctrl_i2c1 phandle contains the I2C pins configuration. Make sure that the PADs connected to the PN7120 are not used in other device node.

 

 

&iomuxc {
        imx6q-udoo {        
               ...
                pinctrl_i2c1: i2c1grp {
                        fsl,pins = <
                        MX6QDL_PAD_GPIO_5__I2C3_SCL             0x4001b8b1
                        MX6QDL_PAD_GPIO_6__I2C3_SDA             0x4001b8b1
                        >;
                };
        };
};

After this you can generate the dtb file and send it with scp

 

make dtbs
sudo scp arch/arm/boot/dts/imx6q-udoo.dtb root@<board_ip>:/run/media/mmcblk0p1/imx6q-udoo.dtb

NOTE:

Attached you can find the complete dts and dtsi files used in this document.

 

5. NFC LIBRARY    

 

To work with the PN7120 in Linux the libnfc-nci stack is needed. You can find more details in http://www.nxp.com/documents/application_note/AN11697.pdf . This sections explains how to cross-compile the libray and install the required files in the target (The below steps must be performed in the host).

 

  1. Get the library
    $  git clone https://github.com/NXPNFCLinux/linux_libnfc-nci.git
  2. Generate the configuration script
    $ ./bootstrap
  3. Mount the target rootfs to /mnt in the host.
    $ sudo mount /dev/sdX2 /mnt
  4. Generate the Makefile
    $ ./configure --host=arm-none-linux --prefix=/opt/poky/1.7/sysroots/x86_64-pokysdk-linux/usr --sysconfdir=/mnt/etc
  5. Build and install the source code
    $ make
    $ make install
  6. After a succesful bulding the libraries and a application demo are built in .libs directory. Copy the libaries to /usr/lib directory of the target and nfcDemoApp to /usr/sbin
    $ cd linux_libnfc-nci/.libs
    $ sudo cp * /mnt/usr/lib/

 

6. TESTING NFC READER    

 

To test the application you have to follow the below steps on the target:

 

  1. Install the .ko file
    $ insmod /lib/modules/3.14.28+g91cf351/kernel/drivers/misc/nxp-pn5xx/pn5xx_i2c.ko
  2. Run the nfcDemoApp
    $  nfcDemoApp poll
    You should get a console output like the shown below when placing a NFC tag next to the NFC reader.

 

 

7. REFERENCES    

Integrating NFC Controller library with KSDK

http://www.nxp.com/documents/application_note/AN11697.pdf

http://www.nxp.com/documents/user_manual/UM10878.pdf

3 people found this helpful

Attachments

    Outcomes