<?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>LPC MicrocontrollersのトピックADC with DMA FIFO issue</title>
    <link>https://community.nxp.com/t5/LPC-Microcontrollers/ADC-with-DMA-FIFO-issue/m-p/1835256#M55748</link>
    <description>&lt;P&gt;MCU: LPC5536. Board: custom.&lt;/P&gt;&lt;P&gt;I am trying to read ADC measurements with DMA. However, on the first run, only 3 out of 9 values are "grabbed"&amp;nbsp; by DMA, which results in DMA transfer done callback getting called only after the second ADC trigger.&lt;/P&gt;&lt;P&gt;Here is how it looks. ADC0 is 10 channels, ADC1 is 9 channels. Watermarks FIFO0 are 9 and 8 respectively. DMA0 channels are 21 for ADC0 and 27 for ADC1.&lt;/P&gt;&lt;P&gt;ADC clocks are 24 MHz.&lt;/P&gt;&lt;P&gt;Reading procedure:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;// On the first run:

void ReadAllChannels()
{
    uint32_t testFifoAdc0 = LPADC_GetConvResultCount(ADC0, 0U); // = 0
    LPADC_DoSoftwareTrigger(LPADC_ADC0, 1U); 
    testFifoAdc0 = LPADC_GetConvResultCount(ADC0, 0U); // = 10
    DMA_DoChannelSoftwareTrigger(ADC_DMA_BASE, DMA_ADC0_CHANNEL);
    testFifoAdc0 = LPADC_GetConvResultCount(ADC0, 0U); // = 7!!!
 
    uint32_t testFifoAdc1 = LPADC_GetConvResultCount(ADC1, 0U); // =0
    LPADC_DoSoftwareTrigger(LPADC_ADC1, 1U); 
    testFifoAdc1 = LPADC_GetConvResultCount(ADC1, 0U); // = 9
    
    DMA_DoChannelSoftwareTrigger(ADC_DMA_BASE, DMA_ADC1_CHANNEL);
    testFifoAdc1 = LPADC_GetConvResultCount(ADC1, 0U); // = 6!!!
}

// On the SECOND and consecutive runs:

