<?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>LPCXpresso IDE中的主题 Re: Array passed to function changes despite const qualifier</title>
    <link>https://community.nxp.com/t5/LPCXpresso-IDE/Array-passed-to-function-changes-despite-const-qualifier/m-p/1309224#M33302</link>
    <description>&lt;P&gt;I was able to fix my issue by disabling timer0 when doing the data processing. The timer interrupt was interrupting the data processing in the middle and rewriting to the samples array before it was done processing&lt;/P&gt;</description>
    <pubDate>Fri, 16 Jul 2021 17:09:17 GMT</pubDate>
    <dc:creator>tristanhegseth</dc:creator>
    <dc:date>2021-07-16T17:09:17Z</dc:date>
    <item>
      <title>Array passed to function changes despite const qualifier</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Array-passed-to-function-changes-despite-const-qualifier/m-p/1309220#M33301</link>
      <description>&lt;P&gt;I am having a weird problem where my array of samples (uint16_t) will get altered after data processing. I tried the const qualifier, I tried malloc and memcpy, I tried dummy variables, yet the original sample array still gets affected. The data processing function is a low pass filter, which in this case is operated similar to a moving weighted average. It multiplies some coefficient with the samples around the current sample and sums them together. The only reason I can think of from this function that might change this array is memory being overwritten, but I cannot find out how. I am using the LPCLink2 with the LPC4370 chip. Here is the convolution function.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;static void convolute(uint16_t data[SAMPLES_PER_PULSE], const uint16_t const sample[SAMPLES_PER_PULSE]) {&lt;/P&gt;&lt;P&gt;for (int i = 10; i &amp;lt; SAMPLES_PER_PULSE; i++) {&lt;/P&gt;&lt;P&gt;data[i] = coefficients[0] * (sample[i+1] + sample[i-9]) + coefficients[1] * (sample[i+0] + sample[i-8]) + coefficients[2] * (sample[i-1] + sample[i-7]) + coefficients[3] * (sample[i-2] + sample[i-6]) + coefficients[4] * (sample[i-3] + sample[i-5]) + coefficients[5] * (sample[i-4]);&lt;/P&gt;&lt;P&gt;}&lt;BR /&gt;for (int i = 0; i &amp;lt; 10; i++) {&lt;BR /&gt;data[i] = data[10];&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I setup my code to only display the samples array after data processing is done. I run my program with and without this function being called and without this function the samples are their expected values. With this function they are unpredictable and wrong. My full code is included as a file below&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jul 2021 16:52:31 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Array-passed-to-function-changes-despite-const-qualifier/m-p/1309220#M33301</guid>
      <dc:creator>tristanhegseth</dc:creator>
      <dc:date>2021-07-16T16:52:31Z</dc:date>
    </item>
    <item>
      <title>Re: Array passed to function changes despite const qualifier</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Array-passed-to-function-changes-despite-const-qualifier/m-p/1309224#M33302</link>
      <description>&lt;P&gt;I was able to fix my issue by disabling timer0 when doing the data processing. The timer interrupt was interrupting the data processing in the middle and rewriting to the samples array before it was done processing&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jul 2021 17:09:17 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Array-passed-to-function-changes-despite-const-qualifier/m-p/1309224#M33302</guid>
      <dc:creator>tristanhegseth</dc:creator>
      <dc:date>2021-07-16T17:09:17Z</dc:date>
    </item>
    <item>
      <title>Re: Array passed to function changes despite const qualifier</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Array-passed-to-function-changes-despite-const-qualifier/m-p/1309252#M33303</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/189054"&gt;@tristanhegseth&lt;/a&gt; ,&lt;/P&gt;&lt;P&gt;'const' in a parameter list only marks things non-writable (that you cannot change the value from the C code), nothing more.&lt;/P&gt;&lt;P&gt;Your code is helpful, but is not complete (cannot be compiled without lots of other things).&lt;/P&gt;&lt;P&gt;What I notice is that you allocate lots of data on the stacks: SAMPLES_PER_PULSE is 256, so for example for update_stats() alone you need more than 1 KByte of stack. Do you have enough stack space allocated? Otherwise your stack might run over and change the data. Use the MCUXpresso Image Info (see &lt;A href="https://mcuoneclipse.com/2019/06/16/new-nxp-mcuxpresso-ide-v11-0/" target="_blank"&gt;https://mcuoneclipse.com/2019/06/16/new-nxp-mcuxpresso-ide-v11-0/&lt;/A&gt; ) and check the costs/size in the 'Call Graph' tab how much stack you need. It could be helpful if you allocate the two arrays used statically (global memory) to narrow down the issue.&lt;/P&gt;&lt;P&gt;Have you used watchpoints? If you know the data changed, you can set a watchpoint there, see &lt;A href="https://mcuoneclipse.com/2012/04/29/watchpoints-data-breakpoints-in-mcu10/" target="_blank"&gt;https://mcuoneclipse.com/2012/04/29/watchpoints-data-breakpoints-in-mcu10/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;I hope this helps,&lt;/P&gt;&lt;P&gt;Erich&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jul 2021 18:21:30 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Array-passed-to-function-changes-despite-const-qualifier/m-p/1309252#M33303</guid>
      <dc:creator>ErichStyger</dc:creator>
      <dc:date>2021-07-16T18:21:30Z</dc:date>
    </item>
  </channel>
</rss>

