1 (edited by delerrok 2016-05-09 17:12:45)

Topic: [SOLVED]libnfc works on raspberry pi 2, doesn't work on raspberry pi 3

Here's a strange one.
We're upgrading our Raspberry Pi 2s to Raspberry Pi 3s and everything works except for communication with the iTead NFC boards we're using over serial.

So my all the libnfc-bin programs work unmodified on the Pi 2 but when I use the same SD card(!) on a Pi 3, libnfc is no longer able to communicate:

pi@tp-1 ~ $ nfc-list
nfc-list uses libnfc 1.7.1
error    libnfc.driver.pn532_uart    pn53x_check_communication error
nfc-list: ERROR: Unable to open NFC device: pn532_uart:/dev/ttyAMA0
pi@tp-1 ~ $ nfc-scan-device -i -v
nfc-scan-device uses libnfc 1.7.1
1 NFC device(s) found:
error    libnfc.driver.pn532_uart    pn53x_check_communication error
nfc_open failed for pn532_uart:/dev/ttyAMA0

I have:

pi@tp-1 ~ $ cat /etc/nfc/devices.d/pn532_uart_on_rpi.conf
name = "PN532 board via UART"
connstring = pn532_uart:/dev/ttyAMA0
allow_intrusive_scan = true
pi@tp-1 ~ $

When I "strace nfc-list" I get the following in the end:

open("/dev/ttyAMA0", O_RDWR|O_NOCTTY|O_NONBLOCK) = 3
ioctl(3, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, {B9600 opost isig icanon echo ...}) = 0
ioctl(3, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, {B9600 opost isig icanon echo ...}) = 0
ioctl(3, SNDCTL_TMR_START or SNDRV_TIMER_IOCTL_TREAD or TCSETS, {B0 -opost -isig -icanon -echo ...}) = 0
ioctl(3, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, {B0 -opost -isig -icanon -echo ...}) = 0
nanosleep({0, 50000000}, NULL)          = 0
ioctl(3, TCFLSH, 0)                     = 0
ioctl(3, FIONREAD, [0])                 = 0
ioctl(3, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, {B0 -opost -isig -icanon -echo ...}) = 0
ioctl(3, SNDCTL_TMR_STOP or SNDRV_TIMER_IOCTL_GINFO or TCSETSW, {B115200 -opost -isig -icanon -echo ...}) = 0
ioctl(3, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, {B115200 -opost -isig -icanon -echo ...}) = 0
pipe([4, 5])                            = 0
ioctl(3, TCFLSH, 0)                     = 0
ioctl(3, FIONREAD, [0])                 = 0
write(3, "UU\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 16) = 16
ioctl(3, TCFLSH, 0)                     = 0
ioctl(3, FIONREAD, [0])                 = 0
write(3, "\0\0\377\3\375\324\24\1\27\0", 10) = 10
select(4, [3], NULL, NULL, {1, 0})      = 0 (Timeout)
write(2, "error\tlibnfc.driver.pn532_uart\t", 31error    libnfc.driver.pn532_uart    ) = 31
write(2, "pn53x_check_communication error", 31pn53x_check_communication error) = 31
write(2, "\n", 1
)                       = 1
ioctl(3, TCFLSH, 0)                     = 0
ioctl(3, FIONREAD, [0])                 = 0
write(3, "\0\0\377\3\375\324R\0\332\0", 10) = 10
select(4, [3], NULL, NULL, {0, 350000}) = 0 (Timeout)
ioctl(3, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, {B115200 -opost -isig -icanon -echo ...}) = 0
ioctl(3, SNDCTL_TMR_START or SNDRV_TIMER_IOCTL_TREAD or TCSETS, {B9600 opost isig icanon echo ...}) = 0
ioctl(3, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, {B9600 opost isig icanon echo ...}) = 0
close(3)                                = 0
close(4)                                = 0
close(5)                                = 0
write(2, "nfc-list: ", 10nfc-list: )              = 10
write(2, "ERROR: Unable to open NFC device"..., 57ERROR: Unable to open NFC device: pn532_uart:/dev/ttyAMA0) = 57
write(2, "\n", 1
)                       = 1
exit_group(0)                           = ?
+++ exited with 0 +++

which indicates it can open and write to /dev/ttyAMA0, but can't seem to read.

In contrast, here is the same section of the strace output on the Pi 2:

open("/dev/ttyAMA0", O_RDWR|O_NOCTTY|O_NONBLOCK) = 3
ioctl(3, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, {B115200 -opost -isig -icanon -echo ...}) = 0
ioctl(3, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, {B115200 -opost -isig -icanon -echo ...}) = 0
ioctl(3, SNDCTL_TMR_START or SNDRV_TIMER_IOCTL_TREAD or TCSETS, {B0 -opost -isig -icanon -echo ...}) = 0
ioctl(3, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, {B0 -opost -isig -icanon -echo ...}) = 0
nanosleep({0, 50000000}, NULL)          = 0
ioctl(3, TCFLSH, 0)                     = 0
ioctl(3, FIONREAD, [0])                 = 0
ioctl(3, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, {B0 -opost -isig -icanon -echo ...}) = 0
ioctl(3, SNDCTL_TMR_STOP or SNDRV_TIMER_IOCTL_GINFO or TCSETSW, {B115200 -opost -isig -icanon -echo ...}) = 0
ioctl(3, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, {B115200 -opost -isig -icanon -echo ...}) = 0
pipe([4, 5])                            = 0
ioctl(3, TCFLSH, 0)                     = 0
ioctl(3, FIONREAD, [0])                 = 0
write(3, "UU\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 16) = 16
ioctl(3, TCFLSH, 0)                     = 0
ioctl(3, FIONREAD, [0])                 = 0
write(3, "\0\0\377\3\375\324\24\1\27\0", 10) = 10
select(4, [3], NULL, NULL, {1, 0})      = 1 (in [3], left {0, 997713})
ioctl(3, FIONREAD, [6])                 = 0
read(3, "\0\0\377\0\377\0", 6)          = 6

Does anyone have any clues?

Re: [SOLVED]libnfc works on raspberry pi 2, doesn't work on raspberry pi 3

I was able to figure out the problem.  Turns out the Raspberry Pi 3 uses the first serial port for its integrated Bluetooth!  There are several ways to get around the problem, knowing this.
For now and for my purposes, simply disabling bluetooth did the trick:

add "dtoverlay=pi3-disable-bt" to /boot/config.txt
and then "sudo systemctl disable hciuart" to disable to the bluetooth service.  Reboot and NFC through /dev/ttyAMA0 works again!