Raspberry Pi setup: ------------------- = I2C communication = To use the I2C communication: - Edit the Raspberry Pi Configuration, go the interfaces pane: enable the I2C interface (disable the SPI and UART interfaces). - Edit /boot/config.txt and make sure the following parameters are set: # Set a fixed core frequency to avoid frequency changes depending on processor load, I2C clock is derived from this one. core_freq=250 # Set Fast mode I2C (400kHz) dtparam=i2c_arm=on,i2x_arm_baudrate=400000 How to build: ------------- Ensure the correct RFAL variant is set in CMakeLists.txt, e.g.: set(RFAL_VARIANT "st25r3916" CACHE STRING "Select the RFAL library") Then Go to the build directory $ mkdir -p linux_demo/build $ cd linux_demo/build Choose the build type: 1. For the Reader/Writer demo: $ cmake .. 2. For the Card Emulation-only demo: $ cmake -DCARD_EMULATION_ONLY=ON .. Then build: $ make How to run from the build folder: --------------------------------- $ sudo ./demo/nfc_demo_ or $ sudo ./demo/nfc_demo__CE Note on the Linux SPI driver: ----------------------------- Check SPI driver version with: $ modinfo spidev With recent Linux kernel and SPI driver, you may encounter "Failed to get line handle for GPIO pin8 (errno 16)" This occurs with SPI driver v5.4.51, because it reserves GPIO8 for SPI0 CS0. This prevents the nfc_demo_ to control this GPIO itself. To overcome this, tell the SPI driver to use another GPIO to control the Chip Select signal. To do so on the Raspberry Pi, add the following to /boot/config.txt: dtoverlay spi0-cs,cs0_pin=6 This was not needed for SPI driver v4.19.97. Another issue can occur with SPI driver v5.10.11-v8+: The kernel sets up SPI0 and SPI1. You may encounter "Failed to get line handle for GPIO pin7 (errno 16)" GPIO 7 is used by SPI1 CE1, preventing to use it by the NFC demo receiving interrupts on GPIO ST25R_INT_PIN. To overcome this, tell the SPI driver to setup only one SPI bus. To do so on the Raspberry Pi, add the following to /boot/config.txt: dtoverlay spi0-1cs or tell it to use another GPIO to control the Chip Select signal. Add the following to /boot/config.txt: dtoverlay spi0-1cs,cs0_pin=6 A convenient way to check GPIO configuration is using the shell command $ gpio readall $ gpio readall +-----+-----+---------+------+---+---Pi 3B--+---+------+---------+-----+-----+ | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM | +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+ | | | 3.3v | | | 1 || 2 | | | 5v | | | | 2 | 8 | SDA.1 | IN | 1 | 3 || 4 | | | 5v | | | | 3 | 9 | SCL.1 | IN | 1 | 5 || 6 | | | 0v | | | | 4 | 7 | GPIO. 7 | IN | 1 | 7 || 8 | 1 | IN | TxD | 15 | 14 | | | | 0v | | | 9 || 10 | 1 | IN | RxD | 16 | 15 | | 17 | 0 | GPIO. 0 | IN | 0 | 11 || 12 | 0 | IN | GPIO. 1 | 1 | 18 | | 27 | 2 | GPIO. 2 | IN | 0 | 13 || 14 | | | 0v | | | | 22 | 3 | GPIO. 3 | IN | 0 | 15 || 16 | 0 | IN | GPIO. 4 | 4 | 23 | | | | 3.3v | | | 17 || 18 | 0 | IN | GPIO. 5 | 5 | 24 | | 10 | 12 | MOSI | ALT0 | 0 | 19 || 20 | | | 0v | | | | 9 | 13 | MISO | ALT0 | 0 | 21 || 22 | 0 | IN | GPIO. 6 | 6 | 25 | | 11 | 14 | SCLK | ALT0 | 0 | 23 || 24 | 1 | OUT | CE0 | 10 | 8 | | | | 0v | | | 25 || 26 | 0 | IN | CE1 | 11 | 7 | // Pay attention to 'CE1' set on pin 7 with direction 'IN' | 0 | 30 | SDA.0 | IN | 1 | 27 || 28 | 1 | IN | SCL.0 | 31 | 1 | | 5 | 21 | GPIO.21 | IN | 1 | 29 || 30 | | | 0v | | | | 6 | 22 | GPIO.22 | IN | 1 | 31 || 32 | 0 | IN | GPIO.26 | 26 | 12 | | 13 | 23 | GPIO.23 | IN | 0 | 33 || 34 | | | 0v | | | | 19 | 24 | GPIO.24 | IN | 0 | 35 || 36 | 0 | IN | GPIO.27 | 27 | 16 | | 26 | 25 | GPIO.25 | IN | 0 | 37 || 38 | 0 | IN | GPIO.28 | 28 | 20 | | | | 0v | | | 39 || 40 | 1 | IN | GPIO.29 | 29 | 21 | +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+ | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM | +-----+-----+---------+------+---+---Pi 3B--+---+------+---------+-----+-----+ This is a working configuration set with: dtparam=spi=off dtoverlay=spi0-1cs Debugging: ---------- $ cmake -DCMAKE_BUILD_TYPE=Debug .. $ make sudo gdbtui ./demo/nfc_demo_ or sudo gdbtui ./demo/nfc_demo__CE to set a breakpoint: b b : r to run s to step into the code (go down into the function) up to go one level up n to go to next line bt to show backtrace CTRL-C to break c to continue info b to list the breakpoints del n to delete breakpoint