cancel
Showing results for 
Search instead for 
Did you mean: 

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

REdmo.1
Associate III

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

1 ACCEPTED SOLUTION

Accepted Solutions
REdmo.1
Associate III

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)

View solution in original post

2 REPLIES 2
REdmo.1
Associate III

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)

i have been there.

F

we dont need to firmware by ourselves, lets talk