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

MBook.1
Associate
October 1, 2022

Using STM32CubeMX 6.6.1 RC2 Build 20220706-1420 (UTC) and STMCubeIDE 1.10.1

Started a new project for STM32H730 with just a single ADC enabled. This worked under polling. Then tried to enable several ADC channels on ADC1 with DMA.

DMA still gets fixed under all the other function calls and can't be moved - why? At least let the user change the order if it's not going to work automatically.

The ioc file doesn't match the instructions given in previous posts so I'm stuck with changing the order of calls in the program every time I change an option. It's definitely not cool.

Please get this changed properly.

victagayun
Senior III
October 2, 2022

Seems to be a problem when you later decide that you may need a DMA at a later time.

MBook.1
Associate
October 3, 2022

@victagayun​ Thanks for the reply

@Support I've tried it with a Nucleo board (Nucleo STM32L4R5ZI) I have here. I can run the ADC to DMA with no problems. It is definitely something to do with the STM32H730 initialisation file - other devices (at least the one I've used) behave in the way expected. The problem is we're using the H730 and the DMA doesn't work at all because it's in the wrong place - and it can't be moved using the Project Manager.

My colleague is trying to test the OctoSPI using MDMA and it has the same problem.

Please fix this so we can get on and test the board and design our software.

MRich.2
Graduate
October 26, 2022

Test with STM32CubeIDE v1.10.1 containing STM32CubeMX STMicroelectronics 6.6.1.202207061420, creating project for NUCLEO-H7232ZG to use DMA to move data from memory to USART3.

Initialization order created by STM32CubeMX is still wrong:

/* Configure the system clock */

 SystemClock_Config();

 /* USER CODE BEGIN SysInit */

 /* USER CODE END SysInit */

 /* Initialize all configured peripherals */

 MX_GPIO_Init();

 MX_ETH_Init();

 MX_USART3_UART_Init();

 MX_DMA_Init();

 MX_USB_OTG_HS_USB_Init();

 /* USER CODE BEGIN 2 */

In Project Manager - Advanced Settings - Generated Function Calls, the engry for MX_DMA_Init() is greyed out and cannot be moved, butthe MX_USART3_UART_Init() entry can be shifted down to correct the error.

waclawek.jan
Super User
November 6, 2022

@CJans.1​  provided a workaround, which may perhaps be a somewhat more persistent solution? I don't use Cube/CubeMX so can't judge.

JW

Javier1
Principal
March 1, 2023

I do the same, to manually override initialization of the DMA, but every time i click autogenerate it tends to switch them back to the wrong order, it gets very tyring after a while.

hit me up in https://www.linkedin.com/in/javiermuñoz/
Piranha
Principal III
March 1, 2023

Clearly you didn't even read the link Jan gave...

Johannes
Senior
March 1, 2023

You can edit the ioc file manually with a text editor.

Just look at this line:

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

Here you can modify the order of initialization.

You can move the DMA init to position 3 (change the numbers with it).

From now on, the CubeMX will generate correct code.

Johannes