<?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>S32KのトピックRe: SPI DMA problem</title>
    <link>https://community.nxp.com/t5/S32K/SPI-DMA-problem/m-p/1073405#M7430</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Austin,&lt;/P&gt;&lt;P&gt;Apparently, the root cause is that you use DMA and the core at the same time to fill the TX FIFO. And the Watermark changes the timing. I guess you should use a mutex and don't allow the core to write to the data register when the DMA is using it. Once the DMA transfer is complete, you could read the Module Busy Flag (MBF) or check the number of words in the TX FIFO (FSR_TXCOUNT).&lt;/P&gt;&lt;P&gt;By the way, your TCF clearing is not good, it clears all the other w1c flags in the status register that are set at the time of the write (read-modify-write operation).&lt;/P&gt;&lt;P&gt;Mask the TCF flag only: LPSPI0-&amp;gt;SR = LPSPI_SR_TCF_MASK; /* Clear TCF flag */&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Daniel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 13 Jul 2020 14:19:25 GMT</pubDate>
    <dc:creator>danielmartynek</dc:creator>
    <dc:date>2020-07-13T14:19:25Z</dc:date>
    <item>
      <title>SPI DMA problem</title>
      <link>https://community.nxp.com/t5/S32K/SPI-DMA-problem/m-p/1073400#M7425</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am trying to use DMA LPSPI to write to a SD card. The DMA SPI was supposed to send 512 bytes in one major loop. The major loop has 512 minor loops and each minor loop transfer 1 byte.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is my problem. I wanted to maximize my throughput that's why I set my SPI TX watermark to 3. But when I set it to 3, somehow my last byte (byte number 511) was not sent. It is oddly replaced with a random 0xFF byte. However, If I set the TX watermark to 1,2 or 4, it would work perfectly. However, I feel like setting a TX water mark of 4 will cause problems and 2 is not really efficient (the TX fifo has a size of 4). I have attached the picture of the array I get from reading the data back from the SD card.&amp;nbsp;I know for sure that my read function is not the source of problem.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using the S32K148evb-q176.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is my code for SPI config.&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;/*&lt;BR /&gt; * Copyright (c) 2014 - 2016, Freescale Semiconductor, Inc.&lt;BR /&gt; * Copyright (c) 2016 - 2018, NXP.&lt;BR /&gt; * All rights reserved.&lt;BR /&gt; *&lt;BR /&gt; * Redistribution and use in source and binary forms, with or without&lt;BR /&gt; * modification, are permitted provided that the following conditions are met:&lt;BR /&gt; *&lt;BR /&gt; * 1. Redistributions of source code must retain the above copyright notice,&lt;BR /&gt; * this list of conditions and the following disclaimer.&lt;BR /&gt; *&lt;BR /&gt; * 2. Redistributions in binary form must reproduce the above copyright notice,&lt;BR /&gt; * this list of conditions and the following disclaimer in the documentation&lt;BR /&gt; * and/or other materials provided with the distribution.&lt;BR /&gt; *&lt;BR /&gt; * 3. Neither the name of the copyright holder nor the names of its contributors&lt;BR /&gt; * may be used to endorse or promote products derived from this software&lt;BR /&gt; * without specific prior written permission.&lt;BR /&gt; *&lt;BR /&gt; * THIS SOFTWARE IS PROVIDED BY NXP "AS IS" AND ANY EXPRESSED OR&lt;BR /&gt; * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES&lt;BR /&gt; * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.&lt;BR /&gt; * IN NO EVENT SHALL NXP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,&lt;BR /&gt; * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES&lt;BR /&gt; * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR&lt;BR /&gt; * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)&lt;BR /&gt; * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,&lt;BR /&gt; * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING&lt;BR /&gt; * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF&lt;BR /&gt; * THE POSSIBILITY OF SUCH DAMAGE.&lt;BR /&gt; */&lt;/P&gt;&lt;P&gt;#include "device_registers.h" /* include peripheral declarations */&lt;BR /&gt;#define PTB0 0&lt;/P&gt;&lt;P&gt;void LPSPI0_init_master(void)&lt;BR /&gt;{&lt;BR /&gt; /*!&lt;BR /&gt; * LPSPI0 Clocking:&lt;BR /&gt; * ===================================================&lt;BR /&gt; */&lt;BR /&gt; PCC-&amp;gt;PCCn[PCC_LPSPI0_INDEX] = 0; /* Disable clocks to modify PCS ( default) */&lt;BR /&gt; PCC-&amp;gt;PCCn[PCC_LPSPI0_INDEX] = PCC_PCCn_PR_MASK /* (default) Peripheral is present. */&lt;BR /&gt; |PCC_PCCn_CGC_MASK /* Enable PCS=SPLL_DIV2 (40 MHz func'l clock) */&lt;BR /&gt; |PCC_PCCn_PCS(6);&lt;BR /&gt; /*!&lt;BR /&gt; * LPSPI0 Initialization:&lt;BR /&gt; * ===================================================&lt;BR /&gt; */&lt;BR /&gt; LPSPI0-&amp;gt;CR = 0x00000000; /* Disable module for configuration */&lt;BR /&gt; LPSPI0-&amp;gt;IER = 0x00000000; /* Interrupts not used */&lt;BR /&gt; LPSPI0-&amp;gt;DER = 0x00000000; /* DMA not used */&lt;BR /&gt; LPSPI0-&amp;gt;CFGR0 = 0x00000000; /* Defaults: */&lt;BR /&gt; /* RDM0=0: rec'd data to FIFO as normal */&lt;BR /&gt; /* CIRFIFO=0; Circular FIFO is disabled */&lt;BR /&gt; /* HRSEL, HRPOL, HREN=0: Host request disabled */&lt;/P&gt;&lt;P&gt;LPSPI0-&amp;gt;CFGR1 = LPSPI_CFGR1_MASTER_MASK | LPSPI_CFGR1_NOSTALL_MASK; /* Configurations: master mode */&lt;BR /&gt; /* PCSCFG=0: PCS[3:2] are enabled */&lt;BR /&gt; /* OUTCFG=0: Output data retains last value when CS negated */&lt;BR /&gt; /* PINCFG=0: SIN is input, SOUT is output */&lt;BR /&gt; /* MATCFG=0: Match disabled */&lt;BR /&gt; /* PCSPOL=0: PCS is active low */&lt;BR /&gt; /* NOSTALL=0: Stall if Tx FIFO empty or Rx FIFO full */&lt;BR /&gt; /* AUTOPCS=0: does not apply for master mode */&lt;BR /&gt; /* SAMPLE=0: input data sampled on SCK edge */&lt;BR /&gt; /* MASTER=1: Master mode */&lt;/P&gt;&lt;P&gt;LPSPI0-&amp;gt;TCR = LPSPI_TCR_PRESCALE(2)&lt;BR /&gt; |LPSPI_TCR_PCS(0)&lt;BR /&gt; |LPSPI_TCR_FRAMESZ(7); /* Transmit cmd: PCS0, 16 bits, prescale func'l clk by 4, etc */&lt;BR /&gt; /* CPOL=0: SCK inactive state is low */&lt;BR /&gt; /* CPHA=0: capture data on SCK lead'g, changing on trail'g edge */&lt;BR /&gt; /* PRESCALE=2: Functional clock divided by 2**2 = 4 */&lt;BR /&gt; /* PCS=0: Transfer using PCS0 */&lt;BR /&gt; /* LSBF=0: Data is transfered MSB first */&lt;BR /&gt; /* BYSW=0: Byte swap disabled */&lt;BR /&gt; /* CONT, CONTC=0: Continuous transfer disabled */&lt;BR /&gt; /* RXMSK=0: Normal transfer: rx data stored in rx FIFO */&lt;BR /&gt; /* TXMSK=0: Normal transfer: data loaded from tx FIFO */&lt;BR /&gt; /* WIDTH=0: Single bit transfer */&lt;BR /&gt; /* FRAMESZ=47: # bits in frame = 47+1=48 */&lt;/P&gt;&lt;P&gt;LPSPI0-&amp;gt;CCR = LPSPI_CCR_SCKPCS(4)&lt;BR /&gt; |LPSPI_CCR_PCSSCK(4)&lt;BR /&gt; |LPSPI_CCR_DBT(8)&lt;BR /&gt; |LPSPI_CCR_SCKDIV(8); /* Clock dividers based on prescaled func'l clk of 100 nsec */&lt;BR /&gt; /* SCKPCS=4: SCK to PCS delay = 4+1 = 5 (500 nsec) */&lt;BR /&gt; /* PCSSCK=4: PCS to SCK delay = 4+1 = 5 (500 usec) */&lt;BR /&gt; /* DBT=8: Delay between Transfers = 8+2 = 10 (1 usec) */&lt;BR /&gt; /* SCKDIV=8: SCK divider =8+2 = 10 (1 usec: 1 MHz baud rate) */&lt;/P&gt;&lt;P&gt;LPSPI0-&amp;gt;FCR = LPSPI_FCR_TXWATER(3); /* RXWATER=0: Rx flags set when Rx FIFO &amp;gt; 0 */&lt;BR /&gt; /* TXWATER=3: Tx flags set when Tx FIFO &amp;lt;= 3 */&lt;/P&gt;&lt;P&gt;LPSPI0-&amp;gt;CR = LPSPI_CR_MEN_MASK&lt;BR /&gt; |LPSPI_CR_DBGEN_MASK; /* Enable module for operation */&lt;BR /&gt; /* DBGEN=1: module enabled in debug mode */&lt;BR /&gt; /* DOZEN=0: module enabled in Doze mode */&lt;BR /&gt; /* RST=0: Master logic not reset */&lt;BR /&gt; /* MEN=1: Module is enabled */&lt;BR /&gt;}&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Here is the code for DMA config&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;#include "device_registers.h" /* include peripheral declarations */&lt;BR /&gt;#include "S32K148.h"&lt;BR /&gt;#include "dma.h"&lt;/P&gt;&lt;P&gt;uint8_t dummy = 0xFF;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;void DMA_TCD_init_Tx(void* p_tx_data)&lt;BR /&gt;{&lt;BR /&gt; DMA-&amp;gt;TCD[0].SADDR = (uint32_t)(p_tx_data); /* Source Address. */&lt;BR /&gt; DMA-&amp;gt;TCD[0].SOFF = DMA_TCD_SOFF_SOFF(1); /* Src. addr add 4 byte after Transfers */&lt;BR /&gt; DMA-&amp;gt;TCD[0].ATTR = DMA_TCD_ATTR_SMOD(0) | /* Src. modulo feature not used */&lt;BR /&gt; DMA_TCD_ATTR_SSIZE(0) | /* Src. read 2**2 = 4 byte per transfer */&lt;BR /&gt; DMA_TCD_ATTR_DMOD(0) | /* Dest. modulo feature not used */&lt;BR /&gt; DMA_TCD_ATTR_DSIZE(0); /* Dest. write 2**2 =4 byte per trans. */&lt;/P&gt;&lt;P&gt;DMA-&amp;gt;TCD[0].NBYTES.MLNO = DMA_TCD_NBYTES_MLNO_NBYTES(1); /* Transfer 16 byte /minor loop */&lt;BR /&gt; DMA-&amp;gt;TCD[0].SLAST = DMA_TCD_SLAST_SLAST(-512); /* Src addr change after major loop */&lt;/P&gt;&lt;P&gt;DMA-&amp;gt;TCD[0].DADDR = DMA_TCD_DADDR_DADDR((uint32_t)&amp;amp;(LPSPI0-&amp;gt;TDR)); /* Destination Address. */&lt;BR /&gt; DMA-&amp;gt;TCD[0].DOFF = DMA_TCD_DOFF_DOFF(0); /* No dest adr offset after transfer */&lt;BR /&gt;&lt;BR /&gt; DMA-&amp;gt;TCD[0].CITER.ELINKNO= DMA_TCD_CITER_ELINKNO_CITER(512) | /* 11 minor loop iterations */&lt;BR /&gt; DMA_TCD_CITER_ELINKNO_ELINK(0); /* No minor loop chan link */&lt;/P&gt;&lt;P&gt;DMA-&amp;gt;TCD[0].DLASTSGA = DMA_TCD_DLASTSGA_DLASTSGA(0); /* No dest chg after major loop */&lt;BR /&gt; DMA-&amp;gt;TCD[0].CSR = DMA_TCD_CSR_START(0) | /* Clear START status flag */&lt;BR /&gt; DMA_TCD_CSR_INTMAJOR(0) | /* No IRQ after major loop */&lt;BR /&gt; DMA_TCD_CSR_INTHALF(0) | /* No IRQ after 1/2 major loop */&lt;BR /&gt; DMA_TCD_CSR_DREQ(1) | /* en chan after major loop */&lt;BR /&gt; DMA_TCD_CSR_ESG(0) | /* Disable Scatter Gather */&lt;BR /&gt; DMA_TCD_CSR_MAJORELINK(0) | /* No major loop chan link */&lt;BR /&gt; DMA_TCD_CSR_ACTIVE(0) | /* Clear ACTIVE status flag */&lt;BR /&gt; DMA_TCD_CSR_DONE(0) | /* Clear DONE status flag */&lt;BR /&gt; DMA_TCD_CSR_MAJORLINKCH(0) | /* Chan # if major loop ch link */&lt;BR /&gt; DMA_TCD_CSR_BWC(0); /* No eDMA stalls after R/W */&lt;/P&gt;&lt;P&gt;DMA-&amp;gt;TCD[0].BITER.ELINKNO= DMA_TCD_BITER_ELINKNO_BITER(512) | /* Initial iteration count */&lt;BR /&gt; DMA_TCD_BITER_ELINKNO_ELINK(0); /* No minor loop chan link */&lt;BR /&gt;}&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Here is the code to initiate the DMA using start bit&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;void initiate_DMA_Tx(){&lt;/P&gt;&lt;P&gt;while (!((DMA-&amp;gt;TCD[0].CSR &amp;gt;&amp;gt; DMA_TCD_CSR_DONE_SHIFT) &amp;amp; 1)) { /* Loop till DONE = 1 */&lt;BR /&gt; while((LPSPI0-&amp;gt;SR &amp;amp; LPSPI_SR_TDF_MASK)&amp;gt;&amp;gt;LPSPI_SR_TDF_SHIFT==0); /* Wait for tx fifo to have space */&lt;/P&gt;&lt;P&gt;DMA-&amp;gt;SSRT = 0; /* Set chan 0 START bit to initiate next minor loop */&lt;/P&gt;&lt;P&gt;while (((DMA-&amp;gt;TCD[0].CSR &amp;gt;&amp;gt; DMA_TCD_CSR_START_SHIFT) &amp;amp; 1) | /* Wait for START = 0 */&lt;BR /&gt; ((DMA-&amp;gt;TCD[0].CSR &amp;gt;&amp;gt; DMA_TCD_CSR_ACTIVE_SHIFT) &amp;amp; 1)) {} /* and ACTIVE = 0 */&lt;BR /&gt; /* Now minor loop has completed */&lt;BR /&gt; }&lt;BR /&gt;}&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When TX Watermark is 1,2,4&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="d.PNG"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/114843i6F2D1EC05340A103/image-size/large?v=v2&amp;amp;px=999" role="button" title="d.PNG" alt="d.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When TX Watermark is 3&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="ds.PNG"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/114844i52AF83CADE7D3152/image-size/large?v=v2&amp;amp;px=999" role="button" title="ds.PNG" alt="ds.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Jul 2020 14:13:01 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S32K/SPI-DMA-problem/m-p/1073400#M7425</guid>
      <dc:creator>trunghieudon</dc:creator>
      <dc:date>2020-07-07T14:13:01Z</dc:date>
    </item>
    <item>
      <title>Re: SPI DMA problem</title>
      <link>https://community.nxp.com/t5/S32K/SPI-DMA-problem/m-p/1073401#M7426</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello&amp;nbsp;&lt;A class="jx-jive-macro-user" href="https://community.nxp.com/people/trunghieudon@geotab.com"&gt;trunghieudon@geotab.com&lt;/A&gt;,&lt;/P&gt;&lt;P&gt;I tested your code with the S32K144_project_LPSPI example.&lt;/P&gt;&lt;P&gt;The only thing I changed&lt;/P&gt;&lt;P&gt;LPSPI0 -&amp;gt; LPSPI1&lt;/P&gt;&lt;P&gt;LPSPI_TCR_PCS(0) -&amp;gt;&amp;nbsp;&lt;SPAN&gt;LPSPI_TCR_PCS(3)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The&amp;nbsp;initiate_DMA_Tx() was being called continuously and all the data seemed to be transmitted correctly.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_4.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/114995iB8D764417688E3E9/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_4.png" alt="pastedImage_4.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can you scope the SPI?&lt;/P&gt;&lt;P&gt;Or could you share a complete test project so that can replicate the issue on my side?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;BR,&amp;nbsp;Daniel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Jul 2020 14:44:44 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S32K/SPI-DMA-problem/m-p/1073401#M7426</guid>
      <dc:creator>danielmartynek</dc:creator>
      <dc:date>2020-07-08T14:44:44Z</dc:date>
    </item>
    <item>
      <title>Re: SPI DMA problem</title>
      <link>https://community.nxp.com/t5/S32K/SPI-DMA-problem/m-p/1073402#M7427</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Daniel,&lt;/P&gt;&lt;P&gt;Thank you for your response. I have attached my code. Though my code is&amp;nbsp;expected to get a response from the&amp;nbsp;SD card therefore it might need some modifications to the code on your end to run it. I also scoped the SPI and the error also shows on the scope.&lt;BR /&gt;I noticed just now that if I&amp;nbsp;run the whole thing without any breakpoints, it will show the wrong SPI data as mentioned. But if I put breakpoints before and after the &lt;STRONG&gt;initiate_DMA_Tx() (line 254 in SD_Module.c)&lt;/STRONG&gt;, it will run properly and&amp;nbsp;sends the right data. So I am suspecting that this is a timing issue. I have tried to add the "wait for SPI transfer complete"&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;while((LPSPI0-&amp;gt;SR &amp;amp; LPSPI_SR_TCF_MASK)&amp;gt;&amp;gt;LPSPI_SR_TCF_SHIFT==0);&lt;/EM&gt;&lt;/STRONG&gt; after the&amp;nbsp;&lt;SPAN&gt;initiate_DMA_Tx() but this will only solve for the first initiate_DMA_Tx() call (meaning 511th bit will be corrected, though 1023th bit,&amp;nbsp;1535th bit, 2047th bit will still be 255). Do you know why this is the problem?&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Jul 2020 16:10:25 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S32K/SPI-DMA-problem/m-p/1073402#M7427</guid>
      <dc:creator>trunghieudon</dc:creator>
      <dc:date>2020-07-08T16:10:25Z</dc:date>
    </item>
    <item>
      <title>Re: SPI DMA problem</title>
      <link>https://community.nxp.com/t5/S32K/SPI-DMA-problem/m-p/1073403#M7428</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Austin,&lt;/P&gt;&lt;P&gt;It's difficult to debug it without the SD card.&lt;/P&gt;&lt;P&gt;But I think you have found the solution already.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_1.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/115518i38C1C464F959E56D/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_1.png" alt="pastedImage_1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_2.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/115519i2F8504940A959825/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_2.png" alt="pastedImage_2.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;You send 0xFF at the end of the 512-frame transfer, and the code that you sent does not wait until the SPI transfer is complete. At the time the DMA transfer ends the SPI is still working.&lt;/P&gt;&lt;P&gt;The fact that it works with the TCF flag only for the first time got me thinking that you probably don't clear the TCF flag.&lt;/P&gt;&lt;P&gt;Also, you could enable interrupts on the LPSPI error flags.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Daniel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Jul 2020 10:01:07 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S32K/SPI-DMA-problem/m-p/1073403#M7428</guid>
      <dc:creator>danielmartynek</dc:creator>
      <dc:date>2020-07-10T10:01:07Z</dc:date>
    </item>
    <item>
      <title>Re: SPI DMA problem</title>
      <link>https://community.nxp.com/t5/S32K/SPI-DMA-problem/m-p/1073404#M7429</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&amp;nbsp;&lt;A class="jx-jive-macro-user" href="https://community.nxp.com/people/danielmartynek"&gt;danielmartynek&lt;/A&gt;,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That makes sense. Though I was wrong before, It actually behaves even stranger. It works only on the 1st time, 3rd time, 5th time and wouldn't work on any even calls. This happens when I check the TCF flag after&amp;nbsp;calling the initiate_DMA_Tx() or after it finished the 512th minor loop (checking TCF within the &lt;STRONG&gt;initiate_DMA_Tx() function&lt;/STRONG&gt;). I then tried to check TCF flag at the 511th minor loop and 512th minor loop and it works.&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;void initiate_DMA_Tx(){&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; uint16_t count=0;&lt;BR /&gt; while (!((DMA-&amp;gt;TCD[0].CSR &amp;gt;&amp;gt; DMA_TCD_CSR_DONE_SHIFT) &amp;amp; 1)) { /* Loop till DONE = 1 */&lt;BR /&gt; while((LPSPI0-&amp;gt;SR &amp;amp; LPSPI_SR_TDF_MASK)&amp;gt;&amp;gt;LPSPI_SR_TDF_SHIFT==0); /* Wait for tx fifo to have space */&lt;/P&gt;&lt;P&gt;DMA-&amp;gt;SSRT = 0; /* Set chan 0 START bit to initiate next minor loop */&lt;/P&gt;&lt;P&gt;while (((DMA-&amp;gt;TCD[0].CSR &amp;gt;&amp;gt; DMA_TCD_CSR_START_SHIFT) &amp;amp; 1) | /* Wait for START = 0 */&lt;BR /&gt; ((DMA-&amp;gt;TCD[0].CSR &amp;gt;&amp;gt; DMA_TCD_CSR_ACTIVE_SHIFT) &amp;amp; 1)) {} /* and ACTIVE = 0 */&lt;BR /&gt; /* Now minor loop has completed */&lt;BR /&gt; count++;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; &lt;EM&gt;&lt;STRONG&gt;if(count&amp;gt;=511){&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt; while((LPSPI0-&amp;gt;SR &amp;amp; LPSPI_SR_TCF_MASK)&amp;gt;&amp;gt;LPSPI_SR_TCF_SHIFT==0); /* Wait for Transfer to be complete*/&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt; LPSPI0-&amp;gt;SR |= LPSPI_SR_TCF_MASK; /* Clear TCF flag */&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt; }&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;}&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;It was probably the delay time of the if statement + checking it&amp;nbsp;that allows it to slow down and finishes the final transfers. It doesn't seem to be the best way to do it but it works for now. Let me know if you know why it only works for odds calls&amp;nbsp;and if there is a better way to check for the complete transfer. Thanks very much for your help!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;Austin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Jul 2020 17:57:37 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S32K/SPI-DMA-problem/m-p/1073404#M7429</guid>
      <dc:creator>trunghieudon</dc:creator>
      <dc:date>2020-07-10T17:57:37Z</dc:date>
    </item>
    <item>
      <title>Re: SPI DMA problem</title>
      <link>https://community.nxp.com/t5/S32K/SPI-DMA-problem/m-p/1073405#M7430</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Austin,&lt;/P&gt;&lt;P&gt;Apparently, the root cause is that you use DMA and the core at the same time to fill the TX FIFO. And the Watermark changes the timing. I guess you should use a mutex and don't allow the core to write to the data register when the DMA is using it. Once the DMA transfer is complete, you could read the Module Busy Flag (MBF) or check the number of words in the TX FIFO (FSR_TXCOUNT).&lt;/P&gt;&lt;P&gt;By the way, your TCF clearing is not good, it clears all the other w1c flags in the status register that are set at the time of the write (read-modify-write operation).&lt;/P&gt;&lt;P&gt;Mask the TCF flag only: LPSPI0-&amp;gt;SR = LPSPI_SR_TCF_MASK; /* Clear TCF flag */&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Daniel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Jul 2020 14:19:25 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S32K/SPI-DMA-problem/m-p/1073405#M7430</guid>
      <dc:creator>danielmartynek</dc:creator>
      <dc:date>2020-07-13T14:19:25Z</dc:date>
    </item>
  </channel>
</rss>

