NfcRdLib for i.mx7dsabresd

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

NfcRdLib for i.mx7dsabresd

NfcRdLib for i.mx7dsabresd

Introduction

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 http://commondatastorage.googleapis.com/git-repo-downloads/repo > ~/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://git.freescale.com/imx/fsl-arm-yocto-bsp.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 fsl-setup-release.sh -b buildDevSpi

$ bitbake fsl-image-machine-test

To build the toolchain, run:

$ bitbake meta-toolchain

$ cd buildDevSpi/tmp/deploy/sdk/

$ ./fsl-imx-xwayland-glibc-x86_64-meta-toolchain-cortexa7hf-neon-toolchain-4.1.15-2.1.0.sh

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
J11 - 2SPI SS0GPIO6_IO22 (SAI2_TX_DATA)B9
J31 - 2SPI MOSIECSPI3_MOSI (SAI2_TX_BCLK)B10
J21 - 2SPI MISOECSPI3_MISO (SAI2_TX_SYNC)B11
J192 - 3PN5180 BUSYGPIO6_IO14 (SAI1_TX_SYNC)B58
J51 - 2PN5180 IRQGPIO6_IO13 (SAI1_TX_BCLK)B62
XXPN5180 DWLGNDB52
XXGNDGNDB2

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:

$ ./build.sh 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: https://www.nxp.com/webapp/sps/download/preDownload.jsp?render=true

– NFC Reader Library for Linux Installation: https://www.nxp.com/docs/en/application-note/AN11802.pdf

– PN5180 component: https://www.nxp.com/docs/en/data-sheet/PN5180A0XX-C1-C2.pdf

Attachments
Comments

Hi,

My platform is i.MX6ULL evkit.  It's different than i.mx7dsabresd but they should be similar.  When I run Example 1 it gave me below error:

root@imx6ull14x14evk:~/PN5180# ./NfcrdlibEx1_BasicDiscoveryLoop

BasicDiscoveryLoop Example:
Line: 114 Error - (0xF181) has occurred : 0xCCEE CC-Component ID, EE-Error code. Refer-ph_Status.h

Line: 123 Error - (0xF181) has occurred in NFCLIB

How do I check what the 0xF181 error message means? 

In Platform/DAL/boards/Board_PiPn5180.h

As you said, DWL is connected to GND, so what should I put for #define PHDRIVER_PIN_DWL?

#define PHDRIVER_PIN_RESET 20 
#define PHDRIVER_PIN_IRQ 21 
#define PHDRIVER_PIN_BUSY 25

I've checked that I can control pin high/low with /sys/class/gpio/gpio20, 21, and 25.  I've also configured dts to have /dev/spidev3.0 and run spidev_test, and this device node can read/write successfully.  

cmake .. -DFRONTEND_PN5180=ON -DFRONTEND_RC663=OFF didn't work, so I manually modified CMakeLists.txt to the following:

OPTION(WITH_NDA "With Components/Examples Under NDA" OFF)

OPTION(BOARD_RaspberryPi "Platform is RaspberryPi" ON)

OPTION(FRONTEND_PN5180 "IC Frontend is PN5180" ON)
OPTION(FRONTEND_RC663 "IC Frontend is RC663" OFF)

OPTION(BUS_SPIUserMode "Connected to FRONTEND over SPI in User Mode" ON)
OPTION(BUS_SPIKernelMode "Connected to FRONTEND over SPI in Kernal Mode" OFF)

My board is not raspberryPi but if I change this option to off, it gave compilation error.  So I supposed I should use ON for raspberryPi option:

