Skip to main content
Khouloud OTHMAN
Technical Moderator
December 7, 2021
Solved

MX_DMA_Init order in the main.c file generated by STM32CubeMX, How to fix?

  • December 7, 2021
  • 25 replies
  • 21603 views

When DMA is used, the MX_DMA_Init shall always be called before any other HAL_***_Init (where *** is any peripheral with a HW dependency on DMA init code).

A regression was detected in the previous STM32CubeMX version 6.3.0 (STM32CubeIDE Version: 1.7.0 ) generating a wrong order of initialization functions.

This issue was fixed in the latest STM32CubeMX version 6.4.0. Thus, newly created project with this version will generate the correct initialization functions order.

Because the calling order is saved into the ioc file, the misplacement call to MX_DMA_Init() remains the same when trying to migrate automatically an old project from a buggy old version to the fixed version. The order stays the same and the generated code will be unfunctional.

For any old ioc file created by any STM32CubeMX version up to 6.3.0 included, hereafter some steps to overcome this misbehavior:

  • Open the saved .ioc file (already created with 6.3.0 version) with any text editor installed in your machine and delete the line: ProjectManager.functionlistsort=....

0693W00000HnoAHQAZ.png 

  • After saving the modification, re-open the .ioc file with latest CubeMX version 6.4.0 ( STM32CubeIDE Version: 1.8.0).
  • Through Project Manager view > Advanced Settings tab, make sure that the initialization functions are correctly ordered and re-generate your project:

0693W00000HnoBFQAZ.png

This topic has been closed for replies.
Best answer by Sara BEN HADJ YAHYA

Hello,

This issue is fixed in STM32CubeMX latest release.

V6.6.0 is now available under this Link.

Thanks for your contribution.

Sara.

25 replies

CWalk.1
Visitor II
May 31, 2022

Hello @Sara BEN HADJ YAHYA​ I have just been fighting this issue for a few days and finally solved on my own before finding this thread. The strange thing is I built a different project with the same version CubeMX (6.4) and one project listed MX_DMA_Init() in the correct location (in my case, before ADC init). But another project listed DMA init AFTER ADC init. I followed your guidance to modify the .ioc file (delete ProjectManager.functionlistsort=....) and it worked. I have since installed 6.5 and the issue persists. Will ST please address this?

ST Employee
May 31, 2022

hello @CWalk.1​ ,

Thanks for your feedback,

We are aware of this issue and the dev team is working on it. I will let you know once the issue is solved.

Sara.

CWork.1
Visitor II
June 16, 2022

I also have seen this with I2C Init

ST Employee
June 29, 2022

Hello,

This issue is fixed in STM32CubeMX latest release.

V6.6.0 is now available under this Link.

Thanks for your contribution.

Sara.

froesel
Associate II
June 30, 2022

Can confirm, this bug is not fixed in STM32Cube FW_H7 V1.10.0 :

 /* Initialize all configured peripherals */

 MX_GPIO_Init();

 MX_DTS_Init();

 MX_RTC_Init();

 MX_SPI2_Init();

 MX_TIM1_Init();

 MX_UART4_Init();

 MX_ADC1_Init();

 MX_DMA2D_Init();

 MX_I2C1_Init();

 MX_RNG_Init();

 MX_TIM5_Init();

 MX_TIM17_Init();

 MX_ADC2_Init();

 MX_COMP1_Init();

 MX_UART5_Init();

 MX_SDMMC2_SD_Init();

 MX_TIM4_Init();

 MX_UART8_Init();

 MX_I2C2_Init();

 MX_OCTOSPI2_Init();

 MX_UART9_Init();

 MX_CRC_Init();

 MX_FATFS_Init();

 MX_USB_DEVICE_Init();

 MX_DMA_Init();

 MX_TIM16_Init();

 MX_TouchGFX_Init();

 /* USER CODE BEGIN 2 */

