<?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 Discrepancy in values when struct is accessed via a pointer. in i.MX RT Crossover MCUs</title>
    <link>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/Discrepancy-in-values-when-struct-is-accessed-via-a-pointer/m-p/1840234#M29655</link>
    <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;I am using the iMXRT1064 processor on a custom board with an eMMC card fitted&lt;BR /&gt;&lt;BR /&gt;MCUXpresso is the development environment.&lt;BR /&gt;&lt;BR /&gt;I am using the file fsl_mmc.c from the SDK for library functions to access the eMMC card.&lt;/P&gt;&lt;P&gt;The eMMC card descriptor is a C struct allocated at a certain memory address.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;mmc_card_t g_mmc;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The descriptor is initialised by calling the library function, &lt;STRONG&gt;MMC_Init(mmc_card_t *card)&lt;/STRONG&gt; passing a pointer to the struct.&lt;BR /&gt;&lt;BR /&gt;After the return from MMC_Init, the fields of the struct have "bad" values, eg blockSize is 17017344 instead of 512.&lt;/P&gt;&lt;P&gt;Inside MMC_Init, when the struct is accessed directly (as a test), most of the fields show different values than when it is accessed via the pointer; so that the initialisation done via the pointer is placing bad values into the actual struct in memory.&lt;BR /&gt;&lt;BR /&gt;The attached file &lt;STRONG&gt;g_mmc.docx&lt;/STRONG&gt; shows two screenshots taken just before the return from MMC_Init. This shows the "good" values via the pointer, but "bad" values in the actual memory locations.&lt;BR /&gt;( In successive executions, the "bad" values are always the same.)&lt;BR /&gt;&lt;BR /&gt;NOTE. For those familiar with &lt;STRONG&gt;mmc_card_t,&amp;nbsp;&lt;/STRONG&gt; I experimented by moving one field to the end of the struct.&lt;BR /&gt;&lt;BR /&gt;I have tried various alignments of &lt;STRONG&gt;g_mmc&lt;/STRONG&gt; but without success.&lt;BR /&gt;&lt;BR /&gt;Can anyone suggest how accessing the same struct directly and via a pointer can yield different values?&lt;BR /&gt;&lt;BR /&gt;Thank you in anticipation.&lt;BR /&gt;&lt;BR /&gt;Damien&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 03 Apr 2024 16:11:36 GMT</pubDate>
    <dc:creator>dmckeever</dc:creator>
    <dc:date>2024-04-03T16:11:36Z</dc:date>
    <item>
      <title>Discrepancy in values when struct is accessed via a pointer.</title>
      <link>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/Discrepancy-in-values-when-struct-is-accessed-via-a-pointer/m-p/1840234#M29655</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;I am using the iMXRT1064 processor on a custom board with an eMMC card fitted&lt;BR /&gt;&lt;BR /&gt;MCUXpresso is the development environment.&lt;BR /&gt;&lt;BR /&gt;I am using the file fsl_mmc.c from the SDK for library functions to access the eMMC card.&lt;/P&gt;&lt;P&gt;The eMMC card descriptor is a C struct allocated at a certain memory address.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;mmc_card_t g_mmc;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The descriptor is initialised by calling the library function, &lt;STRONG&gt;MMC_Init(mmc_card_t *card)&lt;/STRONG&gt; passing a pointer to the struct.&lt;BR /&gt;&lt;BR /&gt;After the return from MMC_Init, the fields of the struct have "bad" values, eg blockSize is 17017344 instead of 512.&lt;/P&gt;&lt;P&gt;Inside MMC_Init, when the struct is accessed directly (as a test), most of the fields show different values than when it is accessed via the pointer; so that the initialisation done via the pointer is placing bad values into the actual struct in memory.&lt;BR /&gt;&lt;BR /&gt;The attached file &lt;STRONG&gt;g_mmc.docx&lt;/STRONG&gt; shows two screenshots taken just before the return from MMC_Init. This shows the "good" values via the pointer, but "bad" values in the actual memory locations.&lt;BR /&gt;( In successive executions, the "bad" values are always the same.)&lt;BR /&gt;&lt;BR /&gt;NOTE. For those familiar with &lt;STRONG&gt;mmc_card_t,&amp;nbsp;&lt;/STRONG&gt; I experimented by moving one field to the end of the struct.&lt;BR /&gt;&lt;BR /&gt;I have tried various alignments of &lt;STRONG&gt;g_mmc&lt;/STRONG&gt; but without success.&lt;BR /&gt;&lt;BR /&gt;Can anyone suggest how accessing the same struct directly and via a pointer can yield different values?&lt;BR /&gt;&lt;BR /&gt;Thank you in anticipation.&lt;BR /&gt;&lt;BR /&gt;Damien&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Apr 2024 16:11:36 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/Discrepancy-in-values-when-struct-is-accessed-via-a-pointer/m-p/1840234#M29655</guid>
      <dc:creator>dmckeever</dc:creator>
      <dc:date>2024-04-03T16:11:36Z</dc:date>
    </item>
    <item>
      <title>Re: Discrepancy in values when struct is accessed via a pointer.</title>
      <link>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/Discrepancy-in-values-when-struct-is-accessed-via-a-pointer/m-p/1840606#M29666</link>
      <description>&lt;P&gt;The behavior is even more bizarre.&lt;/P&gt;&lt;P&gt;Example.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;mmc_card_t *card = (mmc_card_t*)&amp;amp;g_mmc;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;Execute the following statement, with a breakpoint on the second line:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;MMCdeviceSectors = g_mmc.userPartitionBlocks;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Success = true;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Expression windows in the debugger show that the value of &lt;STRONG&gt;g_mmc.userPartitionBlocks&lt;/STRONG&gt; shown in the struct (ie 7733248) is not being assigned to the variable &lt;STRONG&gt;MMCdeviceSectors &lt;/STRONG&gt;( ie. 131072)&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;The value assigned (131072) is the "bad" value&amp;nbsp; shown when the &lt;STRONG&gt;g_mmc&lt;/STRONG&gt; struct is accessed via the&amp;nbsp; pointer &lt;STRONG&gt;card .&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;The attached file Expression Discrepancy.docx shows this with screenshots.&lt;BR /&gt;&lt;BR /&gt;Help please!&lt;/P&gt;&lt;P&gt;Damien&lt;/P&gt;</description>
      <pubDate>Thu, 04 Apr 2024 10:55:26 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/Discrepancy-in-values-when-struct-is-accessed-via-a-pointer/m-p/1840606#M29666</guid>
      <dc:creator>dmckeever</dc:creator>
      <dc:date>2024-04-04T10:55:26Z</dc:date>
    </item>
    <item>
      <title>Re: Discrepancy in values when struct is accessed via a pointer.</title>
      <link>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/Discrepancy-in-values-when-struct-is-accessed-via-a-pointer/m-p/1844693#M29744</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/150957"&gt;@dmckeever&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;May I have the IDE tool version? From here it seems ok. Please kindly refer to the following for details.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Kan_Li_0-1712803430293.png" style="width: 715px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/273036i34AC02D997E5D75E/image-dimensions/715x336?v=v2" width="715" height="336" role="button" title="Kan_Li_0-1712803430293.png" alt="Kan_Li_0-1712803430293.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Kan_Li_1-1712803465906.png" style="width: 716px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/273037i3471EE3F9AC22321/image-dimensions/716x341?v=v2" width="716" height="341" role="button" title="Kan_Li_1-1712803465906.png" alt="Kan_Li_1-1712803465906.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Kan_Li_2-1712803537529.png" style="width: 527px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/273039i9E0A2F7B159D2302/image-dimensions/527x282?v=v2" width="527" height="282" role="button" title="Kan_Li_2-1712803537529.png" alt="Kan_Li_2-1712803537529.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your IDE version is lower than above, maybe you have to update it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope that helps,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have a great day,&lt;BR /&gt;Kan&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;-------------------------------------------------------------------------------&lt;BR /&gt;Note:&lt;BR /&gt;- If this post answers your question, please click the "Mark Correct" button. Thank you!&lt;BR /&gt;- We are following threads for 7 weeks after the last post, later replies are ignored&lt;BR /&gt;Please open a new thread and refer to the closed one, if you have a related question at a later point in time.&lt;BR /&gt;-------------------------------------------------------------------------------&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Apr 2024 02:46:32 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/Discrepancy-in-values-when-struct-is-accessed-via-a-pointer/m-p/1844693#M29744</guid>
      <dc:creator>Kan_Li</dc:creator>
      <dc:date>2024-04-11T02:46:32Z</dc:date>
    </item>
  </channel>
</rss>

