<?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 Problem when using fopen with a hardcoded file name (data alignment problem ?) in MQX Software Solutions</title>
    <link>https://community.nxp.com/t5/MQX-Software-Solutions/Problem-when-using-fopen-with-a-hardcoded-file-name-data/m-p/223711#M6005</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; here is what I am using : MQX 4.0.2.2 \ CW 10.2 \ Kinetis K60&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; I am trying to use the « fopen » on a SDCARD passing a hardcoded string for the filename.&amp;nbsp; For some reason, It fails when I do so :&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CfgFile = fopen (&lt;/SPAN&gt;&lt;SPAN lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: #2a00ff;"&gt;"a:\\config.txt"&lt;/SPAN&gt;&lt;SPAN lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: black;"&gt;, &lt;/SPAN&gt;&lt;SPAN lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: #2a00ff;"&gt;"r"&lt;/SPAN&gt;&lt;SPAN lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: black;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If I put the name into a ram buffer, then it works :&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;&lt;SPAN lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: #7f0055;"&gt;char&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: black;"&gt; FileName[16] =&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: #2a00ff;"&gt;"a:\\config.txt"&lt;/SPAN&gt;&lt;SPAN lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: black;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CfgFile = fopen (FileName, &lt;/SPAN&gt;&lt;SPAN lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: #2a00ff;"&gt;"r"&lt;/SPAN&gt;&lt;SPAN lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: black;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; I traced into the fopen function and I am not exactly sure what happen, but the loop that scans for all available devices (“ttya:”, “gpio:”, …) doesn’t break at the same place.&amp;nbsp; A difference I can see between the two calls is that the one using the hardcoded string uses a pointer that is not 32 bit aligned (address is “0x1fff0569”) while the second one uses a 32 bit aligned adresss (0x1fffb47c).&amp;nbsp; I am thinking that maybe this does a difference when comparing the strings.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Although I have a workaround for that problem (using a ram buffer), I would very like to know why it does that and how I can avoid it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for any advice.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 08 Jan 2014 19:01:28 GMT</pubDate>
    <dc:creator>slaroche</dc:creator>
    <dc:date>2014-01-08T19:01:28Z</dc:date>
    <item>
      <title>Problem when using fopen with a hardcoded file name (data alignment problem ?)</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/Problem-when-using-fopen-with-a-hardcoded-file-name-data/m-p/223711#M6005</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; here is what I am using : MQX 4.0.2.2 \ CW 10.2 \ Kinetis K60&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; I am trying to use the « fopen » on a SDCARD passing a hardcoded string for the filename.&amp;nbsp; For some reason, It fails when I do so :&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CfgFile = fopen (&lt;/SPAN&gt;&lt;SPAN lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: #2a00ff;"&gt;"a:\\config.txt"&lt;/SPAN&gt;&lt;SPAN lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: black;"&gt;, &lt;/SPAN&gt;&lt;SPAN lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: #2a00ff;"&gt;"r"&lt;/SPAN&gt;&lt;SPAN lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: black;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If I put the name into a ram buffer, then it works :&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;&lt;SPAN lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: #7f0055;"&gt;char&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: black;"&gt; FileName[16] =&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: #2a00ff;"&gt;"a:\\config.txt"&lt;/SPAN&gt;&lt;SPAN lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: black;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CfgFile = fopen (FileName, &lt;/SPAN&gt;&lt;SPAN lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: #2a00ff;"&gt;"r"&lt;/SPAN&gt;&lt;SPAN lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: black;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; I traced into the fopen function and I am not exactly sure what happen, but the loop that scans for all available devices (“ttya:”, “gpio:”, …) doesn’t break at the same place.&amp;nbsp; A difference I can see between the two calls is that the one using the hardcoded string uses a pointer that is not 32 bit aligned (address is “0x1fff0569”) while the second one uses a 32 bit aligned adresss (0x1fffb47c).&amp;nbsp; I am thinking that maybe this does a difference when comparing the strings.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Although I have a workaround for that problem (using a ram buffer), I would very like to know why it does that and how I can avoid it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for any advice.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Jan 2014 19:01:28 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/Problem-when-using-fopen-with-a-hardcoded-file-name-data/m-p/223711#M6005</guid>
      <dc:creator>slaroche</dc:creator>
      <dc:date>2014-01-08T19:01:28Z</dc:date>
    </item>
    <item>
      <title>Re: Problem when using fopen with a hardcoded file name (data alignment problem ?)</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/Problem-when-using-fopen-with-a-hardcoded-file-name-data/m-p/223712#M6006</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;No idea why that wouldn't work.&lt;/P&gt;&lt;P&gt;I did a simple test using the web_hvac example and could do the following&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;log_fp = fopen(&lt;/SPAN&gt;&lt;SPAN style="color: #2a00ff; font-size: 10pt;"&gt;"c:\\hvac_log.txt"&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt;"&gt;,&lt;/SPAN&gt;&lt;SPAN style="color: #2a00ff; font-size: 10pt;"&gt;"a"&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt;"&gt;);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //DES worked&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;#define LOG_FILE "c:\\hvac_log.txt"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;SPAN style="font-size: 10pt;"&gt;log_fp = fopen(LOG_FILE,&lt;/SPAN&gt;&lt;SPAN style="color: #2a00ff; font-size: 10pt;"&gt;"a"&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt;"&gt;);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //DES worked&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;I wonder if something funky with your flash case where the string is not NULL terminated???&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;As an additional test after closing the file I then re-opened it using following code and it worked fine.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&amp;nbsp; log_fp = fopen(&lt;/SPAN&gt;&lt;SPAN style="color: #2a00ff; font-size: 10pt;"&gt;"c:\\hvac_log.txt"&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt;"&gt;,&lt;/SPAN&gt;&lt;SPAN style="color: #2a00ff; font-size: 10pt;"&gt;"r"&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;STRONG style=": ; color: #7f0055; font-size: 10pt;"&gt;if&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt;"&gt; (log_fp) {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;STRONG style=": ; color: #7f0055; font-size: 10pt;"&gt;char&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt;"&gt; temparray[31];&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&amp;nbsp; fgets((&lt;/SPAN&gt;&lt;STRONG style=": ; color: #7f0055; font-size: 10pt;"&gt;char&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt;"&gt; *)&amp;amp;temparray[0], (&lt;/SPAN&gt;&lt;SPAN style="color: #005032; font-size: 10pt;"&gt;int_32&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt;"&gt;)30, log_fp);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt; }&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;Lastly when you step into the fopen() can you use your Variable window to see what the "tmp_ptr" is set to?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;In my picture below it is shown as "c:\\hvac_log.txt"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="ScreenHunter_51 Jan. 17 13.03.gif"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/41867i3D639409C70D1313/image-size/large?v=v2&amp;amp;px=999" role="button" title="ScreenHunter_51 Jan. 17 13.03.gif" alt="ScreenHunter_51 Jan. 17 13.03.gif" /&gt;&lt;/span&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;Regards,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;David&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Jan 2014 19:06:29 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/Problem-when-using-fopen-with-a-hardcoded-file-name-data/m-p/223712#M6006</guid>
      <dc:creator>DavidS</dc:creator>
      <dc:date>2014-01-17T19:06:29Z</dc:date>
    </item>
  </channel>
</rss>

