title: STM32 UART in DMA mode stops receiving after receiving from a host with wrong baud rate
body: <p><strong>The scenario:</strong> I have a STM32 MCU, which uses an UART in DMA Mode with Idle Interrupt for RS485 data transfer. The baud rate of the UART is set in CubeMX, in this case to 115200. My Code works fine, when the Host uses the correct baud rate, it is also &quot;long time&quot; stable, no issues or worries.</p>
  <p>BUT: when I set the wrong baud rate at the host, e.g. 56700 instead of 115200, the UART stops receiving data, even if I later set the baud rate at the host to the same baud rate the Microcontroller uses, it won't work. The only way to solve this issue so far is: reset the MCU and connect again with the correct baud rate.</p>
  <p>To give you some (Pseudo-)Code:</p>
  <pre><code>uint8_t UART_Buf[128];
  HAL_UART_Receive_DMA(&amp;huart2, UART_Buf, 128);
  __HAL_UART_ENABLE_IT(&amp;huart2, UART_IT_IDLE);
  </code></pre>
  <p>Or in Plain Words: there is a UART Buffer for DMA (UART_Buf[128]) and the UART is started with HAL_UART_Receive_DMA(...), DMA Rx is set to circular mode in CubeMX, also the Idle-Interrupt is activated, using the HAL Macro: __HAL_UART_ENABLE_IT(...); This code works fine so far.</p>
  <p>Works fine means:
  when I transmit data from my PC to the Micro, the (one) Idle Interrupt is triggered (correctly) by the MCU. In the ISR I set a flag, to start the data parsing afterwards. I receive exactly the number of bytes I have sent, and all is fine.</p>
  <p>BUT: when I make the wrong setting in my Terminal Program and instead of the (correct) baud rate of 115200, the baud rate select menu is set to e.g. 57600, the trouble begins:</p>
  <p>The idle interrupt will still trigger after each transmission.
  But it triggers 2-4 times in a quick &quot;burst&quot; (depending on the baud rate) and the number of bytes received is 0. I'd expect at least some <em>bs</em> data, but there is exactly 0 data in the buffer - which I can check with the debugger. There is obviously received nothing. When I change the baud rate in my terminal program and restart it, there is still nothing received on the MCU.</p>
  <p>I could live with 0 received bytes, if the baud rate of the host is incorrect, but it's pretty uncool that one incoming transmission of a host with the wrong baud rate disables the UART until a hardware reset is done.</p>
  <p><strong>My attempts to resolve this were so far:</strong>
  count the &quot;Idle Interrupt Bursts&quot; in combination with 0 received bytes to trigger a &quot;self reset&quot; routine, that stops the UART and restarts it, using the MX_USART2_UART_Init(); Routine. With zero effect. I can see the Idle Interrupt is still triggered correctly, but the buffer remains empty and no data is transferred into the buffer. The UART remains in a non-receiving state.</p>
  <p><strong>The Question</strong>
  Has anyone out there experienced similar issues, and if yes: how did you solve that?</p>
  <p>Additional Info: this happens on a STM32F030 as well as on a STM32G03x</p>