root@imx6ull14x14evk:~/PN5180/_build_new# make
Scanning dependencies of target DAL
[ 0%] Building C object Platform/DAL/CMakeFiles/DAL.dir/src/Linux/phDriver_Linux.c.o
[ 1%] Building C object Platform/DAL/CMakeFiles/DAL.dir/src/Linux/phbalReg_Linux_UserSpi.c.o
[ 1%] Building C object Platform/DAL/CMakeFiles/DAL.dir/src/Linux/phDriver_Linux_Int.c.o
[ 2%] Building C object Platform/DAL/CMakeFiles/DAL.dir/src/Linux/phbalReg_Linux_KernelSpi.c.o
[ 2%] Linking C static library libDAL.a
[ 2%] Built target DAL
Scanning dependencies of target NxpRdLib_palI18000p3m3
[ 2%] Building C object NxpNfcRdLib/comps/phpalI18000p3m3/CMakeFiles/NxpRdLib_palI18000p3m3.dir/src/phpalI18000p3m3.c.o
In file included from /home/root/PN5180/RTOS/phOsal/inc/phOsal.h:62:0,
from /home/root/PN5180/NxpNfcRdLib/intfs/phhalHw.h:38,
from /home/root/PN5180/NxpNfcRdLib/intfs/phpalI18000p3m3.h:30,
from /home/root/PN5180/NxpNfcRdLib/comps/phpalI18000p3m3/src/phpalI18000p3m3.c:27:
/home/root/PN5180/RTOS/phOsal/inc/phOsal_Config.h:88:5: error: #error "OSAL not selected"
# error "OSAL not selected"
^
NxpNfcRdLib/comps/phpalI18000p3m3/CMakeFiles/NxpRdLib_palI18000p3m3.dir/build.make:62: recipe for target 'NxpNfcRdLib/comps/phpalI18000p3m3/CMakeFiles/NxpRdLib_palI18000p3m3.dird
make[2]: *** [NxpNfcRdLib/comps/phpalI18000p3m3/CMakeFiles/NxpRdLib_palI18000p3m3.dir/src/phpalI18000p3m3.c.o] Error 1
CMakeFiles/Makefile2:1701: recipe for target 'NxpNfcRdLib/comps/phpalI18000p3m3/CMakeFiles/NxpRdLib_palI18000p3m3.dir/all' failed
make[1]: *** [NxpNfcRdLib/comps/phpalI18000p3m3/CMakeFiles/NxpRdLib_palI18000p3m3.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
root@imx6ull14x14evk:~/PN5180/_build_new#

What else is missing?

Hi Gideon Tsang,

If I remember correctly, the DWL pin is necessary only for pn5180 firmware updates, so I think you can set it to 0 and it will be fine. Also, the raspberryPi should be left on ON because it enables some linux specific components that are required on imx boards too. Also, take care to have enable Userspace IO and Spidev in kernel. The rest of the build options seem fine.

The first error is returned in phbalReg_Init, so the problem is most likely related to the SPI communication (the phbalReg_Init should setup the SPI connection). You can check the error code in phDriver.h, where you will find:

#define PH_COMP_DRIVER              0xF100U /**< DRIVER component code. */

#define PH_DRIVER_FAILURE                 0x0081 /**< Failed to perform the requested operation. */

I think the easiest way to debug is to use a logic analyzer to check the communication between the imx and the pn5180 when an application is running.

Best Regards,

Dragos

Hi Dragos,

Thanks for your help.  I found that I misconfigured the SPI. I went pass the first PH_DRIVER_FAILURE error after modify below for /dev/spidev3.0

#ifdef PHDRIVER_LINUX_USER_SPI
# define PHDRIVER_USER_SPI_BUS 3 /**< "/dev/spidev0.0" */
# define PHDRIVER_USER_SPI_CS 0 /**< "/dev/spidev0.0" */
# define PHDRIVER_USER_SPI_FREQ 5000000 /**< 5 MHz. */
# define PHDRIVER_USER_SPI_CFG_DIR "/dev/spidev"
# define PHDRIVER_USER_SPI_CFG_MODE SPI_MODE_0
# define PHDRIVER_USER_SPI_CFG_BITS_PER_WORD 8
#endif

However, now I still have the NFCLIB error:

./NfcrdlibEx1_BasicDiscoveryLoop

BasicDiscoveryLoop Example:

Line: 123   Error - (0x0101) has occurred in NFCLIB

One thing I noticed that the IRQ LED is always on(IRQ pin level HIGH), and when I check

/sys/class/gpio# ls
export gpio20 gpio23 gpio25

 

which corresponds to my config:

#define PHDRIVER_PIN_RESET 20 /**< "/sys/class/gpio/gpio7/" */
#define PHDRIVER_PIN_IRQ 21 /**< "/sys/class/gpio/gpio23/" */
#define PHDRIVER_PIN_BUSY 25 /**< "/sys/class/gpio/gpio25/" */
#define PHDRIVER_PIN_DWL 23 /** DWL is actually tied to GND */

so it looks something's not right that gpio21 for the IRQ is not created under /sys/class/gpio . Is this correct or I should have something at the device tree to enable this interrupt?

Hi Gideon Tsang,

The PHDRIVER_PIN_IRQ is exported in phApp_Configure_IRQ(), which is at line 136, after phNfcLib_Init(), which means that no entry in /sys/class/gpio is expected.

Best Regards,

Dragos

Hi Gideon Tsang,

Have you checked that you can control the pin values from userspace? To me, it seems that the library fails to properly initialize the pn5180.

Best Regards,

Dragos

Hi Dragos,

Yes I can control pin values from userspace /sys/class/gpio/.  

Do you happen to know where to find a full schematic of the PN5180 evkit?  I looked at AN11744.pdf , but the pictures are not good and I couldn't really read it.  I found that the LED LD201 is not ON when I'm using Linux.  It was ON when it works(when I use Windows Cockpit).  I doubt if the chip is powered up properly.

thanks,

Gideon

Here is the SPI waveform.  I would like to know why is it "NFCLIB error" after these 0x07 0x12 0x02 SPI commands?  Does it expect something return from MISO line?

pastedImage_1.png

Hi Gideon,

The command 0x7 0x12 0x2 is an EEPROM read access. It means read 2 bytes starting from address 0x12. From the PN5180 manual, we can find that address 0x12 and 0x13 store the firmware major and minor version. It is ok that nothing is on the MISO line, because they library should perform another exchange in order to get the information back.

The SPI enable seems to not be working as the library expects: it is asserted and deasserted for every byte, and in the manual it specifies that the SPI enable must be set to low before a data transaction starts and must be kept low for the whole transaction (no chaining is supported).

Also, the fact that another atempt to perform an exchange and read the response is not performed may indicate a problem with the busy line.

A picture in which the busy line is visible will be really useful.

Best Regards,

Dragos

It's working now once I changed the CS pin to other GPIO!  Many thanks Dragos!

In case someone else has similar issue, it may relate to below issue:

native cs and gpio cs in spi - imx6  

I haven't really dig into the details why the default cs doesn't work.  It is not really "not working", since it's pulling low when the master is sending out data, but it doesn't stay low to follow spi spec.  For now my fix is just changing to another gpio for cs:

My device tree config:

... &iomuxc

       pinctrl_ecspi4: ecspi4grp {
          fsl,pins = <
              MX6UL_PAD_ENET2_TX_CLK__ECSPI4_MISO      0x1b0b1
              MX6UL_PAD_ENET2_TX_EN__ECSPI4_MOSI       0x1b0b1
              MX6UL_PAD_ENET2_TX_DATA1__ECSPI4_SCLK    0x1b0b1
              MX6UL_PAD_ENET2_RX_ER__ECSPI4_SS0        0x1b0b1 /* default CS is buggy */
          >;
      };

&ecspi4 {
    fsl,spi-num-chipselects=<1>;
    /* cs-gpios = <0>;    Default CS pin doesn't give good cs signals */
    cs-gpios = <&gpio1 30 0>;   /* change CS to other GPIO for workaroud */
    pinctrl-names = "default";
    pinctrl-0 = <&pinctrl_ecspi4>;
    status = "okay";

    spidev@0x00 {
      compatible = "spidev";
      spi-max-frequency = <50000000>;
      reg = <0>;
    };
};‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

As a reference, a good waveform which can successfully init the NFC library and read cards is shown below:

pastedImage_1.png

No ratings
Version history
Last update:
‎11-16-2017 09:13 AM
Updated by: