2022-11-07 02:44 AM
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
Solved! Go to Solution.
2022-11-07 02:51 AM
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)
2022-11-07 02:51 AM
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)
2022-11-07 02:55 AM
i have been there.
F