<?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 K22 bug in MK22F12.h for SPI configurations in Kinetis Software Development Kit</title>
    <link>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/K22-bug-in-MK22F12-h-for-SPI-configurations/m-p/612254#M6340</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;When you use the project generator to make a MK22F12 project, I get the following compiler warnings (though serious):&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;array subscript is above array bounds [-Warray-bounds]&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Which is pointing to fsl_dspi.c:&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class="language-none line-numbers"&gt;&lt;CODE&gt;#if defined(SPI0)
void SPI0_DriverIRQHandler(void)
{
 assert(g_dspiHandle[0]);
 DSPI_CommonIRQHandler(SPI0, g_dspiHandle[0]);
}
#endif
#if defined(SPI1)
void SPI1_DriverIRQHandler(void)
{
 assert(g_dspiHandle[1]);
 DSPI_CommonIRQHandler(SPI1, g_dspiHandle[1]);
}
#endif
#if defined(SPI2)
void SPI2_DriverIRQHandler(void)
{
 assert(g_dspiHandle[2]);
 DSPI_CommonIRQHandler(SPI2, g_dspiHandle[2]);
}
#endif&lt;SPAN class="line-numbers-rows"&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Lines 12 and 19 are the issue, because these are referencing elements 1 and 2 of the g_dspiHandle[] array, but it is only defined in that same file as&amp;nbsp;static void *g_dspiHandle[FSL_FEATURE_SOC_DSPI_COUNT]; and FSL_FEATURE_SOC_DSPI_COUNT is defined elsewhere in the MK22F12_features.h file as 1! &amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In other words, there is only one SPI block (SPI0) on this chip, so the SPI1 and SPI2 features should not be defined, and this error will go away. &amp;nbsp;I have confirmed that eliminating these variables (SPI1, SPI2, etc.) in MK22F12.h fixes the issue.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please fix in future versions, thanks.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Joel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 28 Oct 2016 15:19:13 GMT</pubDate>
    <dc:creator>joelwigton</dc:creator>
    <dc:date>2016-10-28T15:19:13Z</dc:date>
    <item>
      <title>K22 bug in MK22F12.h for SPI configurations</title>
      <link>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/K22-bug-in-MK22F12-h-for-SPI-configurations/m-p/612254#M6340</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;When you use the project generator to make a MK22F12 project, I get the following compiler warnings (though serious):&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;array subscript is above array bounds [-Warray-bounds]&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Which is pointing to fsl_dspi.c:&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class="language-none line-numbers"&gt;&lt;CODE&gt;#if defined(SPI0)
