PN7150/PN7120 NFC Controller SBC Kit for Arduino on the i.MX6SX

Document created by gusarambula Employee on Jun 6, 2016Last modified by gusarambula Employee on Jun 13, 2016
Version 7Show Document
  • View in full screen mode

This is a step by step guide on setting up and running a simple NFC Demo App using the PN7150 NFC Controller SBC Kit for Arduino (OM5578/PN7150ARD) with a UDOO NEO board which uses an i.MX6SX and it's Arduino pin compatible.

 

1. Requirements

- UDOO NEO board. This document refers to the UDOO NEO Full board, but the steps remain the same for all UDOO Neo boards as long as the appropriate Device Tree is used for each. For more information on this board please go to the official site (http://www.udoo.org/)

UDOO_NEO_Small.jpgUDOO Neo Full Board

 

- PN7150 NFC Controller SBC Kit for Arduino (OM5578/PN7150ARD) which is shown on the image below. Alternatively you may use the PN7120 NFC Controller SBC Kit for Arduino (OM5577/PN7120ARD).

 

UDOO_Neo+OM5778_Small.jpg

PN7150 NFC Controller SBC Kit for Arduino mounted over the UDOO Neo

 

You may find more details about the OM5578 board on the user manual (Doc ID UM10935) which is available on the following link.

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

You may also find additional documentation and information of this and other PN7150 demoboards on the link below:

Demoboards for PN7150|NXP

 

You may find more details about the OM5577 board on the user manual (Doc ID UM10878) which is available on the following link.

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

For additional resources for the OM5577 board please refer to the link below.

PN7120 NFC Controller SBC Kit|NXP

 

- Host computer with Ubuntu 12.04 or later (14.04 is preferred).

 

- L3.14.28 BSP Release for the i.MX6SX installed on the host. You may find the documentation on how to download and setup this BSP on the following link.

http://www.nxp.com/products/microcontrollers-and-processors/arm-processors/i.mx-applications-processors/embedded-linux-for-i.mx-applications-processors:IMXLINUX?code=IMXLINUX

 

2. Setting up NXP BSP Release and Toolchain

Follow the instructions on the Yocto User’s Guide included on the L3.14.28 BSP Release to setup and build an image to for the i.MX6SX (MACHINE= imx6sxsabresd). We’ll be using the fsl-image-gui image with frame buffer (fb) backend. Other images may be used but please keep in mind that the core-image-minimal image does not include the libstdc++.so.6 library required by the NFC Demo App.

 

It is also necessary to build and install the toolchain for cross compiling the kernel and bootloader. This can be done with the following command:

$ bitbake meta-toolchain

 

Once created you may install it by running the following script:

<BSP_DIR>/<BUILD_DIR>/tmp/deploy/sdk/poky-glibc-x86_64-meta-toolchain-cortexa9hf-vfp-neon-toolchain-1.7.sh

 

For more details on how to extract the toolchain please refer to the following Yocto Training Task:

Task #7 - Create the toolchain

 

3. Editing the Device Tree

In previous versions (3.0.35 backward) the Linux Kernel used to contain the entire description of the hardware so the bootloader just had to load the kernel image and execute it. In current Kernel versions the hardware description is located in the device tree blob (DTB), which allows for the same Kernel to be used in different Hardware by changing only the Device Tree. In this scenario the bootloader loads the Kernel image and also the Device Tree (DTB) binary.

 

For more details on how to add a new Device Tree please look at the following Community Document that covers adding a new device tree:

https://community.nxp.com/docs/DOC-329664

 

For this document we will change the current UDOO NEO Device Tree as we will only be adding support for the PN7150 NFC Controller Board.

 

3.1 Copying the original UDOO Neo Device Tree files

 

Create a development folder in your home directory.

mkdir udooneo-dev

 

Download the kernel source into this folder. This also includes the device tree files.

cd udooneo-dev
git clone https://github.com/UDOOboard/linux_kernel

 

The Device Tree files will be available at  udooneo-dev/linux_kernel/arch/arm/boot/dts

 

3.2. Editing the UDOO Neo Device Tree Files

 

We will be using the UDOO Neo Full board, so we will be using the imx6sx-udoo-neo-full-hdmi-m4.dts. If we look into this file using a text editor we will see that it includes several include definition files which are also located in the same directory.

 

#include "imx6sx-udoo-neo.dtsi"
#include "imx6sx-udoo-neo-full.dtsi"
#include "imx6sx-udoo-neo-m4.dtsi"
#include "imx6sx-udoo-neo-hdmi.dtsi"
#include "imx6sx-udoo-neo-externalpins.dtsi"

 

We will need to copy these to the BSP Release dts directory (you may alternatively build the device tree from this directory, but we will cover how to add device trees to the BSP Release in this document):

 

/<BSP_DIR>/<BUILD_DIR>/tmp/work/imx6sxsabresd-poky-linux-gnueabi/linux-imx/3.14.28-r0/git/arch/arm/boot/dts/

 

We will need to add the new dtb file to be compiled on the Makefile from the BSP Release.  This needs to be placed inside the precompiler directive $(CONFIG_ARCH_MXC)

 

MakeFile_dts.jpg

 

There are some additions that must be made to device tree in order to configure the pins used by the NFC controller Board which uses the Arduino Pinout. These can be done to the imx6sx-udoo-neo.dtsi so they are taken by any UDOO Neo Device Tree we compile.

 

The I2C pins used are those of the I2C2 bus. The configuration for these pins should be already implemented on the imx6sx-udoo-neo.dtsi file. If not please add these lines inside the &iomuxc section.

 

&iomuxc {
                        pinctrl_i2c2_1: i2c2grp-1 {
                                        fsl,pins = <
                                                        MX6SX_PAD_GPIO1_IO03__I2C2_SDA          0x4001b8b1
                                                        MX6SX_PAD_GPIO1_IO02__I2C2_SCL           0x4001b8b1
                                        >;
                      };
};

Then we need to add the pn547 entry into the &i2c2 section for the enable pin, interrupt pin, I2C address and buss speed for the PN7150. Put what is in bold below at the end of the “&i2c2” section as shown.

 

&i2c2 {

pn547: pn547@28 {
compatible = "nxp,pn547";
                reg = <0x28>;
clock-frequency = <400000>;
interrupt-gpios = <&gpio4 9 0>;
enable-gpios = <&gpio5 21 0>;
        };
};

Important Note: Prior to adding either of these configurations it is critical that you ensure these pins and I2C addresses are not used anywhere else in this and other *udo*.dtsi files

 

DOCS_internal_pinout.PNG

 

You may find the UDOO Neo Schematics on the UDDO website (link to the schematics below) to see the reason behind these settings.

http://www.udoo.org/download/files/schematics/UDOO_NEO_schematics.pdf

 

IR Signal – J4 Connector – Arduino 7 pin – i.MX6SX B13 pin

VEN Signal - J6 Connector – Arduino 8 pin - i.MX6SX W5 pin

SDA Signal – J6 Connector – Arduino SDA pin - i.MX6SX D20 pin

SCL Signal – J6 Connector – Arduino SCL pin - i.MX6SX C20 pin

 

If you want to review in more detail how to create a simple Device Tree from scratch please check the following very complete and easy to follow Community Document.

Basic Device Tree for the Udoo Board

 

To compile the device tree run the following command

source /opt/poky/1.7/environment-setup-cortexa9hf-vfp-neon-poky-linux-gnueabi 
cd /<BSP_DIR>/<BUILD_DIR>/tmp/work/imx6sxsabresd-poky-linux-gnueabi/linux-imx/3.14.28-r0/git
make ARCH=arm dtbs 

This will produce the Imx6sx-udoo-neo-full-hdmi-m4.dtb that will be used.

 

4. Compiling U-Boot

We will be using the UDOO U-boot for the UDOO Neo Full board. The following steps describe how to download the source code and compiling it using our toolchain.

 

Downloading the source code

mkdir UDOOneo-dev
cd UDOOneo-dev
git clone -b 2015.04.imx-neo https://github.com/UDOOboard/uboot-imx
cd uboot-imx

 

Compiling u-boot

source /opt/poky/1.7/environment-setup-cortexa9hf-vfp-neon-poky-linux-gnueabi 
ARCH=arm CROSS_COMPILE=arm-poky-linux-gnueabi- make udoo_neo_config
ARCH=arm CROSS_COMPILE=arm-poky-linux-gnueabi- make

This will generate a SLP file with the DCD (Device Configuration Data) table and the u-boot.img file.

 

Note: By default this U-Boot configuration detects the UDOO Neo board and in our case it would look for the imx6sx-udoo-neo-full-hdmi-m4.dtb. You may need to use a different device tree depending on your board.

 

5. Flashing SD Card

5.1. Using the .sdcard file to load the BSP Release Image

The easiest way to load the Root File System from our image is using the .sdcard file that is created after running bitbake. This image will be located on the following path:

/<BSP_DIR>/<BUILD_DIR>/tmp/deploy/images/imx6sxsabresd

 

This will also load the BSP Release U-boot and device tree files but we will then exchange for our own. To do this use the following command where sdx is your SD Card.

$ sudo dd if=<image name>.sdcard of=/dev/sdx bs=1M && sync

Alternatively we can manually create the two partitions needed. For more information on this please refer to the Yocto User’s Guide.

 

5.2. Writing U-boot

To flash U-boot you need to flash both the SPL file and the u-boot.img file using the following commands assuming that your SD card is in /dev/sdx

dd if=SPL of=/dev/sdx bs=1K seek=1
dd if=u-boot.img of=/dev/sdx bs=1K seek=69

 

5.3. Copying the Device Tree Blob

Copy the imx6sx-udoo-neo-full-hdmi-m4.dtb device tree to a folder called dts on the FAT partition.

 

6. Adding Kernel Driver

Download the driver source from the git repository from the Linux source directory

 

cd /<BSP_DIR>/<BUILD_DIR>/tmp/work/imx6sxsabresd-poky-linux-gnueabi/linux-imx/3.14.28-r0/git/drivers/misc
$ git clone https://github.com/NXPNFCLinux/nxp-pn5xx.git

 

Add the line below to the Makefile of the current directory

    obj-y += nxp-pn5xx/ 

 

Include the driver config by adding below line to the heading configuration file

(drivers/misc/Kconfig).

source "drivers/misc/nxp-pn5xx/Kconfig"

 

Export the environment variables

cd /<BSP_DIR>/<BUILD_DIR>/tmp/work/imx6sxsabresd-poky-linux-gnueabi/linux-imx/3.14.28-r0/git/
    $ 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 
make menuconfig

 

Inside menu config include the driver as a module (<M>), which is on the path:

Device Drivers --->       Misc devices --->     < M> NXP PN5XX based driver

 

MenuConfig_PN5XX_Driver.jpg

 

Save the changes and exit, and then compile the modules.

$ make modules

 

We will then install the modules to our image. Insert the SD card with the loaded image and mount it to access it from the command promt.

sudo mount /dev/sdx ~/mountpoint/

 

Where sdx is your SD card. Then use the following command to install the modules.

sudo ARCH=arm INSTALL_MOD_PATH=/home/user/mountpoint modules_install firmware_install

 

Before unmounting our SD card we will install the NFC library.

 

7.Installing the NFC library.

Install the necessary libraries on the host by running the following commands:

 

sudo apt-get update
sudo apt-get install automake
sudo apt-get install autoconf
sudo apt-get install libtool

 

Note: In case you are using Ubuntu 12.04 the following commands will allow for autoconf 2.69 to be installed, which is the minimum version required by the NFC library.

sudo add-apt-repository ppa:dns/gnu -y
sudo apt-get update -q
sudo apt-get install --only-upgrade autoconf

 

Enter our directory and install the Linux libnfc-nci stack

cd ~/UDOOneo-dev
git clone https://github.com/NXPNFCLinux/linux_libnfc-nci.git

 

Generate the configuration script by executing the bootstrap bash script

cd ~/UDOOneo-dev/linux_libnfc-nci
./bootstrap

 

Configure Make file. We are using the default toolchain sysroots path.

To configure for the PN7150 please use the following settings:

./configure --enable-pn7150 --host=arm-none-linux --prefix=/opt/poky/1.7/sysroots/x86_64-pokysdk-linux/usr --sysconfdir=/home/user/mountpoint/etc

To configure for the PN7120 please use the following settings:

./configure --enable-pn7120 --host=arm-none-linux --prefix=/opt/poky/1.7/sysroots/x86_64-pokysdk-linux/usr --sysconfdir=/home/user/mountpoint/etc

 

We are ready to execute the make and install the stack.

make
sudo make install

 

After a successful build the libraries and a application demo are built in .libs directory. Copy the libraries to “/usr/lib” directory of the target and nfcDemoApp to the targets “/usr/sbin”

cd .libs
sudo cp * /home/user/mountpoint/usr/lib
sudo cp nfcDemoApp /home/user/mountpoint/usr/sbin
cd ~/UDOOneo-dev/linux_libnfc-nci/conf/PN7150
sudo cp * /home/user/mountpoint/etc

 

Now we can unmount our SD card.

sudo umount /home/user/mountpoint

 

8. Testing the NFC Reader

Insert the micro SD card into the slot of the UDOO Neo board and install the PN1750 NFC Controller board on top of the UDOO Neo board.

 

We will be using the terminal console in order to access the board. You may use the official USB/Serial debug module for NEO or a similar adapter.

For more information on setting up the Serial Debug Console on the UDOO Neo board please refer to the link below.

http://www.udoo.org/docs-neo/Basic_Setup/Serial_Debug_Console.html

 

Once it has booted, install the .ko file.

insmod /lib/modules/3.14.28+g91cf351/kernel/drivers/misc/nxp-pn5xx/pn5xx_i2c.ko

 

Then run the nfcDemoApp. We’ll test it in poll mode, where it looks for available tags and reads them.

nfcDemoApp poll

 

You should get a console output as shown below when placing a NFC tag next to the NFC reader.

 

NFC_Tag_Read.jpg

 

Appendix.

References and useful documents

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

Demoboards for PN7150|NXP

PN7120 NFC Controller SBC Kit|NXP

NFC PN7120 on the  i.MX6Q | NXP Community

Basic Device Tree for the Udoo Board Basic Device Tree for the Udoo Board

U-Boot Migration Example

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

1 person found this helpful

Attachments

    Outcomes