cancel
Showing results for 
Search instead for 
Did you mean: 

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

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

49 REPLIES 49
Sara BEN HADJ YAHYA
ST Employee

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 III

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

Johannes
Senior

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 

victagayun
Senior III

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.

victagayun
Senior III

Here is the other ioc file

This seems to be a good solution at the moment.

I deleted the peripheral and added them again together with the DMA.

If you add the DMA at a later stage, the DMA might be in the wrong sequence.

This is good for simple peripherals like UART, SPI or I2C.

The problem is when the peripherals are complicated like SRAM or HDMI/LCD.

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.

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.

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.

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.