NfcRdLib for i.mx7dsabresd

Document created by Dragos Mincu Employee on Nov 16, 2017Last modified by Dragos Mincu Employee on Feb 23, 2018
Version 5Show Document
  • View in full screen mode



The NFC Reader Library is a feature complete software support library for NXP's NFC Frontend ICs. It is 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 purpose of this document is to provide instructions on how to install the NFC Reader Library on imx7dsabresd and communicate with PN5180, a NFC frontend. It will describe all the steps required to connect the board to an OM25180TWR, the wire connections, the changes in the device tree, and the library configuration.


Building the Linux image and the Bal kernel module


This section describes how to build the Linux image using Yocto and how to compile the Bal kernel module. Informations specific for this library start from the next section.

Requirements: a Linux host PC (ex. Ubuntu 14.04/16.04) and root permissions.

To download the required host packages, use:

$ sudo apt-get install gawk wget git-core diffstat unzip texinfo gcc-multilib build-essential chrpath socat libsdl1.2-dev

Specific for Ubuntu:

$ sudo apt-get install libsdl1.2-dev xterm sed cvs subversion coreutils texi2html docbook-utils python-pysqlite2 help2man make gcc g++ desktop-file-utils \

libgl1-mesa-dev libglu1-mesa-dev mercurial autoconf automake groff curl lzop asciidoc


To setup the repo utility (a tool written on top of git), run the commands:

$ mkdir ~/bin (this step may not be needed if the bin folder already exists)

$ curl > ~/bin/repo

$ chmod a+x ~/bin/repo


Then add the following line to .bashrc to ensure the ~/bin is in the PATH variable.

export PATH=~/bin:$PATH


To download the Freescale Yocto Project Community BSP:

$ mkdir fsl-release-bsp
$ cd fsl-release-bsp
$ repo init -u git:// -b imx-4.1-krogoth
$ repo sync


To build the image, in the fsl-release-bsp run the commands:

$ mkdir buildDevSpi

$ DISTRO=fsl-imx-xwayland MACHINE=imx7dsabresd source -b buildDevSpi

$ bitbake fsl-image-machine-test


To build the toolchain, run:

$ bitbake meta-toolchain

$ cd buildDevSpi/tmp/deploy/sdk/

$ ./

Accept the default parameters.


In order to deploy the image on an SD card use:

$ sudo dd if=fsl-image-machine-test-imx7dsabresd.sdcard of=<sd card> bs=1M && sync

The image is found in buildDevSpi/tmp/deploy/images/imx7dsabresd.


For the kernel module compilation, setup the console environment:

$ . /opt/fsl-imx-xwayland/4.1.14-2.1.0/environment-setup-cortexa7hf-neon-poky-linux-gnueabi

Then, in the kernel module directory, replace the path with your linux build directory in the Makefile and run:

$ make

The bal.ko is the compiled module.


To use the kernel menuconfig, run:

$ bitbake -c menuconfig linux-imx

Another useful command, for rebuilding the linux kernel image, is:

$ bitbake -f -c compile linux-imx; bitbake -f -c deploy linux-imx; bitbake -f -c compile fsl-image-machine-test; bitbake -f fsl-image-machine-test


Host interface


The interface of the PN5180 to a host is based on a SPI interface, extended by the signal line BUSY. Only half-duplex data transfer is supported and no chaining is allowed, meaning that the whole instruction has to be sent, or the whole receiver buffer has to be read out.


The module is connected to the i.MX7D board using the mikro bus expansion port in the following way:

MK_BUS_CS, MK_BUS_SCK, MK_BUS_MOSI, MK_BUS_MISO are used for the SPI bus lines.

MK_BUS_INT, MK_BUS_RX, MK_BUS_TX are used for the BUSY, RESET and IRQ lines.


The pin configuration will be the following: GPIO6_IO22 will be the CS, GPIO6_IO14 will be BUSY, GPIO_IO12 will be RESET and GPIO_IO13 will be IRQ.

The DWL pin, which can be used for firmware update, will be connected to GND. A common ground is also required.


Connections table:

JumperJumper PinsDescriptioni.MX7D I/OTower Edge
J41 - 2SPI Clk SelectionECSPI3_SCLK (SAI2_RX_DATA)B7
J201 - 2PN5180 ResetGPIO6_IO12 (SAI1_RX_DATA)B8
J192 - 3PN5180 BUSYGPIO6_IO14 (SAI1_TX_SYNC)B58
J51 - 2PN5180 IRQGPIO6_IO13 (SAI1_TX_BCLK)B62


Kernel Configuration


In order to allow the library to manage the RESET, IRQ and BUSY pins, the options for Debug GPIO and Userspace I/O drivers must be enabled (in menuconfig, Device Drivers -> GPIO Support -> Debug GPIO and Device Drivers -> Userspace I/O -> Userspace I/O platform driver with generic IRQ).


For controlling the SPI, there are two options: spidev or NXP bal.


For spidev, it is necessary to select Device Drivers -> SPI support -> User mode SPI and apply the imx7d-sdb_spidev.patch (it also does the pinmuxing, it is attached to the document).


When using NXP bal, it is necessary to compile the module, initialize it with insmod and apply the imx7d-sdb_bal.patch (it also does the pinmuxing, the patch and the module are attached to this document).


Library Configuration


For the library configuration, <lib-folder>/Platform/DAL/Board_Imx6ulevkPn5180.h must be replaced with Board_Imx7dsabresdPn5180_bal.h or Board_Imx7dsabresdPn5180_spidev.h (based on the selected spi interface).


For compilation, the command is:

$ ./ yocto /opt/fsl-imx-xwayland/4.1.15-2.1.0/sysroots/

The last parameter is the location of the toolchain generated by yocto.

A build folder is generated outside of the source code folder. The applications from the ComplianceApp can be deployed on the board in order to test the functionality provided.



Other useful resources:

– i.MX Yocto Project User's Guide:

– NFC Reader Library for Linux Installation:

– PN5180 component:

4 people found this helpful