<?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>topic LPI2C protection in S32 SDK</title>
    <link>https://community.nxp.com/t5/S32-SDK/LPI2C-protection/m-p/1152360#M1897</link>
    <description>&lt;P&gt;I am making a large number of i2c calls.&amp;nbsp; Sometimes this works okay, but often the bus will hang and the program gets stuck.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There should not be any gaps in the data below.&amp;nbsp; My theory is that some interrupt is occuring, and if the interrupt occurs at some unfortunate moment, the i2c traffic gets messed up:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="m_mishrikey_0-1599879699307.png" style="width: 680px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/124979i867863D1F1D52E9A/image-dimensions/680x311?v=v2" width="680" height="311" role="button" title="m_mishrikey_0-1599879699307.png" alt="m_mishrikey_0-1599879699307.png" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;m_mishrikey_0-1599879699307.png&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;So I wanted to try protecting the i2c call by disabling unrelated interrupts, then reenabling them.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ENABLE_INTERRUPTS() and DISABLE_INTERRUPTS() set primask, which would not be good because the i2c still needs to function.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then I thought I could use BASEPRI, but I am not sure how to set this through the SDK (or otherwise).&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Related question - I was experimenting with blocking and non-blocking variants of the receive code.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="m_mishrikey_1-1599880321567.png" style="width: 938px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/124980i58B6AA7831588287/image-dimensions/938x466?v=v2" width="938" height="466" role="button" title="m_mishrikey_1-1599880321567.png" alt="m_mishrikey_1-1599880321567.png" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;m_mishrikey_1-1599880321567.png&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I have blockng and non-blocking versions of both the send and the receive.&amp;nbsp; If I understand correctly, the non-blocking still blocks the program in a sense, but gives you the option to do something inside the {} brackets while you're waiting.&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;I wonder if there is a safer way to handle this code.&amp;nbsp; If anything happens to the bus, you will get stuck in the while busy loop forever.&amp;nbsp; But if you use the blocking calls, and change the max wait time to something finite, you should return something to the calling function so they know to retry.&amp;nbsp; is there a try/catch way to handle these i2c calls?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 12 Sep 2020 03:21:24 GMT</pubDate>
    <dc:creator>m_mishrikey</dc:creator>
    <dc:date>2020-09-12T03:21:24Z</dc:date>
    <item>
      <title>LPI2C protection</title>
      <link>https://community.nxp.com/t5/S32-SDK/LPI2C-protection/m-p/1152360#M1897</link>
      <description>&lt;P&gt;I am making a large number of i2c calls.&amp;nbsp; Sometimes this works okay, but often the bus will hang and the program gets stuck.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There should not be any gaps in the data below.&amp;nbsp; My theory is that some interrupt is occuring, and if the interrupt occurs at some unfortunate moment, the i2c traffic gets messed up:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="m_mishrikey_0-1599879699307.png" style="width: 680px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/124979i867863D1F1D52E9A/image-dimensions/680x311?v=v2" width="680" height="311" role="button" title="m_mishrikey_0-1599879699307.png" alt="m_mishrikey_0-1599879699307.png" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;m_mishrikey_0-1599879699307.png&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;So I wanted to try protecting the i2c call by disabling unrelated interrupts, then reenabling them.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ENABLE_INTERRUPTS() and DISABLE_INTERRUPTS() set primask, which would not be good because the i2c still needs to function.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then I thought I could use BASEPRI, but I am not sure how to set this through the SDK (or otherwise).&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Related question - I was experimenting with blocking and non-blocking variants of the receive code.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="m_mishrikey_1-1599880321567.png" style="width: 938px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/124980i58B6AA7831588287/image-dimensions/938x466?v=v2" width="938" height="466" role="button" title="m_mishrikey_1-1599880321567.png" alt="m_mishrikey_1-1599880321567.png" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;m_mishrikey_1-1599880321567.png&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I have blockng and non-blocking versions of both the send and the receive.&amp;nbsp; If I understand correctly, the non-blocking still blocks the program in a sense, but gives you the option to do something inside the {} brackets while you're waiting.&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;I wonder if there is a safer way to handle this code.&amp;nbsp; If anything happens to the bus, you will get stuck in the while busy loop forever.&amp;nbsp; But if you use the blocking calls, and change the max wait time to something finite, you should return something to the calling function so they know to retry.&amp;nbsp; is there a try/catch way to handle these i2c calls?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 12 Sep 2020 03:21:24 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S32-SDK/LPI2C-protection/m-p/1152360#M1897</guid>
      <dc:creator>m_mishrikey</dc:creator>
      <dc:date>2020-09-12T03:21:24Z</dc:date>
    </item>
    <item>
      <title>Re: LPI2C protection</title>
      <link>https://community.nxp.com/t5/S32-SDK/LPI2C-protection/m-p/1152477#M1898</link>
      <description>&lt;P&gt;Follow-up question.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does S32K SDK have some form of deadlock recovery such as described by TomE here?&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.nxp.com/t5/i-MX-Processors/I2C-reset/m-p/253182" target="_blank"&gt;https://community.nxp.com/t5/i-MX-Processors/I2C-reset/m-p/253182&lt;/A&gt;&lt;/P&gt;&lt;P&gt;There is also a nice description of what to try here:&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.nxp.com/t5/Kinetis-Microcontrollers/I2C-device-dead-lock-recovery/m-p/304368" target="_blank"&gt;https://community.nxp.com/t5/Kinetis-Microcontrollers/I2C-device-dead-lock-recovery/m-p/304368&lt;/A&gt;&lt;/P&gt;&lt;P&gt;It would be great if the SDK already had what is needed!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 13 Sep 2020 21:14:11 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S32-SDK/LPI2C-protection/m-p/1152477#M1898</guid>
      <dc:creator>m_mishrikey</dc:creator>
      <dc:date>2020-09-13T21:14:11Z</dc:date>
    </item>
    <item>
      <title>Re: LPI2C protection</title>
      <link>https://community.nxp.com/t5/S32-SDK/LPI2C-protection/m-p/1154114#M1914</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;Instead of the LPI2C_DRV_MasterGetTransferStatus() function, you can use a callback function which is then called from the LPI2C_DRV_MasterIRQHandler(). &lt;/P&gt;
