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/
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 |
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)
Then stacked together the boards with the Raspberry Pi board.
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.
2 Enable i2c interface
1). Run command:
sudo raspi-config
2). Use the down arrow to select "Interface Options"
3). Arrow down to "I5 I2C"
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
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
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
We can look more into what is installed
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
Here is the info on libgpiod-dev
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
6.3.2 src/nfcandroid_nfc_hidlimpl/halimpl/tml/transport/NfccAltTransport.cc
......
and src/nfcandroid_nfc_hidlimpl/halimpl/tml/transport/NfccAltTransport.h
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
8 Set the library to map i2c interface
9 Build and install the library
$ make
$ sudo make install
$ export LD_LIBRARY_PATH=/usr/local/lib
10 Run & Verify the NFC functionality
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