void ReadAllChannels()
{
    uint32_t testFifoAdc0 = LPADC_GetConvResultCount(ADC0, 0U); // = 7
    LPADC_DoSoftwareTrigger(LPADC_ADC0, 1U); 
    // here ADC0 DMA callback fires... 
    testFifoAdc0 = LPADC_GetConvResultCount(ADC0, 0U); // = 10
    DMA_DoChannelSoftwareTrigger(ADC_DMA_BASE, DMA_ADC0_CHANNEL);
    testFifoAdc0 = LPADC_GetConvResultCount(ADC0, 0U); // still = 7!!!
 
    uint32_t testFifoAdc1 = LPADC_GetConvResultCount(ADC1, 0U); // =6
    LPADC_DoSoftwareTrigger(LPADC_ADC1, 1U); 
    // here ADC1 Dma callback fires...
    testFifoAdc1 = LPADC_GetConvResultCount(ADC1, 0U); // = 9
    DMA_DoChannelSoftwareTrigger(ADC_DMA_BASE, DMA_ADC1_CHANNEL);
    testFifoAdc1 = LPADC_GetConvResultCount(ADC1, 0U); // = 6!!!
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DMA configs:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;#define LPADC0_RESFIFO_REG_ADDR     (uint32_t)(&amp;amp;(ADC0-&amp;gt;RESFIFO[0]))
static DMA_ALLOCATE_LINK_DESCRIPTORS(adc0DmaDesc, 1);
uint32_t adc0ConvResults[10];

static void DMA_ADC0_Configuration()
{
    dma_channel_config_t dmaChannelConfigStruct;

    DMA_EnableChannel(ADC_DMA_BASE, DMA_ADC0_CHANNEL);
    DMA_CreateHandle(&amp;amp;dmaAdc0HandleStruct, ADC_DMA_BASE, DMA_ADC0_CHANNEL);
    DMA_SetCallback(&amp;amp;dmaAdc0HandleStruct, ADC0_DMA_Callback, NULL);

    uint32_t g_XferConfig = DMA_CHANNEL_XFER(true,                          
                                            true,                          
                                            true,                           
                                            false,                         
                                            sizeof(uint32_t),              
                                            kDMA_AddressInterleave0xWidth,
                                            kDMA_AddressInterleave1xWidth,
                                            10* sizeof(uint32_t) 
                                            );

    DMA_PrepareChannelTransfer(&amp;amp;dmaChannelConfigStruct,              
                               (void *)LPADC0_RESFIFO_REG_ADDR,      
                               (void*)adc0ConvResults,                  
                               g_XferConfig,                         
                               ADC_DMA_TRANSFER_TYPE,  // peripheral to memory              
                               NULL,                                 
                               (dma_descriptor_t *)&amp;amp;(adc0DmaDesc[0])
    );

    DMA_SetupDescriptor(
                        (dma_descriptor_t *)&amp;amp;(adc0DmaDesc[0]), 
                        g_XferConfig,
                        (void *)LPADC0_RESFIFO_REG_ADDR,
                        (void*)adc0ConvResults, 
                        (dma_descriptor_t *)&amp;amp;(adc0DmaDesc[0]));

    DMA_SubmitChannelTransfer(&amp;amp;dmaAdc0HandleStruct, &amp;amp;dmaChannelConfigStruct);
    DMA_SetChannelConfigValid(ADC_DMA_BASE, DMA_ADC0_CHANNEL);
}


#define LPADC1_RESFIFO_REG_ADDR     (uint32_t)(&amp;amp;(ADC1-&amp;gt;RESFIFO[0]))
static DMA_ALLOCATE_LINK_DESCRIPTORS(adc1DmaDesc, 1);
uint32_t adc1ConvResults[9];

static void DMA_ADC1_Configuration()
{
    dma_channel_config_t dmaChannelConfigStruct;

    DMA_EnableChannel(ADC_DMA_BASE, DMA_ADC1_CHANNEL);
    DMA_CreateHandle(&amp;amp;dmaAdc1HandleStruct, ADC_DMA_BASE, DMA_ADC1_CHANNEL);
    DMA_SetCallback(&amp;amp;dmaAdc1HandleStruct, ADC1_DMA_Callback, NULL);

    uint32_t g_XferConfig = DMA_CHANNEL_XFER(true,
                                            true,
                                            true,
                                            false,
                                            sizeof(uint32_t),
                                            kDMA_AddressInterleave0xWidth,
                                            kDMA_AddressInterleave1xWidth,
                                            9* sizeof(uint32_t)
                                            );


    DMA_PrepareChannelTransfer(&amp;amp;dmaChannelConfigStruct,              
                               (void *)LPADC1_RESFIFO_REG_ADDR,
                               (void*)adc1ConvResults,
                               g_XferConfig,
                               ADC_DMA_TRANSFER_TYPE,
                               NULL,
                               (dma_descriptor_t *)&amp;amp;(adc1DmaDesc[0])
    );

    DMA_SetupDescriptor(
                        (dma_descriptor_t *)&amp;amp;(adc1DmaDesc[0]), 
                        g_XferConfig,
                        (void *)LPADC1_RESFIFO_REG_ADDR,
                        (void*)adc1ConvResults, 
                        (dma_descriptor_t *)&amp;amp;(adc1DmaDesc[0]));

    DMA_SubmitChannelTransfer(&amp;amp;dmaAdc1HandleStruct, &amp;amp;dmaChannelConfigStruct);
    
    DMA_SetChannelConfigValid(ADC_DMA_BASE, DMA_ADC1_CHANNEL);
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ADC channels for both ADC peripherals are configured to send conv values to FIFO0.&lt;/P&gt;&lt;P&gt;I have seen this post, they report a similar behaviour &lt;A href="https://community.nxp.com/t5/LPC-Microcontrollers/Using-Configtools-to-set-up-ADC-and-DMA-from-scratch-Sample/m-p/1183779" target="_blank" rel="noopener"&gt;https://community.nxp.com/t5/LPC-Microcontrollers/Using-Configtools-to-set-up-ADC-and-DMA-from-scratch-Sample/m-p/1183779&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What can I do?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 26 Mar 2024 08:27:39 GMT</pubDate>
    <dc:creator>leannee</dc:creator>
    <dc:date>2024-03-26T08:27:39Z</dc:date>
    <item>
      <title>ADC with DMA FIFO issue</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/ADC-with-DMA-FIFO-issue/m-p/1835256#M55748</link>
      <description>&lt;P&gt;MCU: LPC5536. Board: custom.&lt;/P&gt;&lt;P&gt;I am trying to read ADC measurements with DMA. However, on the first run, only 3 out of 9 values are "grabbed"&amp;nbsp; by DMA, which results in DMA transfer done callback getting called only after the second ADC trigger.&lt;/P&gt;&lt;P&gt;Here is how it looks. ADC0 is 10 channels, ADC1 is 9 channels. Watermarks FIFO0 are 9 and 8 respectively. DMA0 channels are 21 for ADC0 and 27 for ADC1.&lt;/P&gt;&lt;P&gt;ADC clocks are 24 MHz.&lt;/P&gt;&lt;P&gt;Reading procedure:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;// On the first run:

void ReadAllChannels()
{
    uint32_t testFifoAdc0 = LPADC_GetConvResultCount(ADC0, 0U); // = 0
    LPADC_DoSoftwareTrigger(LPADC_ADC0, 1U); 
    testFifoAdc0 = LPADC_GetConvResultCount(ADC0, 0U); // = 10
    DMA_DoChannelSoftwareTrigger(ADC_DMA_BASE, DMA_ADC0_CHANNEL);
    testFifoAdc0 = LPADC_GetConvResultCount(ADC0, 0U); // = 7!!!
 
    uint32_t testFifoAdc1 = LPADC_GetConvResultCount(ADC1, 0U); // =0
    LPADC_DoSoftwareTrigger(LPADC_ADC1, 1U); 
    testFifoAdc1 = LPADC_GetConvResultCount(ADC1, 0U); // = 9
    
    DMA_DoChannelSoftwareTrigger(ADC_DMA_BASE, DMA_ADC1_CHANNEL);
    testFifoAdc1 = LPADC_GetConvResultCount(ADC1, 0U); // = 6!!!
}

// On the SECOND and consecutive runs:

void ReadAllChannels()
{
    uint32_t testFifoAdc0 = LPADC_GetConvResultCount(ADC0, 0U); // = 7
    LPADC_DoSoftwareTrigger(LPADC_ADC0, 1U); 
    // here ADC0 DMA callback fires... 
    testFifoAdc0 = LPADC_GetConvResultCount(ADC0, 0U); // = 10
    DMA_DoChannelSoftwareTrigger(ADC_DMA_BASE, DMA_ADC0_CHANNEL);
    testFifoAdc0 = LPADC_GetConvResultCount(ADC0, 0U); // still = 7!!!
 
    uint32_t testFifoAdc1 = LPADC_GetConvResultCount(ADC1, 0U); // =6
    LPADC_DoSoftwareTrigger(LPADC_ADC1, 1U); 
    // here ADC1 Dma callback fires...
    testFifoAdc1 = LPADC_GetConvResultCount(ADC1, 0U); // = 9
    DMA_DoChannelSoftwareTrigger(ADC_DMA_BASE, DMA_ADC1_CHANNEL);
    testFifoAdc1 = LPADC_GetConvResultCount(ADC1, 0U); // = 6!!!
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DMA configs:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;#define LPADC0_RESFIFO_REG_ADDR     (uint32_t)(&amp;amp;(ADC0-&amp;gt;RESFIFO[0]))
static DMA_ALLOCATE_LINK_DESCRIPTORS(adc0DmaDesc, 1);
uint32_t adc0ConvResults[10];

static void DMA_ADC0_Configuration()
{
    dma_channel_config_t dmaChannelConfigStruct;

    DMA_EnableChannel(ADC_DMA_BASE, DMA_ADC0_CHANNEL);
    DMA_CreateHandle(&amp;amp;dmaAdc0HandleStruct, ADC_DMA_BASE, DMA_ADC0_CHANNEL);
    DMA_SetCallback(&amp;amp;dmaAdc0HandleStruct, ADC0_DMA_Callback, NULL);

    uint32_t g_XferConfig = DMA_CHANNEL_XFER(true,                          
                                            true,                          
                                            true,                           
                                            false,                         
                                            sizeof(uint32_t),              
                                            kDMA_AddressInterleave0xWidth,
                                            kDMA_AddressInterleave1xWidth,
                                            10* sizeof(uint32_t) 
                                            );

    DMA_PrepareChannelTransfer(&amp;amp;dmaChannelConfigStruct,              
                               (void *)LPADC0_RESFIFO_REG_ADDR,      
                               (void*)adc0ConvResults,                  
                               g_XferConfig,                         
                               ADC_DMA_TRANSFER_TYPE,  // peripheral to memory              
                               NULL,                                 
                               (dma_descriptor_t *)&amp;amp;(adc0DmaDesc[0])
    );

    DMA_SetupDescriptor(
                        (dma_descriptor_t *)&amp;amp;(adc0DmaDesc[0]), 
                        g_XferConfig,
                        (void *)LPADC0_RESFIFO_REG_ADDR,
                        (void*)adc0ConvResults, 
                        (dma_descriptor_t *)&amp;amp;(adc0DmaDesc[0]));

    DMA_SubmitChannelTransfer(&amp;amp;dmaAdc0HandleStruct, &amp;amp;dmaChannelConfigStruct);
    DMA_SetChannelConfigValid(ADC_DMA_BASE, DMA_ADC0_CHANNEL);
}


#define LPADC1_RESFIFO_REG_ADDR     (uint32_t)(&amp;amp;(ADC1-&amp;gt;RESFIFO[0]))
static DMA_ALLOCATE_LINK_DESCRIPTORS(adc1DmaDesc, 1);
uint32_t adc1ConvResults[9];

static void DMA_ADC1_Configuration()
{
    dma_channel_config_t dmaChannelConfigStruct;

    DMA_EnableChannel(ADC_DMA_BASE, DMA_ADC1_CHANNEL);
    DMA_CreateHandle(&amp;amp;dmaAdc1HandleStruct, ADC_DMA_BASE, DMA_ADC1_CHANNEL);
    DMA_SetCallback(&amp;amp;dmaAdc1HandleStruct, ADC1_DMA_Callback, NULL);

    uint32_t g_XferConfig = DMA_CHANNEL_XFER(true,
                                            true,
                                            true,
                                            false,
                                            sizeof(uint32_t),
                                            kDMA_AddressInterleave0xWidth,
                                            kDMA_AddressInterleave1xWidth,
                                            9* sizeof(uint32_t)
                                            );


    DMA_PrepareChannelTransfer(&amp;amp;dmaChannelConfigStruct,              
                               (void *)LPADC1_RESFIFO_REG_ADDR,
                               (void*)adc1ConvResults,
                               g_XferConfig,
                               ADC_DMA_TRANSFER_TYPE,
                               NULL,
                               (dma_descriptor_t *)&amp;amp;(adc1DmaDesc[0])
    );

    DMA_SetupDescriptor(
                        (dma_descriptor_t *)&amp;amp;(adc1DmaDesc[0]), 
                        g_XferConfig,
                        (void *)LPADC1_RESFIFO_REG_ADDR,
                        (void*)adc1ConvResults, 
                        (dma_descriptor_t *)&amp;amp;(adc1DmaDesc[0]));

    DMA_SubmitChannelTransfer(&amp;amp;dmaAdc1HandleStruct, &amp;amp;dmaChannelConfigStruct);
    
    DMA_SetChannelConfigValid(ADC_DMA_BASE, DMA_ADC1_CHANNEL);
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ADC channels for both ADC peripherals are configured to send conv values to FIFO0.&lt;/P&gt;&lt;P&gt;I have seen this post, they report a similar behaviour &lt;A href="https://community.nxp.com/t5/LPC-Microcontrollers/Using-Configtools-to-set-up-ADC-and-DMA-from-scratch-Sample/m-p/1183779" target="_blank" rel="noopener"&gt;https://community.nxp.com/t5/LPC-Microcontrollers/Using-Configtools-to-set-up-ADC-and-DMA-from-scratch-Sample/m-p/1183779&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What can I do?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2024 08:27:39 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/ADC-with-DMA-FIFO-issue/m-p/1835256#M55748</guid>
      <dc:creator>leannee</dc:creator>
      <dc:date>2024-03-26T08:27:39Z</dc:date>
    </item>
    <item>
      <title>Re: ADC with DMA FIFO issue</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/ADC-with-DMA-FIFO-issue/m-p/1835425#M55753</link>
      <description>&lt;P&gt;Solved.&lt;/P&gt;&lt;P&gt;In LPC553x Reference Manual, chapter DMA Controller:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="leannee_0-1711453871210.png" style="width: 400px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/270437iC3958D965248087B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="leannee_0-1711453871210.png" alt="leannee_0-1711453871210.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;So in the end of DMA configuration function add this:&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;    DMA_DisableChannelPeriphRq(*dma_base*, *dma_channel*);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2024 11:52:45 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/ADC-with-DMA-FIFO-issue/m-p/1835425#M55753</guid>
      <dc:creator>leannee</dc:creator>
      <dc:date>2024-03-26T11:52:45Z</dc:date>
    </item>
  </channel>
</rss>

