Problem: The DMA receive functions for USART1 and USART3 are ineffective immediately after power-on; they only work normally after manually pressing the reset button.
Analysis: This is a typical "race condition" problem in the "DMA + idle interrupt" scheme. The reasons are as follows:
Solution: Before starting DMA reception and enabling the idle interrupt, forcibly clear the USART idle flag once. The code implementation is:
Problem Analysis: Even after adding the code to clear the flag, placing it in the Init function still yields unsatisfactory results. The deep-seated reason is:
main function, after MX_USART1_UART_Init finishes execution, the program continues to execute initialization for other peripherals (MX_I2C2_Init, MX_USART3_UART_Init, etc.).Solution:
HAL_UARTEx_ReceiveToIdle_DMA) from the MX_..._Init() functions, allowing them to be responsible only for pure hardware parameter configuration./* USER CODE BEGIN 2 */ section of the main function.Result: This ensures that all hardware peripherals are configured and the system has entered a stable state before starting application layer tasks like UART DMA reception. The program behavior becomes reliable and meets expectations.

Update: You need to add a HAL_Delay(500); delay function before the initialization of the two serial port peripherals; otherwise, the DMA reception for USART3 may also fail.
MX_..._Init functions do only one thing—configure hardware registers according to CubeMX settings, putting the hardware in a "standby" state.main function, wait until all hardware configurations are complete, then start them in the order of business logic (such as enabling DMA, starting timer PWM, etc.).Following the principle in point 2 can avoid over 90% of difficult-to-troubleshoot embedded system initialization problems and is the necessary path for code to become professional and robust.