cancel
Showing results for 
Search instead for 
Did you mean: 

DMA not working in CubeMX generated code - order of initialization

Here is a (possibly incomplete) list of threads affected by this CubeMX issue:

https://community.st.com/s/question/0D50X0000BVnBhASQV/bug-report-dma-and-adc-initialization-order-changed-in-stm32f4-hal-v1241-causing-incorrect-adc-operation

https://community.st.com/s/feed/0D50X0000BZFWRISQ5

https://community.st.com/s/question/0D50X0000BbKaA5SQK/haluarttransmitdma-doesnt

https://community.st.com/s/question/0D50X0000BbMcnpSQC/dma-adc-doesnt-work

https://community.st.com/s/question/0D50X0000BWqGdtSQF/haladcstartdma-init-msp-bug

https://community.st.com/s/question/0D50X0000BcS7tSSQS/stmcubeide-110-cubemx-540-switch-initialization-order

https://community.st.com/s/question/0D50X0000BVnBhASQV/bug-report-dma-and-adc-initialization-order-changed-in-stm32f4-hal-v1241-causing-incorrect-adc-operation

https://community.st.com/s/question/0D50X0000Bfs7MvSQI/stm32f3-adc-with-dma-bug

https://community.st.com/s/question/0D50X0000Bh6PntSQE/bug-mxdmainit-wrongly-placed-by-code-generator-haluarttransmitdma-does-not-work

https://community.st.com/s/question/0D50X0000BiA27LSQS/code-generated-calls-mxdmainit-too-late-after-mxspiinit

https://community.st.com/s/question/0D50X0000BcPXk2SQG/32f746-usart-dma-with-stemwin-not-working

 https://community.st.com/s/question/0D50X0000BmoZgKSQU/simple-uart1-dma-dosent-work-generated-with-latest-stm32cubemx-540-and-stm32f0-1110

This is just in case somebody would like to put up a sticky post with this...

JW

[EDIT] Further development with CubeMX5.5

https://community.st.com/s/question/0D50X0000Bwjgi7SQA/with-stm32cubemx-55-and-stm32h743-the-mxdmainit-function-is-not-called-at-the-right-time

[EDIT] Problem reappeared 6.3.0 https://community.st.com/s/question/0D53W000011uIPgSAM/adc-dmahandle-is-0

[EDIT] Official method to fix the incorrect order, if project was generated in "incorrect" version of CubeMX: https://community.st.com/s/question/0D53W00001EzCmCSAV/mxdmainit-order-in-the-mainc-file-generated-by-stm32cubemx-how-to-fix

39 REPLIES 39

> Part of the problem is that nowhere in any of the examples or documentation for DMA does it mention the fact the one must enable the clock to the DMA before doing anything.

True, and the RM may've explicitly mentioned that; OTOH, this is one of the things which are expected to come from general understanding of the modern electronics, a.k.a. "everybody knows" that *all* peripherals (bar some rare exceptions) need to have clock enabled before they are used.

Also, this particular issue stems from the desire of users to generate code entirely by clicking and it's probably a well-deserved lesson to highlight the pitfalls of that process.

JW

Standa Standa
Associate II

Thanks for the post... Confirming this bug with this configuration in CubeMX 6.3.0:

ADC group conversion regular, triggered by TIM1. Data via DMA into circular buffer. Memory address wont increment and transaction ends up with ADC overrun.

Changing the order of init routines for DMA and ADC as described above fixes the issue (dma initialized first).

 MX_DMA_Init();

 MX_ADC1_Init();

AndreaC
Associate III

Also with STM32L0, Cube 6.3.0 and libraries V1.12.1, if

  MX_USART1_UART_Init();

precedes

  MX_DMA_Init();

then bit MINC in DMA CCR register is not set and DMA reception doesn't work

Hi @AndreaC​ ,

This known issue should be already fixed with STM32CUbeMX 6.4.0 version.

Please try to switch to this new release.

-Amel

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Hi Amel and thanks for your reply.

I updated CubeMX and regenereated the code but the issue is still present.

I applied @JStor.2​ suggestion to make the solution permanent.

Indeed, that is an expected behaviour because you are not generating your project from scratch but based on an ioc file with issue.

This is said, an internal ticket is submitted in order to improve the tool and avoid such side effect.

Internal ticket number: 118838 (PS: This is an internal tracking number and is not accessible or usable by customers).

Amel

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Got it, thanks.

Here is the official method to fix the incorrect order, if project was generated in "incorrect" version of CubeMX:

https://community.st.com/s/question/0D53W00001EzCmCSAV/mxdmainit-order-in-the-mainc-file-generated-by-stm32cubemx-how-to-fix

JW

DPaen.2
Associate II

Thank you. I changed Rank.

Charles Miller
Associate III

Unfortunately, the bug persists in version 6.5 (I'm working with STM32F756, Nucleo board)

The work-around is to call

__HAL_RCC_DMA1_CLK_ENABLE()

and/or

__HAL_RCC_DMA2_CLK_ENABLE()

before calling any of the ...Init functions.

Peripherals using DMA assume DMA configuration functions (register manipulations) are working (if called)--and this only happens if the DMA clocks are first enabled. Sent a message Imen Dahmen.