void SPI0_DriverIRQHandler(void)
{
 assert(g_dspiHandle[0]);
 DSPI_CommonIRQHandler(SPI0, g_dspiHandle[0]);
}
#endif
#if defined(SPI1)
void SPI1_DriverIRQHandler(void)
{
 assert(g_dspiHandle[1]);
 DSPI_CommonIRQHandler(SPI1, g_dspiHandle[1]);
}
#endif
#if defined(SPI2)
void SPI2_DriverIRQHandler(void)
{
 assert(g_dspiHandle[2]);
 DSPI_CommonIRQHandler(SPI2, g_dspiHandle[2]);
}
#endif&lt;SPAN class="line-numbers-rows"&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Lines 12 and 19 are the issue, because these are referencing elements 1 and 2 of the g_dspiHandle[] array, but it is only defined in that same file as&amp;nbsp;static void *g_dspiHandle[FSL_FEATURE_SOC_DSPI_COUNT]; and FSL_FEATURE_SOC_DSPI_COUNT is defined elsewhere in the MK22F12_features.h file as 1! &amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In other words, there is only one SPI block (SPI0) on this chip, so the SPI1 and SPI2 features should not be defined, and this error will go away. &amp;nbsp;I have confirmed that eliminating these variables (SPI1, SPI2, etc.) in MK22F12.h fixes the issue.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please fix in future versions, thanks.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Joel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Oct 2016 15:19:13 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/K22-bug-in-MK22F12-h-for-SPI-configurations/m-p/612254#M6340</guid>
      <dc:creator>joelwigton</dc:creator>
      <dc:date>2016-10-28T15:19:13Z</dc:date>
    </item>
    <item>
      <title>Re: K22 bug in MK22F12.h for SPI configurations</title>
      <link>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/K22-bug-in-MK22F12-h-for-SPI-configurations/m-p/612255#M6341</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Joel.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for your feedback.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;MKxx_features.h is a file, which contains SoC module features and dspi driver is the same for most of Kinetis MCUs.&lt;/P&gt;&lt;P&gt;So in this case we don´t avoid this warning.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best Regards,&lt;/P&gt;&lt;P&gt;Iva&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 Oct 2016 18:09:58 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/K22-bug-in-MK22F12-h-for-SPI-configurations/m-p/612255#M6341</guid>
      <dc:creator>ivadorazinova</dc:creator>
      <dc:date>2016-10-31T18:09:58Z</dc:date>
    </item>
    <item>
      <title>Re: K22 bug in MK22F12.h for SPI configurations</title>
      <link>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/K22-bug-in-MK22F12-h-for-SPI-configurations/m-p/612256#M6342</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;this bug has another side effect.&lt;/P&gt;&lt;P&gt;In my case, I wanted to use SPI2.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Configuring the SPI2 interface leads to a HardFault, caused itself by a memory access to the main configuration register (SPI2-&amp;gt;MCR).&amp;nbsp;&lt;/P&gt;&lt;P&gt;The chip reacts so because SPI2 is not clocked, even though this is the first action performed by &lt;EM&gt;DSPI_MasterInit&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To be clocked, the driver tries to recognise the SPI instance first:&lt;/P&gt;&lt;PRE class="language-c line-numbers"&gt;&lt;CODE&gt;uint32_t &lt;SPAN class="token function"&gt;DSPI_GetInstance&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;SPI_Type &lt;SPAN class="operator token"&gt;*&lt;/SPAN&gt;base&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; uint32_t instance&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp; &lt;SPAN class="comment token"&gt;/* Find the instance index from base address mappings. */&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;instance &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt; instance &lt;SPAN class="operator token"&gt;&amp;lt;&lt;/SPAN&gt; FSL_FEATURE_SOC_DSPI_COUNT&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt; instance&lt;SPAN class="operator token"&gt;++&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;s_dspiBases&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;instance&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; base&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;break&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp; &lt;SPAN class="token function"&gt;assert&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;instance &lt;SPAN class="operator token"&gt;&amp;lt;&lt;/SPAN&gt; FSL_FEATURE_SOC_DSPI_COUNT&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; instance&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;As pointed by Joel,&amp;nbsp; FSL_FEATURE_SOC_DSPI_COUNT is set to 1.&amp;nbsp; So this function&amp;nbsp; exits the loop before trying to&amp;nbsp; recognize the SPI instance.&lt;/P&gt;&lt;P&gt;In my case, it gets even worse: I use the NDEBUG parameters, so the assert functions is not doing anything.&amp;nbsp; So even if the function failed to recognized a valid SPI instance, it returns the value 0, which &lt;STRONG&gt;&lt;EM&gt;is &lt;/EM&gt;&lt;/STRONG&gt;a valid SPI instance. &lt;/P&gt;&lt;P&gt;This then leads to enable the wrong SPI clock.&amp;nbsp; Which will crash the chip when the code tries to go further with the initialization.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Since there is 3 SPI intstance on the chip I suggest to correct FSL_FEATURE_SOC_DSPI_COUNT to value 3.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Feb 2017 10:49:43 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/K22-bug-in-MK22F12-h-for-SPI-configurations/m-p/612256#M6342</guid>
      <dc:creator>guylejeune</dc:creator>
      <dc:date>2017-02-15T10:49:43Z</dc:date>
    </item>
  </channel>
</rss>

