<?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 Memory Corruption when Writing to DMA CITER in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Memory-Corruption-when-Writing-to-DMA-CITER/m-p/480032#M29360</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'll be honest in that this has me pretty stumped.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So with my application, I am capturing edges via the FTM.&amp;nbsp; Every edge generates a DMA request to save the counter into a circular buffer.&lt;/P&gt;&lt;P&gt;I currently have the DMA configured to act as a circular buffer in case I don't get to the edges in time if they come in too fast.&amp;nbsp; However, every time I check the edges, I want to reset the DMA pointer, and I do this by writing to CITER.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For instance, my circular buffer has 128 elements.&amp;nbsp; When I check my buffer, I execute the following line of code:&lt;/P&gt;&lt;P&gt;DMA0-&amp;gt;TCD[0].CITER_ELINKNO = 128;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This works for a little while, but I noticed after my program has been running for a bit, all of a sudden all of my variable blow up to crazy values, and it seems like there was an illegal jump or something.&amp;nbsp; I'm not able to really figure it out because when I single step through my code, the corruption never happens.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is what I'm doing fine?&amp;nbsp; Is there an application note somewhere that tells me I shouldn't do this?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edit: I forgot to mention, I also tried disabling the DMA channel before and after modifying the CITER register, but this does not seem to help either.&lt;/P&gt;&lt;P&gt;DMAMUX0-&amp;gt;CHCFG[0] ^= ~(DMAMUX_CHCFG_ENBL_MASK);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, I'm using the TWR-K60F120M.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 15 Mar 2016 19:48:46 GMT</pubDate>
    <dc:creator>benjaminschroed</dc:creator>
    <dc:date>2016-03-15T19:48:46Z</dc:date>
    <item>
      <title>Memory Corruption when Writing to DMA CITER</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Memory-Corruption-when-Writing-to-DMA-CITER/m-p/480032#M29360</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'll be honest in that this has me pretty stumped.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So with my application, I am capturing edges via the FTM.&amp;nbsp; Every edge generates a DMA request to save the counter into a circular buffer.&lt;/P&gt;&lt;P&gt;I currently have the DMA configured to act as a circular buffer in case I don't get to the edges in time if they come in too fast.&amp;nbsp; However, every time I check the edges, I want to reset the DMA pointer, and I do this by writing to CITER.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For instance, my circular buffer has 128 elements.&amp;nbsp; When I check my buffer, I execute the following line of code:&lt;/P&gt;&lt;P&gt;DMA0-&amp;gt;TCD[0].CITER_ELINKNO = 128;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This works for a little while, but I noticed after my program has been running for a bit, all of a sudden all of my variable blow up to crazy values, and it seems like there was an illegal jump or something.&amp;nbsp; I'm not able to really figure it out because when I single step through my code, the corruption never happens.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is what I'm doing fine?&amp;nbsp; Is there an application note somewhere that tells me I shouldn't do this?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edit: I forgot to mention, I also tried disabling the DMA channel before and after modifying the CITER register, but this does not seem to help either.&lt;/P&gt;&lt;P&gt;DMAMUX0-&amp;gt;CHCFG[0] ^= ~(DMAMUX_CHCFG_ENBL_MASK);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, I'm using the TWR-K60F120M.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Mar 2016 19:48:46 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Memory-Corruption-when-Writing-to-DMA-CITER/m-p/480032#M29360</guid>
      <dc:creator>benjaminschroed</dc:creator>
      <dc:date>2016-03-15T19:48:46Z</dc:date>
    </item>
    <item>
      <title>Re: Memory Corruption when Writing to DMA CITER</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Memory-Corruption-when-Writing-to-DMA-CITER/m-p/480033#M29361</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think I might have this figured out now.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The key thing I wasn't doing was I wasn't updating DADDR as well as updating CITER.&amp;nbsp; I didn't realize the actual pointer didn't get reset.&amp;nbsp; Now, with having to update 2 different registers, this introduces issues of atomicity.&amp;nbsp; Because I can't guarantee a DMA request won't come in between the time of me updating these 2 registers, I decided to err on the safe side by disabling the DMA channel beforehand, and re-enabling it afterward, and this seems to be working just fine.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DMAMUX0-&amp;gt;CHCFG[0] &amp;amp;= ~(DMAMUX_CHCFG_ENBL_MASK);&lt;/P&gt;&lt;P&gt;DMA0-&amp;gt;TCD[0].CITER_ELINKNO = 128;&lt;/P&gt;&lt;P&gt;DMA0-&amp;gt;TCD[0].DADDR = (uint32_t)freq_dma_arr[0];&lt;/P&gt;&lt;P&gt;DMAMUX0-&amp;gt;CHCFG[0] |= DMAMUX_CHCFG_ENBL_MASK;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Mar 2016 17:06:26 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Memory-Corruption-when-Writing-to-DMA-CITER/m-p/480033#M29361</guid>
      <dc:creator>benjaminschroed</dc:creator>
      <dc:date>2016-03-16T17:06:26Z</dc:date>
    </item>
  </channel>
</rss>

