Skip to main content
Ernesto B
Associate
January 15, 2017
Solved

Problems with ADC and dma

  • January 15, 2017
  • 3 replies
  • 1346 views

Posted on January 15, 2017 at 21:34

 

 

The original post was too long to process during our migration. Please click on the attachment to read the original post.

https://community.st.com/s/question/0D50X00009XkdduSAB/triggering-adc-in-dual-mode-with-dma-problems

    This topic has been closed for replies.
    Best answer by Ernesto B
    Posted on January 26, 2017 at 11:59

    At the end it seems the problem was this one:

    https://community.st.com/0D50X00009XkdfSSAR

    Having a look at the code generated by STM32CubeMX, where it says:

    hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;�?�?�?�?

    Is wrong, it should be:

    hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;�?�?�?�?

    So STM32CubeMX is not generating the correct initialization code for the chosen options.

    Cheers.

    3 replies

    Ernesto B
    Ernesto BAuthorBest answer
    Associate
    January 26, 2017
    Posted on January 26, 2017 at 11:59

    At the end it seems the problem was this one:

    https://community.st.com/0D50X00009XkdfSSAR

    Having a look at the code generated by STM32CubeMX, where it says:

    hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;�?�?�?�?

    Is wrong, it should be:

    hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;�?�?�?�?

    So STM32CubeMX is not generating the correct initialization code for the chosen options.

    Cheers.

    ST Technical Moderator
    April 7, 2017
    Posted on April 07, 2017 at 17:29

    Hello

    Barragan.Ernesto

    ,

    I reported this issue internally to our CubeMx team for further check and investigation.

    Thank your for your contribution.

    Regards

    Imen

    In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Thanks
    Angus Cunningham-Burley_O
    Visitor II
    August 25, 2017
    Posted on August 25, 2017 at 12:37

    Hello

    Barragan.Ernesto

    ,

    I have tried to reproduce your configuration with CubeMX 4.

    HoweverI'm unable to get the same generated code as you for the Peripheral DMA init.

    If IactivateUse Fifo (enable FIFOMode), then I obtain:

    hdma_adc1.Instance = DMA2_Stream0;

    hdma_adc1.Init.Channel = DMA_CHANNEL_0;

    hdma_adc1.Init.Direction = DMA_PERIPH_TO_MEMORY;

    hdma_adc1.Init.PeriphInc = DMA_PINC_DISABLE;

    hdma_adc1.Init.MemInc = DMA_MINC_ENABLE;

    hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;

    hdma_adc1.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;

    hdma_adc1.Init.Mode = DMA_NORMAL;

    hdma_adc1.Init.Priority = DMA_PRIORITY_VERY_HIGH;

    hdma_adc1.Init.FIFOMode = DMA_FIFOMODE_ENABLE;

    hdma_adc1.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_HALFFULL;

    hdma_adc1.Init.MemBurst = DMA_MBURST_SINGLE;

    hdma_adc1.Init.PeriphBurst = DMA_PBURST_SINGLE;

    But if I deactivate Use Fifo (disable FIFOMode), then I get:

    hdma_adc1.Instance = DMA2_Stream0;

    hdma_adc1.Init.Channel = DMA_CHANNEL_0;

    hdma_adc1.Init.Direction = DMA_PERIPH_TO_MEMORY;

    hdma_adc1.Init.PeriphInc = DMA_PINC_DISABLE;

    hdma_adc1.Init.MemInc = DMA_MINC_ENABLE;

    hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;

    hdma_adc1.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;

    hdma_adc1.Init.Mode = DMA_NORMAL;

    hdma_adc1.Init.Priority = DMA_PRIORITY_VERY_HIGH;

    hdma_adc1.Init.FIFOMode = DMA_FIFOMODE_DISABLE;

    You say that your problem is resolved when you change the source transfer width.

    hdma_adc1

    .

    Init

    .

    PeriphDataAlignment

    =

    DMA_PDATAALIGN_WORD

    ;

    If -as your code suggests - the Fifo is disabled (direct mode) then data packing/unpacking is not possible and the source and destination transfer data widths are the same and defined by PeriphDataAlignment (PSIZE). This means that although your 'corrected' source code may read:

    hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;

    hdma_adc1.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;

    the hardware implementationwill beequivalent to:

    hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;

    hdma_adc1.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;

    Can you please confirm whether the Fifo mode is enabled or disabled in you code?

    Many thanks,

    Angus