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
Louis Cloete work
Associate III

Any place where I can see if this is fixed in the newest CubeMX?

Hi @Community member​ ,

Did you downloaded latest CubeMX version (5.6)? The issue is already fixed.

-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.

Thanks for the reply. I did not download it because of data usage concerns. I'll download it now that I know it is fixed.

For future reference, do you have a place where we can see the status of publicly-reported bugs? It would be very useful.

Hi @Community member​ ,

Generally, when a new STM32CubeMX version is released, we make a post listing known limitations and some fixed issues, like https://community.st.com/s/question/0D50X0000CBkdCTSQZ/stm32cubemx-560-released.

-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.

Thanks!

Hi Amel,

this thread https://community.st.com/s/question/0D53W000004HgujSAC/the-stm32g484cetx-initialization-code-generated-by-stm32cubemx-has-a-bug appears to say that the problem persists in CubeMX v5.6.0 ?

JW

@Amel NASRI​ 

JStor.2
Associate

Can confirm that this is (still) a problem with recent STM32CubeIDE versions. I've run into this problem on STM32CubeIDE 1.7.0 (which has STM32CubeMX 6.3.0)

To reproduce:

  • Start a new STM32 Project in STM32CubeIDE
  • Enable an I2C peripheral in the Device Configuration Tool
  • Generate code
  • Add DMA channels to the I2C peripheral
  • Generate code again
  • Observe in `main.c` that `MX_I2C1_Init()` is called before `MX_DMA_Init()`
  • Observe that the HAL_I2C_*_DMA() functions don't work

I tried both `HAL_I2C_Master_Transmit_DMA()` and `HAL_I2C_Master_Receive_DMA()`. Swapping the initialization order in the genrated code (calling `MX_DMA_Init()` before `MX_I2C1_Init()`) causes the functions to work.

Note that the following sequence leads to code that's generated in the correct order:

  • Start a new STM32 Project
  • Enable an I2C peripheral in the Device Configuration Tool
  • Add DMA channels to the I2C peripheral
  • Generate code

This implies that it's a bug in the "Updating Code" step.

I was able to fix the problem by manually moving `MX_DMA_Init()` before `MX_I2C1_Init()`. The code remained working even when the code was re-generated. It also meant that I didn't have to create a new .ioc file, or disable/re-enable peripherals, to fix the problem.

It also appears that similar problems exist with other DMA-enabled peripherals -- I repeated the same steps above with the I2C, SPI and USART peripherals, and observed the same behaviour for each of the peripherals.

For completeness, I was using STM32Cube FW_F0, targetting an STM32F042K6Tx (but I don't think this information is particularly relevant)

Can't edit, so just to note that manually changing the order in `main.c` actually didn't fix the issue. The correct fix is to re-order in the Device Configuration Tool -- as noted in https://community.st.com/s/question/0D50X0000Boy3eVSQQ/cubemx-540-generates-broken-code-for-stm32h7-stm32h7432-sai-dma

Use the buttons (3) to move `MX_DMA_Init()` above the peripheral init

0693W00000FBsbDQAT.png

Hi @JStor.2​ ,

Unfortunately this is a regression issue introduced wit STM32CubeMX 6.3 and STM32CubeIDE 1.7.0.

This is tracked internally and should be fixed on coming release of the tool. @Khouloud OTHMAN​ can confirm about fix availability.

Internal ticket 112040 : 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.

FColl.1
Associate III

Funny how all my googling about "STM32 Can not set DMA configuration register" "DMA CR not writing with ADC" etc. etc. did not bring me here. I had to figure out the bug myself, wasting half a day. This is very annoying given it is a known issue. 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. Can someone from STM please make a note to add to the DMA documentation a tip to enable it first up??