Skip to main content
GZini.16
Visitor II
November 22, 2022
Solved

Possible erroneous CubeMx code generation

  • November 22, 2022
  • 1 reply
  • 1050 views

I noticed that CubeMx (version 6.6.1 and earlier) when generating the code, may place the MX_DMA_Init() function after other ***_init functions that configure DMA registers. The problem is that those registers cannot be accessed 'before' enabling the DMA clock. For example here is a snippet of erroneous code:

 MX_ADC1_Init();
 MX_ADC3_Init();
 MX_I2C2_Init();
 MX_I2C3_Init();
 MX_SPI1_Init();
 MX_SPI2_Init();
 MX_DMA_Init();

In the example above the ADC1 and ADC3 peripheral use the DMA mode, but the DMA is not initialized yet. In attachment there is the whole main.c file containing the above snippet.

A possible workaround could be to impose the clock initialization before any other initialization:

 /* USER CODE BEGIN SysInit */
 /* Workaround for a CubeMx bug */
 __HAL_RCC_DMA2_CLK_ENABLE();
 /* USER CODE END SysInit */

This topic has been closed for replies.
Best answer by Ghofrane GSOURI

Hello @GZini.16​ ;

First let me thank you for posting.

I assume this is the exact same issue already reported to the development team and tracked by the

Internal ticket number: 132093

(This is an internal tracking number and is not accessible or usable by customers).

and that will be fixed as soon as possible.

I will keep you posted with updates.

Thx

Ghofrane

1 reply

Ghofrane GSOURI
Technical Moderator
November 22, 2022

Hello @GZini.16​ ;

First let me thank you for posting.

I assume this is the exact same issue already reported to the development team and tracked by the

Internal ticket number: 132093

(This is an internal tracking number and is not accessible or usable by customers).

and that will be fixed as soon as possible.

I will keep you posted with updates.

Thx

Ghofrane

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.