<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>NFCのトピックPN7160 error read Mifare Classic</title>
    <link>https://community.nxp.com/t5/NFC/PN7160-error-read-Mifare-Classic/m-p/2074179#M12991</link>
    <description>&lt;P class=""&gt;Good morning,&lt;BR /&gt;I am using the PN7160 chip in a project with an STM32MP157F. I'm working with the libnfc-nci library, but adapted to use libgpiod version 2.x. I'm experiencing an issue when reading a Mifare Classic badge.&lt;BR /&gt;If I enable logging (which introduces some delay), the badge is always read successfully on the first attempt. However, if I disable logging, the badge is only read after several attempts.&lt;/P&gt;&lt;P class=""&gt;Our badge must be read from a protected sector, so authentication is required first.&lt;BR /&gt;I noticed that after the authentication command, I get the following sequence:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;R 0x28 0x60 0x06 0x03  
R 0x28 0x01 0x00 0x01  
R 0x28 0x00 0x00 0x02  
R 0x28 0x40 0x00        -&amp;gt; authentication successful (if it fails, it returns 0x03)  
W 0x28 0x00 0x00 0x03 0x10 0x30 0x04  
R 0x28 0x60 0x06 0x03  
R 0x28 0x01 0x00 0x01  
R 0x28 0x00 0x00 0x12  
R                        -&amp;gt; sector 0 block 1  &lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;When logging is enabled, there is a delay of about 6 ms between these two steps:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;R 0x28 0x40 0x00  
W 0x28 0x00 0x00 0x03 0x10 0x30 0x04  &lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;However, without logging, just 1 ms later a different write is triggered that breaks the sequence:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;W 0x28 0x21 0x06 0x01 0x01  &lt;/LI-CODE&gt;&lt;P class=""&gt;I don't understand why this happens. Besides introducing a manual delay in my reader application, I would like to understand the root cause more deeply.&lt;BR /&gt;I’m attaching two captures from a logic analyzer showing the described behavior.&lt;/P&gt;&lt;P class=""&gt;Thank you&lt;BR /&gt;&lt;BR /&gt;M.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 04 Apr 2025 09:20:06 GMT</pubDate>
    <dc:creator>amatteo78</dc:creator>
    <dc:date>2025-04-04T09:20:06Z</dc:date>
    <item>
      <title>PN7160 error read Mifare Classic</title>
      <link>https://community.nxp.com/t5/NFC/PN7160-error-read-Mifare-Classic/m-p/2074179#M12991</link>
      <description>&lt;P class=""&gt;Good morning,&lt;BR /&gt;I am using the PN7160 chip in a project with an STM32MP157F. I'm working with the libnfc-nci library, but adapted to use libgpiod version 2.x. I'm experiencing an issue when reading a Mifare Classic badge.&lt;BR /&gt;If I enable logging (which introduces some delay), the badge is always read successfully on the first attempt. However, if I disable logging, the badge is only read after several attempts.&lt;/P&gt;&lt;P class=""&gt;Our badge must be read from a protected sector, so authentication is required first.&lt;BR /&gt;I noticed that after the authentication command, I get the following sequence:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;R 0x28 0x60 0x06 0x03  
R 0x28 0x01 0x00 0x01  
R 0x28 0x00 0x00 0x02  
R 0x28 0x40 0x00        -&amp;gt; authentication successful (if it fails, it returns 0x03)  
W 0x28 0x00 0x00 0x03 0x10 0x30 0x04  
R 0x28 0x60 0x06 0x03  
R 0x28 0x01 0x00 0x01  
R 0x28 0x00 0x00 0x12  
R                        -&amp;gt; sector 0 block 1  &lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;When logging is enabled, there is a delay of about 6 ms between these two steps:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;R 0x28 0x40 0x00  
W 0x28 0x00 0x00 0x03 0x10 0x30 0x04  &lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;However, without logging, just 1 ms later a different write is triggered that breaks the sequence:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;W 0x28 0x21 0x06 0x01 0x01  &lt;/LI-CODE&gt;&lt;P class=""&gt;I don't understand why this happens. Besides introducing a manual delay in my reader application, I would like to understand the root cause more deeply.&lt;BR /&gt;I’m attaching two captures from a logic analyzer showing the described behavior.&lt;/P&gt;&lt;P class=""&gt;Thank you&lt;BR /&gt;&lt;BR /&gt;M.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Apr 2025 09:20:06 GMT</pubDate>
      <guid>https://community.nxp.com/t5/NFC/PN7160-error-read-Mifare-Classic/m-p/2074179#M12991</guid>
      <dc:creator>amatteo78</dc:creator>
      <dc:date>2025-04-04T09:20:06Z</dc:date>
    </item>
    <item>
      <title>Re: PN7160 error read Mifare Classic</title>
      <link>https://community.nxp.com/t5/NFC/PN7160-error-read-Mifare-Classic/m-p/2076688#M13015</link>
      <description>&lt;P&gt;Base on your information, it is hard to determine what is the issue. It is better to compare the log with your code together to debug what is it happen.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Apr 2025 05:12:14 GMT</pubDate>
      <guid>https://community.nxp.com/t5/NFC/PN7160-error-read-Mifare-Classic/m-p/2076688#M13015</guid>
      <dc:creator>jimmychan</dc:creator>
      <dc:date>2025-04-09T05:12:14Z</dc:date>
    </item>
    <item>
      <title>Re: PN7160 error read Mifare Classic</title>
      <link>https://community.nxp.com/t5/NFC/PN7160-error-read-Mifare-Classic/m-p/2079295#M13049</link>
      <description>&lt;P&gt;Hi, by checking which debug logs were solving the issue, I discovered that the ones in the file NfccAltI2cTransport.cc were responsible. Inside the Read function, at the beginning and the end, there were these logs:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;NXPLOG_TML_D("%s Enter", __func__);
NXPLOG_TML_D("%s exit", __func__);&lt;/LI-CODE&gt;&lt;P&gt;These are the logs that, somehow, were solving the problem. I’m not exactly sure why, and I’d like to better understand the behavior. So I recreated a function to simulate the same behavior without actually logging:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;void EmulateLogDelay() {
  pthread_mutex_lock(&amp;amp;wait_log_mutex);
  volatile int sum = 0;
  for (int i = 0; i &amp;lt; 100000; ++i) sum += i;
  pthread_mutex_unlock(&amp;amp;wait_log_mutex);
}&lt;/LI-CODE&gt;&lt;P class=""&gt;And now everything works perfectly, reading the badge correctly on the first try every time. Essentially, I had to create a delay — but not just a simple wait. It required a for loop and a pthread_mutex lock, exactly like the original log system does.&lt;/P&gt;&lt;P class=""&gt;Do you have any idea why this happens? What’s going on in that moment that alters the following write behavior? Of course, if I understood the driver logic better, I could probably come up with a cleaner solution — maybe using a semaphore — but first, I need to understand what exactly needs to be awaited.&lt;/P&gt;&lt;P class=""&gt;If you're interested, I’ve published a fork of the libnfc_nxp driver on my repository with support for libgpiod 2.x and this fix included.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Apr 2025 19:09:36 GMT</pubDate>
      <guid>https://community.nxp.com/t5/NFC/PN7160-error-read-Mifare-Classic/m-p/2079295#M13049</guid>
      <dc:creator>amatteo78</dc:creator>
      <dc:date>2025-04-11T19:09:36Z</dc:date>
    </item>
  </channel>
</rss>

