Porting PN7160 NCI2 stack to Raspberry Pi 5 OS --Bookworm

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

Porting PN7160 NCI2 stack to Raspberry Pi 5 OS --Bookworm

Porting PN7160 NCI2 stack to Raspberry Pi 5 OS --Bookworm

The Raspberry Pi Foundation released the Raspberry Pi 5 in October 2023, Raspberry Pi 5 features the Broadcom BCM2712 quad-core Arm Cortex A76 processor @2.4GHz, making it up to three times fast than Raspberry Pi 4.   The latest version of Raspberry Pi OS is Bookworm.

However, some customers found the PN7160 is not detected over I2C/SPI on the Raspberry Pi 5. Running "i2cdetect -y 1" produces a blank table, and running "nfcDemoApp poll" results in an "nfcservice init fail" message. The incompatibility appears to be between the PN7160 and the new Raspberry Pi OS—Bookworm.  This reason is Raspberry Pi OS received a major update in Linux Kernel 6.6,  the classic way of GIPO handling no long work.   In step 6, a new GPIO interface is introduced to resolve the incompatibility issue. This article is a step-by-step guide to port PN7160 NCI2 stack to Raspberry Pi OS--Bookworm.

 

Hardware setup:

For detail information about Raspberry Pi 5, please refer to below link.

 https://www.raspberrypi.com/products/

danielchen_0-1729324169624.png

 

The PN7160 EVK board must be connected to Raspberry Pi using the following instructions:

 

Raspberry Pi 5 board pin

NFC controller board signal

#1 3.3V PWR

VDD (PAD)

+5V

VBAT and VDD (UP)

#16 GPIO23

IRQ

#18 GPIO24

VEN

#22

DWL_REQ

#6

GND

#5

I2C_SCL

#3

I2C_SDA

 

danielchen_1-1729324214785.png

 

This matches the Raspberry Pi version of OM27160A1EVK (I2C variant).  The kit can then be plugged on Raspberry Pi 5 board to run the example.

First of all, assemble the PN7160 NFC controller board (OM27160A1HN or

OM27160B1HN) with the Raspberry Pi interface board (OM29110RPI)

 

danielchen_2-1729324261302.png

 

 Then stacked together the boards with the Raspberry Pi board.

danielchen_3-1729324294665.png

 

 

Software Setup:

1    Install Rasp 5 OS -Bookworm

We use Raspberry Pi Imager tool to install Raspberry Pi OS (64bit, Bookworm).

Click choose device and select Raspberry Pi 5, next click choose OS and select an operating system –Raspberry Pi OS (64-bit) , and select Micro SD card. Next we can write the Image to the Micro SD card.

danielchen_4-1729324360355.png

 

2 Enable i2c interface

1). Run command:

    sudo raspi-config

 

danielchen_5-1729324408868.png

 

2). Use the down arrow to select "Interface Options"

danielchen_0-1729324525908.png

 

3). Arrow down to "I5 I2C"

 

danielchen_1-1729324564799.png

 

4). Select "yes" when it asks you to enable I2C

5). Use the right arrow to select the <Finish> button

To verify the i2c interface is enabled, enter the following command:

$ ls /dev/i2c*

The Pi should respond with “ /dev/i2c-1” which represents the user-mode i2c interface to which is connected the PN7160

danielchen_2-1729324627935.png

 

 3 Install necessary tools

 

We need to use APT commands to install , update software package in Raspberry Pi OS, please refer to  below link. https://www.raspberrypi.com/documentation/computers/os.html

Libtool needs to be installed to run the NCI stack.

 

 4 Clone Linux libnfc-nci library repository

NFC NCI library is available from the following repository: https://github.com/NXPNFCLinux/linux_libnfc-nci

$ git clone https://github.com/NXPNFCLinux/linux_libnfc-nci.git -b NCI2.0_PN7160

 

danielchen_3-1729324690006.png

 

5 Apply 64bit patch

To install on 64bit OS, we need to apply 64bit patch.  It is under folder linux_libnfc-nci/64bit_patch/ROOT_src.patch

 

6 Modifications for GPIO

Raspberry Pi OS (Bookworm) received a major update which includes the Linux kernel 6.6.   In the new OS update, the classic way of interfacing with GPIO has been deprecated.  Unfortunately our PN7160 NCI stack still interact with GPIO using /sys/class/gpio pseudo-filesystem,  low level control of GPIOs no longer work with Bookworm.  So we need to use the new GPIO interface on the Raspberry PI: libgpiod.  At this point Raspberry OS with a kernel 6.6 both libgpiod and gpiod are not pre-packaged and we need to install them.

 

6.1  Installation of gpiod tools

danielchen_4-1729324839785.png

We can look more into what is installed

danielchen_5-1729324942850.png

 

The output of gpioinfo reports all of the available GPIO lines, by default for all chips.

6.2 Installation of the gpio libraries

If we want to install libraries for development we need to do the following

danielchen_6-1729325031223.png
 

Here is the info on libgpiod-dev

danielchen_7-1729325104084.png

 

danielchen_8-1729325127909.png

 

The development package installs the C libraries and header files for us to use.

Namely, the /usr/include/gpiod.h C header file and the /usr/lib/arm-linux-gnueabihf/libgpiod.so Shared Library.

 

6.3 Modifications in PN7160 NCI2 library.

In source code, we need to add the gpiod library support

6.3.1 Makefile.am 

danielchen_9-1729325179442.png

 

6.3.2 src/nfcandroid_nfc_hidlimpl/halimpl/tml/transport/NfccAltTransport.cc

danielchen_10-1729325241358.png

 

 ......

danielchen_11-1729325277575.pngdanielchen_12-1729325305421.png

 

 

and src/nfcandroid_nfc_hidlimpl/halimpl/tml/transport/NfccAltTransport.h

danielchen_13-1729325356759.png

 

If you need the modified source code files, please let me know. I can send the source code changes to you. 

 

7 Configure the library

danielchen_14-1729325396498.png

 

danielchen_15-1729325419517.png

 

 

8 Set the library to map i2c interface

danielchen_16-1729325461585.png

 

9 Build and install the library

 

$ make

$ sudo make install

$ export LD_LIBRARY_PATH=/usr/local/lib

 

10 Run & Verify the NFC functionality

 

danielchen_17-1729325515743.png
 

This demo works as expected.

 

Summary:

Porting PN7160 NCI2 stack to Raspberry Pi 5, we need to follow PN7160 Linux porting guide and update the classic GPIO interface to gpiod libraries.

 

Happy porting

Labels (1)
100% helpful (1/1)
Version history
Last update:
‎10-19-2024 01:19 AM
Updated by: