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
MRich.2
Associate

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.

Exact, same issue for CubeMX, V6.5.0

@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

When you say not working, did you get zeros in the output? Or did you get in a deadlock​?

@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

we dont need to firmware by ourselves, lets talk

good luck with that

we dont need to firmware by ourselves, lets talk

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

we dont need to firmware by ourselves, lets talk

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.

we dont need to firmware by ourselves, lets talk
Johannes
Senior

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

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