OpenWrt package for NXP PN7160 NFC Controller NCI stack.
NOTE: do not download the firmware, because download bugy
now software support version:
FW Version: 12.50.5 (in module)
FW Version: 12.50.9 (in libpn7160_fw.so)
According to NXP official documentation, PN7160 will not respond to standard I2C scans. Here's why:
PN7160 Special Features:
- Uses proprietary NCI (NFC Controller Interface) protocol
- Not a standard I2C slave device
- Only responds to specific NCI command sequences
- Does not respond to regular I2C read operations
- Requires specific initialization handshake process
Correct Usage:
- Must send correct NCI initialization commands
- Use NXP provided libraries and drivers
- Similar chips (like PN532, PN7150) have the same characteristics
- All require specialized drivers
# 1. Get NXP's NCI stack
git clone https://github.com/NXPNFCLinux/linux_libnfc-nci.git
# 2. Compile and install
cd linux_libnfc-nci
./bootstrap
./configure
make
sudo make install
# 3. Configure device tree or kernel driver
# PN7160 support needs to be enabled in Linux kernellibnfc-nci/
βββ Makefile # OpenWrt package definition
βββ README.md # This file (English)
βββ README_CN.md # Chinese documentation
βββ patches/ # Source code patches
β βββ 001-change-config-dir.patch
β βββ 002-fix-transport-config-path.patch
β βββ 003-fix-config-path-provider.patch
β βββ 100-64bit-support.patch
βββ files/ # Additional files to install
βββ src/ # (Reserved for local source if needed)
These patches change the configuration file location from /usr/local/etc/ to /etc/nfc/:
| Patch File | Description |
|---|---|
| 001-change-config-dir.patch | Updates Makefile.am to install configs to /etc/nfc/ |
| 002-fix-transport-config-path.patch | Updates config.cc transport path |
| 003-fix-config-path-provider.patch | Updates all config paths in ConfigPathProvider.cc |
100-64bit-support.patch: Fixes for 64-bit architecture compatibility
- Type conversion fixes (
unsigned intvssize_t) - Pointer dereference fixes
- Data structure alignment fixes
The package installs configuration files to /etc/nfc/:
Main Configuration Files:
libnfc-nci.conf- System configurationlibnfc-nxp.conf- Vendor configuration
Additional Configuration Files (if present):
libese-nxp.conf- ESE configurationlibnfc-nxp_RF.conf- RF configurationlibnfc-nxpTransit.conf- Transit configuration
This package produces three packages:
/usr/lib/libnfc_nci_linux.so*/etc/nfc/libnfc-nci.conf/etc/nfc/libnfc-nxp.conf
/usr/sbin/nfcDemoApp
/usr/lib/libpn7160_fw.so*
| Library | Description |
|---|---|
libstdcpp |
C++ standard library |
libpthread |
POSIX threads |
librt |
Real-time extensions |
libgpiod |
GPIO library (for PN7160 hardware control) |
autoconfautomakelibtool
Copy this directory to your OpenWrt packages feed:
# For feeds/packages
cp -r libnfc-nci $(OPENWRT_DIR)/feeds/packages/libs/
# Or for custom packages
cp -r libnfc-nci $(OPENWRT_DIR)/package/cd $(OPENWRT_DIR)
./scripts/feeds update -a
./scripts/feeds install -amake menuconfigNavigate to:
Librariesβ Selectlibnfc-nciUtilitiesβ Selectlibnfc-nci-utilsLibrariesβ Selectlibpn7160-fw
# Build single package
make package/libnfc-nci/compile V=s
# Build with dependencies
make package/libnfc-nci/{clean,compile} V=s
# Build all selected packages
make -j$(nproc)ls $(OPENWRT_DIR)/bin/packages/*/packages/libnfc-nci*.ipk| Sparefunction | Mainfunction | pin# | pin# | Mainfunction | Sparefunction | |
|---|---|---|---|---|---|---|
| - | 3V3 | 1 | β β | 2 | 5V | - |
| I2C_SDA | GPIO 4 | 3 | β β | 4 | 5V | - |
| I2C SCL | GPIO 3 | 5 | β β | 6 | GND | - |
| PWM1 | GPIO 22 | 7 | β β | 8 | GPIO 43 | UART1 TX |
| - | GND | 9 | β β | 10 | GPIO 42 | UART1 RX |
| UART2 TX | GPIO 30 | 11 | β β | 12 | GPIO 64 | PCM_CLK |
| UART2 RX | GPIO 29 | 13 | β β | 14 | GND | - |
| PCM_FS | GPIO 65 | 15 | β β | 16 | GPIO 45 | UART1_RTS |
| - | 3V3 | 17 | β β | 18 | GPIO 44 | UART1_CTS |
| SPIC_MO | GPIO 7 | 19 | β β | 20 | GND | - |
| SPIC_MI | GPIO 8 | 21 | β β | 22 | GPIO 62 | PCM_DTX |
| SPIC_CK | GPIO 6 | 23 | β β | 24 | GPIO 14 | SPIC_CS |
| - | GND | 25 | β β | 26 | GPIO 63 | PCM_DRX |
| PIN | Signal | I/O Type | Description |
|---|---|---|---|
| PIN1 | SCL | OD | I2C SCL (internal 4.7K pull-up) |
| PIN2 | SDA | OD | I2C SDA (internal 4.7K pull-up) |
| PIN3 | IRQ | I/O | Tell the host this module have I2C data to send. High enable, normal Low |
| PIN4 | VEN | I/O | Reset the module, set Low to reset |
| PIN5 | D-/DWL | I/O | USB D- (USB mode); DWL (I2C mode - firmware download) |
| PIN6 | D+/NC | I/O | USB D+ (USB mode); NC (I2C mode - not connected) |
| PIN7 | GND | PWR | Power GND |
| PIN8 | VDD | PWR | Power supply, default 5V (3.3V selectable) |
Notes:
- β Module has internal 4.7KΞ© pull-up resistors on I2C lines
- β‘ USB D+/D- pins for USB communication mode
- β’ In I2C mode: PIN5 = DWL (firmware download), PIN6 = NC (not connected)
| BPI-R3 Pin | PN7160 Pin | Function |
|---|---|---|
| Pin 2 (5V) | VDD (PIN8) | Power |
| Pin 6 (GND) | GND (PIN7) | Ground |
| Pin 3 (GPIO 4/SDA) | SDA (PIN2) | I2C Data |
| Pin 5 (GPIO 3/SCL) | SCL (PIN1) | I2C Clock |
| Pin 23 (GPIO 6) | IRQ (PIN3) | Interrupt |
| Pin 21 (GPIO 8) | VEN (PIN4) | Enable |
| Pin 15 (GPIO 65) | DWL (PIN5) | Download |
Connection Summary:
- Power & Ground: Pin 2 (5V) and Pin 6 (GND - near 5V)
- I2C Bus: Pin 3 (SDA) and Pin 5 (SCL) β Hardware I2C (i2c-0)
- Control Signals: Pin 23 (IRQ), Pin 21 (VEN), Pin 15 (DWL)
Add to /etc/config/modules or load manually:
insmod i2c-dev
PN7160 module connected to BPI-R3 via 26-pin header
# Run demo application
nfcDemoApp poll
# Check configuration files
cat /etc/nfc/libnfc-nci.conf
cat /etc/nfc/libnfc-nxp.confThe package includes multiple configuration files:
- libnfc-nxp.conf - Main NXP vendor configuration
- libnfc-nxp-debug.conf - Debug configuration with verbose logging
- libnfc-nci.conf - System configuration
Successful NFC tag detection and reading
You can override config paths using environment variables:
export LIBNFC_NCI_CONF_PATH=/custom/path/PN7160 will NOT respond to standard I2C scan (i2cdetect -y 1). This is normal behavior as the device requires GPIO initialization first.
Ensure libgpiod is installed. Required for modern kernels (6.6+).
The application needs access to:
- I2C device (
/dev/i2c-*) - GPIO devices
- Configuration files in
/etc/nfc/
- Kernels < 6.6: Legacy GPIO sysfs interface
- Kernels >= 6.6: libgpiod required
Solutions:
- β Verify GPIO pins are correctly configured
- β Ensure
libgpiodis installed - β Check I2C interface is enabled
- β Verify hardware connections
- β Check dmesg for kernel messages
Solutions:
- β Verify files exist in
/etc/nfc/ - β Check file permissions
- β Review application logs for path details
Solutions:
- β Ensure all dependencies are selected in menuconfig
- β Clean build:
make package/libnfc-nci/clean - β Check build log:
make package/libnfc-nci/compile V=s
- Create patch file in
patches/directory - Name format:
NNN-description.patch000-099β Configuration patches100-199β Architecture/platform patches200-299β Feature patches900-999β Local/temporary patches
- Patches are applied in numerical order
# Clean and rebuild
make package/libnfc-nci/clean
make package/libnfc-nci/compile V=s
# Test on device
scp bin/packages/*/packages/libnfc-nci*.ipk root@device:/tmp/
ssh root@device "opkg install /tmp/libnfc-nci*.ipk"BSD-3-Clause
- π NXP Official Repository
- π NXP NFC Examples
- π NXP Community Porting Guide - Raspberry Pi 5
- π PN7160 Linux Porting Guide (AN13287)
- π PN7160 Evaluation Kit Quick Start Guide (AN12991)
- π OM27160 Raspberry I2C Troubleshooting
- π Elechouse PN7160 Module
- π Elechouse I2C Quick Guide
For issues related to:
| Issue Type | Get Help |
|---|---|
| π¨ Package building | Check OpenWrt forums |
| π‘ NFC functionality | Refer to NXP documentation |
| π§ PN7160 hardware | Check NXP community forums |