workaround is manually editing to:

 /* Initialize all configured peripherals */

 MX_GPIO_Init();

 MX_DTS_Init();

 MX_RTC_Init();

 MX_DMA_Init();

 MX_SPI2_Init();

 MX_TIM1_Init();

 MX_UART4_Init();

 MX_ADC1_Init();

 MX_DMA2D_Init();

 MX_I2C1_Init();

 MX_RNG_Init();

 MX_TIM5_Init();

 MX_TIM17_Init();

 MX_ADC2_Init();

 MX_COMP1_Init();

 MX_UART5_Init();

 MX_SDMMC2_SD_Init();

 MX_TIM4_Init();

 MX_UART8_Init();

 MX_I2C2_Init();

 MX_OCTOSPI2_Init();

 MX_UART9_Init();

 MX_CRC_Init();

 MX_FATFS_Init();

 MX_USB_DEVICE_Init();

 MX_TIM16_Init();

 MX_TouchGFX_Init();

 /* USER CODE BEGIN 2 */

not that nice...

Florian

ST Employee
July 7, 2022

Hello @Florian Rösel​ ,

Did you migrate your project to the latest MX/IDE release (v6.6.0/ v1.10.0) with a wrong order or did you start a new project with the latest version?

Sara.

froesel
Associate II
July 11, 2022

was able to reproduce this situation in both scenarios - migration AND new project creation.

@Johannes​ 's workaround and his manual editing was the same I did and for now it works. But the original Problem still exists, you have to check manually, if the order is correct.

Johannes
Senior
July 6, 2022

The problem still exists with CubeIDE V1.9.0 on STM32L4 V1.17.2

New aspect: I normally can modify the order of initializaiton in IOC file in "Project Manager" / "Advanced settings"

0693W00000QKYosQAH.pngOne can see, that some lines are "fixed" and cannot be modified like "clock" "GPIO" and "DMA".

The Line ADC1 cannot be moved either. For some reason, ADC1 is not allowed to be moved. Others can be moved.

It is possible to edit this sequence though, by editing the IOC-File "by hand".

ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_DMA_Init-DMA-false-HAL-true,4-MX_ADC1_Init-ADC1-false-HAL-true,5-MX_CAN1_Init-CAN1-false-HAL-true,6-MX_DAC1_Init-DAC1-false-HAL-true,7-MX_I2C2_Init-I2C2-false-HAL-true,8-MX_ADC2_Init-ADC2-false-HAL-true,9-MX_SPI3_Init-SPI3-false-HAL-true,10-MX_TIM1_Init-TIM1-false-HAL-true,11-MX_TIM17_Init-TIM17-false-HAL-true,12-MX_TIM2_Init-TIM2-false-HAL-true,13-MX_UART5_Init-UART5-false-HAL-true,14-MX_USB_DEVICE_Init-USB_DEVICE-false-HAL-false

 Now it is correct

0693W00000QKYsQQAX.png 

ST Employee
July 7, 2022

Hello @Johannes​ ,

The issue is fixed in CubeMX/IDE latest release (v6.6.0/ v1.10.0). Could you please update your MX/IDE and check the order.

If you are planning to migrate your project to the latest CubeIDE version please check this thread first.

Sara.

Javier1
Principal
March 1, 2023

@Sara BEN HADJ YAHYA​ I got the same issue with cubeMx 6.6.1

I cannot change the order , for some reason DMa is greyed out and TIM1 cannot be moved neither

0693W00000aHy4dQAC.png 

0693W00000aHyEQQA0.png0693W00000aHyEfQAK.png 

For the others TIM3 and TIM17 , i am able to change positions

hit me up in https://www.linkedin.com/in/javiermuñoz/
victagayun
Senior III
July 6, 2022

One of my ioc files is in the correct order but the other one is like this.

0693W00000QKZOHQA5.png 

Thus, my HAL_UART_RxCpltCallback is not being called.

ST Employee
July 7, 2022

Hello @victagayun​ ,

Did you by any chance migrated your project to v1.10.0 with the wrong order or did you start a new project with the latest version?

Sara.

victagayun
Senior III
July 6, 2022
victagayun
Senior III
October 2, 2022

The only way to solve this is to open-source it!

Javier1
Principal
March 1, 2023

good luck with that

hit me up in https://www.linkedin.com/in/javiermuñoz/
WLear
Associate II
August 18, 2022

This problem STILL exists in CubeMX V6.6.1.

The original workaround of hand editing the .ioc file does correct the issue

Javier1
Principal
March 1, 2023

Not for me, aparently if you migrated the cubeMX from older versions DMA's place in the Advanced Settings menu cannot be changed

hit me up in https://www.linkedin.com/in/javiermuñoz/
victagayun
Senior III
August 26, 2022

Is the CubeMX open source or will be open sourced, so everyone can check the problem/s?