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

1 ACCEPTED SOLUTION

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

View solution in original post

49 REPLIES 49
ABlig.1
Associate

Many thanks for posting this. It saved my sanity after a couple of frustrating days trying to get DMA working for the LPUART and the ADCs.

There are many posts on stackoverflow etc. saying that the DMA must be initialised before the thing that uses it, e.g. ADCs. I had moved the DMA initialisation to position 3 in the start up order (after GPIO and SystemClock_Config) but DMA didn't work. When I moved it to position 2 as shown above, DMA worked. So there must be some interaction between the DMA and the SystemClock_Config initialisation that is preventing the DMA from running correctly.

tldr: Make sure the order is:

  1. GPIO
  2. DMA
  3. SystemClock_Config
  4. the rest.
SSchu.4
Associate II

I have just generated code with this IDE

STM32CubeIDE

Version: 1.8.0

Build: 11526_20211125_0815 (UTC)

OS: Linux, v.5.13.0-28-generic, x86_64 / gtk 3.24.20, WebKit 2.34.4

Java version: 11.0.11

CubeMX Version: 6.4.0-RC4

Build: 20211122-2105 (UTC)

Still: Wrong code. WTF ST?

 /* Configure the system clock */
  SystemClock_Config();
 
  /* USER CODE BEGIN SysInit */
 
  /* USER CODE END SysInit */
 
  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_ADC1_Init();
  MX_DMA_Init();

PAkRad
Associate III

Version 6.5.0 - same thing!!!

0693W00000LyB9DQAV.png

@PAkRad​ ,

is this a project newly started in version 6.5.0, or did you migrate a project created in older version of CubeMX?

JW

PAkRad
Associate III

New project from scratch.

PAkRad
Associate III

@Community member​ new project from scratch, actually to test the new version.

parth kothiya
Senior

In latest version of cubeMX also same issue not resolved.

MX_GPIO_Init();

MX_ADC1_Init();

MX_DMA_Init();

Dma not working.​

I deside to switch another MCU.

Lots of bugs and when you design your own product using ST s MCU then you can't get solution immediately.​

Sara BEN HADJ YAHYA
ST Employee

Hello @parth kothiya​ , @PAkRad​ ,

I re-did the test from my part on an STM32H7 and I couldn't see the issue, the order is generated correctly.

Could you please share your ioc file and provide us with the exact scenario that led to this issue?

Thanks,

Sara.