Skip to main content
REdmo.1
Associate II
November 7, 2022
Solved

Is there a bug in auto-generated CubeMX code that means DMA channels are not configured correctly for UARTS in STM32F407?

  • November 7, 2022
  • 2 replies
  • 1000 views

CubeMX (version 6.6.1 and others) generates this code.

 /* Initialize all configured peripherals */
 MX_GPIO_Init();
 MX_USART3_UART_Init();
 MX_I2C1_Init();
 MX_UART4_Init();
 MX_UART5_Init();
 MX_USART1_UART_Init();
 MX_DMA_Init();
 MX_USART6_UART_Init();
 MX_USART2_UART_Init();

The purpose of MX_DMA_Init() appears to be to configure the clocks for the required DMA peripherals. I don't see this being done anywhere else.

If DMA is being used for the UARTs, the MX_UART*_Init() functions call HAL_UART_Init() which calls HAL_UART_MspInit() which calls HAL_DMA_Init() which attempts to write to registers of the DMA peripheral(s).

Unfortunately, in the case of USART3, UART4, UART5 and USART1 in the example above, the clock for the DMA peripheral has not been enabled at this point and so the writes to registers of the DMA peripheral fail. The UART then does not operate as intended.

The workaround seems to be to explicitly call MX_DMA_Init() before this sequence.

 /* USER CODE BEGIN SysInit */
 
 MX_DMA_Init(); //bug in autogenerated code
 
 /* USER CODE END SysInit */
 
 /* Initialize all configured peripherals */
 MX_GPIO_Init();
 MX_USART3_UART_Init();
 MX_I2C1_Init();
 MX_UART4_Init();
 MX_UART5_Init();
 MX_USART1_UART_Init();
 MX_DMA_Init();
 MX_USART6_UART_Init();
 MX_USART2_UART_Init();

Or did I miss something?

Richard

This topic has been closed for replies.
Best answer by REdmo.1

Seems to be a duplicate of https://community.st.com/s/question/0D53W00001v1qjsSAA/stm32cubemx-initialization-bug

sorry (tho wish I'd known before trying to debug this)

2 replies

REdmo.1
REdmo.1AuthorBest answer
Associate II
November 7, 2022

Seems to be a duplicate of https://community.st.com/s/question/0D53W00001v1qjsSAA/stm32cubemx-initialization-bug

sorry (tho wish I'd known before trying to debug this)

Javier1
Principal
November 7, 2022

i have been there.

F

hit me up in https://www.linkedin.com/in/javiermuñoz/