Skip to main content
Visitor II
June 20, 2022
Solved

Read/Write to STmicro ISO 14443-4 tags using X-Nucleo and raspberry pi

  • June 20, 2022
  • 25 replies
  • 7518 views

Hi all,

I'm trying to read and write values to an STmicro tag(ST25TA02KB-D,  ISO 14443-4) using the X-Nucleo board from a python program. I've tried a number of approaches(waveshare pi hat, standalone PN532 modules, using libnfc and adafruit libraries, to list) but none really work and it's honestly a little out of my depth.

Currently I've built the Linux nfc polling demo included with the X-Nucleo board, but even that fails to run(see attached)

If I had resources or python examples using any of these systems, I could probably figure it out, but all the support I've found seems to apply mainly to mifare classic cards.

If anybody has experience or pointers for any of this I'd be quite grateful to hear it!

    This topic has been closed for replies.
    Best answer by JMilk.1

    Thank you! I'm a junior EE mostly dealing with hardware, but we're tagging in one of our developers to assist, so hopefully that'll be less of an issue.

    What we're trying to do is automate the process of reading the memory and writing a short text file- essentially a model number. Unfortunately we're locked into the ST25TA at this point, and revising the board isn't a possibility, though there are some alternative options to interface with it, namely a waveshare PN532 NFC hat, or a standalone PN532 module.

    Solution update: I've found that NFCpy(https://nfcpy.readthedocs.io/en/latest/topics/get-started.html#installation) has support for T4T tags- we're using the PN532 module connected over UART, and are now able to read and write text to the ST25 tag.

    I'm tagging this as best for anyone doing the same thing in the future, Thank you all for your help!

    25 replies

    JMilk.1Author
    Visitor II
    June 29, 2022

    Ok, So I set a breakpoint at main in the built demo and stepped through- it's looping starting at line 117 as shown below. 0693W00000Nt4TnQAJ.png Running the executable seems to only bring up main.c- and GDB won't open st25r3916.c on it's own. I'm guessing the program jumps to st25r3916.c at some point? But I'm not getting there currently.

    Technical Moderator
    June 29, 2022

    Hi,

    if you do not feel confortable with gdb, I suggest you modify the demoIni() function in demo_polling.c file to add

    platformLog("rfalNfcInitialize err = %d\r\n", err);

    just after err = rfalNfcInitialize(); (line 182)

    If you see err = 4 on the console, this means the IRQ handling is not working properly.

    Rgds

    BT

    JMilk.1Author
    Visitor II
    July 3, 2022

    Thank you, I appreciate that!

    So after adding the line and rebuilding, the code outputs "rfalNfcInitialize err = 36", which crosses to "expected hw do not match" in st_errno.h.

    Technical Moderator
    July 4, 2022

    Hi,

    I think you need to debug into st25r3916CheckChipID() to see what it received as ID register. If it is 0x00 or 0xff then I would suspect one of the SPI connections not working. In any case please share the value of ID variable.

    Best Regards, Ulysses

    Technical Moderator
    July 4, 2022

    Hi,

    can you check which board is being used i.e. X-NUCLEO-NFC05A1 or X-NUCLEO-NFC06A1 and can you check which firmware package is being used i.e STSW-ST25R013 or STSW-ST25R009?

    Does your package contain rfal_rfst25r3911.c or rfal_rfst25r3916.c?

    Rgds

    BT

    JMilk.1Author
    Visitor II
    July 4, 2022

    It's the NFC05A1 with the ST25R013 package, 25r3916. Though I've tried ST25R009 as well, though it returned an error when building.

    How might I debug into the checkchipID function? I'm trying to do a similar platformLog approach currently.

    Technical Moderator
    July 5, 2022

    Hi,

    X-NUCLEO-NFC05A1 is based on ST25R3911B NFC reader IC whereas X-NUCLEO-NFC06A1 is based on ST25R3916 IC which is a different chip with a different chip Id.

    STSW-ST25R013 is designed to run on ST25R3916 (X-NUCLEO-NFC06A1) but not for ST25R3911B (X-NUCLEO-NFC05A1). Therefore, using STSW-ST25R013 with X-NUCLEO-NFC05A1 will cause an error due to incorrect chip.

    If you have a X-NUCLEO-NFC05A1, the corresponding Linux package is STSW-ST25R009.

    Rgds

    BT

    JMilk.1Author
    Visitor II
    July 5, 2022

    Thank you! That was my error, I appreciate it!

    I've tried to build ST25R009 but it keeps throwing the below error, an undefined ref to "pthread_create":

    0693W00000QKU7kQAH.pngMy process was first extracting the zip(.xz) file to the home directory, then running "cmake .." and "make" from within its build folder, similar to ST25R0013, which resulted in the output above.

    After doing some research I updated pthread using apt-get(it was already the latest version), and tried "make -pthread" and "make -lpthread" when building, with no change.

    Technical Moderator
    July 5, 2022

    Hi,

    please check if you have libpthread.so in your file system. Please also share CMakeLists.txt and the generated Makefile. Also share the output of the cmake call.

    Best Regards, Ulysses

    Technical Moderator
    July 5, 2022

    Hi,

    It seems the pthread lib is not included by default

    In .\en.STSW-ST25R009\rfal_v1.3.0\applications\CMakeLists.txt, can you add:

    find_library(LIBPTHREAD_PATH pthread)

    and modify the last line of the file to:

    target_link_libraries(nfcPoller ${PROJECT_LINK_LIBS} ${LIBPTHREAD_PATH})

    This should fix your issue (I cannot test on my side but this should be close to the solution)

    Rgds

    BT

    JMilk.1Author
    Visitor II
    July 5, 2022

    Thank you! After making these revisions the tag was picked up by the NFC Poller! Below is the result:

    0693W00000QKUeAQAX.pngHere is Cmakelists.txt:

    0693W00000QKUeFQAX.pngAnd attached is the makefile>

    I've found functions outside of main.c that support reading and writing- would I just call them in main or are there separate examples to support that? I'd like to dump the contents of a tag, then write to a specific location.

    Technical Moderator
    July 5, 2022

    Hi,

    good job!

    Do you use a T2T or T4T tag? The tag seems to be an ST tag (manufacturer id = 02 in the first byte of the UID). Is it an ST25TA (T4T) or an ST25TN (T2T)?

    T2T uses simple READ/WRITE block commands to access memory location whereas T4T uses ISO7816 commands to select an application and then to select a file and then to read/write a given file.

    Rgds

    BT