&lt;P&gt;The callback function takes &lt;STRONG&gt;i2c_master_event_t &lt;/STRONG&gt;as an argument.&lt;/P&gt;
&lt;P&gt;callbacks.h&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="danielmartynek_0-1600251361896.png" style="width: 645px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/125294i603620C84FADF30B/image-dimensions/645x202?v=v2" width="645" height="202" role="button" title="danielmartynek_0-1600251361896.png" alt="danielmartynek_0-1600251361896.png" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;danielmartynek_0-1600251361896.png&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;If using a higher interrupt level for the LPI2C is not enough, you can use the BASEPRI.&lt;/P&gt;
&lt;P&gt;The BASEPRI register is in the same format as the interrupt priority registers.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="danielmartynek_1-1600252132482.png" style="width: 492px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/125296iBA29CC69C3DA63B6/image-dimensions/492x127?v=v2" width="492" height="127" role="button" title="danielmartynek_1-1600252132482.png" alt="danielmartynek_1-1600252132482.png" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;danielmartynek_1-1600252132482.png&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;For example, interrupt priority level 2:&lt;/P&gt;
&lt;P&gt;S32_NVIC-&amp;gt;IP[xx] = 0x20;&lt;/P&gt;
&lt;P&gt;To set BASEPRI to the same level use something like this:&lt;/P&gt;
&lt;P&gt;__asm__("MOV R0, 0x20");&lt;BR /&gt;__asm__("MSR BASEPRI, R0");&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Daniel&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Sep 2020 10:47:27 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S32-SDK/LPI2C-protection/m-p/1154114#M1914</guid>
      <dc:creator>danielmartynek</dc:creator>
      <dc:date>2020-09-16T10:47:27Z</dc:date>
    </item>
    <item>
      <title>Re: LPI2C protection</title>
      <link>https://community.nxp.com/t5/S32-SDK/LPI2C-protection/m-p/1154119#M1915</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;The LPI2C module does not have such a recovery feature and therefore the SDK does not support it either.&lt;/P&gt;
&lt;P&gt;It would need to be a function of the pin_mux driver, I guess, as it would be performed with GPIOs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can refer to this AN4803 I2C Non-Blocking Communication as well.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.nxp.com/docs/en/application-note/AN4803.pdf" target="_blank"&gt;https://www.nxp.com/docs/en/application-note/AN4803.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;I2C restore function definition&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Daniel&lt;/P&gt;</description>
      <pubDate>Wed, 16 Sep 2020 10:55:31 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S32-SDK/LPI2C-protection/m-p/1154119#M1915</guid>
      <dc:creator>danielmartynek</dc:creator>
      <dc:date>2020-09-16T10:55:31Z</dc:date>
    </item>
  </channel>
</rss>

