<?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>Kinetis Software Development KitのトピックUART_DRV_EdmaGetReceiveStatus reports that it has received a certain amount of data before it actually has</title>
    <link>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/UART-DRV-EdmaGetReceiveStatus-reports-that-it-has-received-a/m-p/401141#M1490</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using the Kinetis SDK 1.2 with the FRDMK64f board.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My application uses the CMSIS RTX OS has only one thread. I am trying to start receiving data from UART0 at 115200 baud, using UART_DRV_EdmaReceiveData, and I store the data into a thread safe FIFO. In a polling loop I am making calls to UART_DRV_EdmaGetReceiveStatus, and I advance the tail of the FIFO by how many ever bytes UART_DRV_EdmaGetReceiveStatus tells me it received (I am disabling interrupts when i call UART_DRV_EdmaReceiveData and when I advance the tail of the FIFO).&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem is that, sporadically, the data actually received looks incorrect. Specifically, although UART_DRV_EdmaReceiveData tells me it has received a certain number of bytes (this is generally of the order of 600 or so), when I copy the "new" data in my FIFO, it looks like the data did not actually get written (old values are being copied). However, if i put a breakpoint in my code (i'm using J-Link for debugging), it looks like the data in the FIFO is correct... so presumably by the time the breakpoint got hit the EDMA completed writing all the data.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Like i mentioned, this happens sporadically, and it is more frequent when a lot of data is being sent to UART0.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code I have is pretty complicated, and i'm not sure how I can give you reproduction steps. Has anyone encountered anything similar, or is there a bug with the SDK that may be causing this behavior.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Sid&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 22 Sep 2015 18:46:00 GMT</pubDate>
    <dc:creator>siddharthmenon</dc:creator>
    <dc:date>2015-09-22T18:46:00Z</dc:date>
    <item>
      <title>UART_DRV_EdmaGetReceiveStatus reports that it has received a certain amount of data before it actually has</title>
      <link>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/UART-DRV-EdmaGetReceiveStatus-reports-that-it-has-received-a/m-p/401141#M1490</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using the Kinetis SDK 1.2 with the FRDMK64f board.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My application uses the CMSIS RTX OS has only one thread. I am trying to start receiving data from UART0 at 115200 baud, using UART_DRV_EdmaReceiveData, and I store the data into a thread safe FIFO. In a polling loop I am making calls to UART_DRV_EdmaGetReceiveStatus, and I advance the tail of the FIFO by how many ever bytes UART_DRV_EdmaGetReceiveStatus tells me it received (I am disabling interrupts when i call UART_DRV_EdmaReceiveData and when I advance the tail of the FIFO).&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem is that, sporadically, the data actually received looks incorrect. Specifically, although UART_DRV_EdmaReceiveData tells me it has received a certain number of bytes (this is generally of the order of 600 or so), when I copy the "new" data in my FIFO, it looks like the data did not actually get written (old values are being copied). However, if i put a breakpoint in my code (i'm using J-Link for debugging), it looks like the data in the FIFO is correct... so presumably by the time the breakpoint got hit the EDMA completed writing all the data.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Like i mentioned, this happens sporadically, and it is more frequent when a lot of data is being sent to UART0.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code I have is pretty complicated, and i'm not sure how I can give you reproduction steps. Has anyone encountered anything similar, or is there a bug with the SDK that may be causing this behavior.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Sid&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Sep 2015 18:46:00 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/UART-DRV-EdmaGetReceiveStatus-reports-that-it-has-received-a/m-p/401141#M1490</guid>
      <dc:creator>siddharthmenon</dc:creator>
      <dc:date>2015-09-22T18:46:00Z</dc:date>
    </item>
    <item>
      <title>Re: UART_DRV_EdmaGetReceiveStatus reports that it has received a certain amount of data before it actually has</title>
      <link>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/UART-DRV-EdmaGetReceiveStatus-reports-that-it-has-received-a/m-p/401142#M1491</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Sid,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As you mentioned "I am disabling interrupts when i call UART_DRV_EdmaReceiveData and when I advance the tail of the FIFO", I think that might be the cause, you know, in the example of "uart_edma_non_blocking", interrupr is enabled before calling UART_DRV_EdmaReceiveData(), please kindly refer to "C:\Freescale\KSDK_1.2.0\examples\frdmk64f\driver_examples\uart\uart_edma_non_blocking" for more details.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope that helps,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Have a great day!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Oct 2015 03:26:01 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/UART-DRV-EdmaGetReceiveStatus-reports-that-it-has-received-a/m-p/401142#M1491</guid>
      <dc:creator>Kan_Li</dc:creator>
      <dc:date>2015-10-12T03:26:01Z</dc:date>
    </item>
    <item>
      <title>Re: UART_DRV_EdmaGetReceiveStatus reports that it has received a certain amount of data before it actually has</title>
      <link>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/UART-DRV-EdmaGetReceiveStatus-reports-that-it-has-received-a/m-p/401143#M1492</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Kan,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for your suggestion. Unfortunately that does not solve my problem. Let me give you more information.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;this is how i initialize the UART EDMA (this is not the actual code, but an equivalent):&lt;/P&gt;&lt;P&gt;void CommService::initializeDMA()&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;/* NOTE: the following properties are stored as private properties of the CommService class&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp; edma_user_config_t edmaConfig_;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp; uart_edma_user_config_t uartEdmaConfig_;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp; uart_edma_state_t uartEdmaState_;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp; edma_callback_t driverTxCallback_;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp; edma_callback_t driverRxCallback_;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;*/&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp; // initialize the EDMA&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp; edmaConfig_.chnArbitration = kEDMAChnArbitrationRoundrobin;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp; edmaConfig_.notHaltOnError = false;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp; EDMA_DRV_Init(&amp;amp;edmaState_, &amp;amp;edmaConfig_);&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp; // configure the edma uart driver&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp; uartEdmaConfig_.baudRate = BAUD_RATE;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp; uartEdmaConfig_.bitCountPerChar = kUart8BitsPerChar;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp; uartEdmaConfig_.parityMode = kUartParityDisabled;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp; uartEdmaConfig_.stopBitCount = kUartOneStopBit;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp; UART_DRV_EdmaInit(UART_INSTANCE, &amp;amp;uartEdmaState_, &amp;amp;uartEdmaConfig_);&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp; // replace dma completions installed by init with our own&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp; driverTxCallback_&amp;nbsp; = uartEdmaState_.edmaUartTx.callback;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp; uartEdmaState_.edmaUartTx.callback = sendComplete;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp; driverRxCallback_&amp;nbsp; = uartEdmaState_.edmaUartRx.callback;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp; uartEdmaState_.edmaUartRx.callback = receiveComplete;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp; dmaInitialized_ = true;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp; dmaChannelError_ = false;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In receiveComplete()... the custom callback that gets invoked after the UART receive has finished(or in case of a channel error), i do this:&lt;/P&gt;&lt;P&gt;extern "C" void receiveComplete(void *param, edma_chn_status_t status)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp; using coder::tgtsvc::CommService;&lt;/P&gt;&lt;P&gt;&amp;nbsp; auto &amp;amp;cs = CommService::instance();&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if (status == kEDMAChnError) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cs.setChannelErrorFlag(); //sets an error flag that terminates the program&lt;/P&gt;&lt;P&gt;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; // call the driver's callback&lt;/P&gt;&lt;P&gt;&amp;nbsp; cs.driverRxCallback_(param, status);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; // add recently received bytes to fifo&lt;/P&gt;&lt;P&gt;&amp;nbsp; cs.rxFIFO_.contents_add(cs.recvCount_); //advance the tail of rxFIFO&lt;/P&gt;&lt;P&gt;&amp;nbsp; cs.recvCount_ = 0;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; // start a new dma receive&lt;/P&gt;&lt;P&gt;&amp;nbsp; auto ra = cs.rxFIFO_.space_carray(); //ra is an object of data structure that stores contiguous data from a managed pool&lt;/P&gt;&lt;P&gt;&amp;nbsp; cs.recvCount_ = ra.size_; //ra.size is a large number, we don't know how much the sender actually wants to send at this point&lt;/P&gt;&lt;P&gt;&amp;nbsp; // I am currently working around this bug, by setting cs.recvCount_ = 1; &lt;/P&gt;&lt;P&gt;&amp;nbsp; ///\todo overflow error if cs.recvCount_ == 0&lt;/P&gt;&lt;P&gt;&amp;nbsp; UART_DRV_EdmaReceiveData(CommService::UART_INSTANCE, ra.addr_, cs.recvCount_);&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now in the program's main thread, i call this method:&lt;/P&gt;&lt;P&gt;void CommService::updateReceiveStatus()&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt; // I am currently working around this bug by not doing anything in this method, as&amp;nbsp; receiveComplete() advances the tail of rxFIFO&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt; uint32_t n = 0;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp; UART_DRV_EdmaGetReceiveStatus(UART_INSTANCE, &amp;amp;n);&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp; uint32_t bytesReceived = recvCount_ - n;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp; if (bytesReceived&amp;gt;0)&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp; {&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&amp;nbsp; GlobalGuard guard; //disables interrupts when in scope, note that i'm not doing this before UART_DRV_EdmaGetReceiveStatus is called&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&amp;nbsp; recvCount_ = n;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&amp;nbsp; rxFIFO_.contents_add(bytesReceived);&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&amp;nbsp; &lt;STRONG&gt;uint8_t cmdId = rxFIFO_.front(); //gets the first 9 bytes in the rxFIFO&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&amp;nbsp; &lt;STRONG&gt;// if bytesReceived is a number &amp;gt;100 or so, and , if I pause for an arbitrary amount of time&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp; // for example using CMSIS RTX's osDelay(100) to delay for 100ms&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&lt;STRONG&gt;&amp;nbsp; uint8_t cmdId2 = rxFIFO_.front(); &lt;STRONG&gt; //gets the first 9 bytes in the rxFIFO again&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp; assert(cmdId ==cmdId); //this assertion fails!!&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope this makes things more clear.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Oct 2015 15:35:27 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/UART-DRV-EdmaGetReceiveStatus-reports-that-it-has-received-a/m-p/401143#M1492</guid>
      <dc:creator>siddharthmenon</dc:creator>
      <dc:date>2015-10-12T15:35:27Z</dc:date>
    </item>
  </channel>
</rss>

