title: HAL_UART_Transmit_IT: only a few bytes are sent
body: <p>i've got a problem on my STM32F407 with FreeRTOS.
  So Far most of the messages to a xbee module are sent. Only Sometimes (after 5 to 60 minutes) the TX process will be interrupted. </p>
  
  <p>In the debug session i can see, that TXEIE ist not set anymore after the 2 bytes (of ~40). Also the TxXferCount of the UART_HandleTypeDef is 42 (TxXferSize: 44).
  The flag TXE in SR-Register ist set but the TXEIE in CR1-Register not.</p>
  
  <p>The ISR was active for 2 times to store them into data/shift registers. This i can see on logic analyzer.
  But i can't figure out the source of the writing task/isr. </p>
  
  <p>The Xbee module get messages and sends response messages.
  Thanks for any Response!</p>
  
  <p>The init:</p>
  
  <pre><code>GPIO_InitTypeDef GPIO_InitStruct;
  
  __GPIOA_CLK_ENABLE();
  __GPIOD_CLK_ENABLE();
  __GPIOF_CLK_ENABLE();
  
  
  /* RX-TX PIN */
  GPIO_InitStruct.Pin = XBEE1_TX_PIN | XBEE1_RX_PIN;
  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
  GPIO_InitStruct.Alternate = GPIO_AF7_USART2;
  HAL_GPIO_Init(XBEE1_TX_PORT, &amp;GPIO_InitStruct);
  
  /* Power*/
  GPIO_InitStruct.Pin =  XBEE1_PWR_PIN;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_PULLUP;
  GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
  HAL_GPIO_Init(XBEE1_PWR_PORT, &amp;GPIO_InitStruct);
  HAL_GPIO_WritePin(XBEE1_PWR_PORT, XBEE1_PWR_PIN, GPIO_PIN_SET);
  
  /* Reset PIN */
  GPIO_InitStruct.Pin = XBEE1_RESET_PIN;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_PULLUP;
  GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
  HAL_GPIO_Init(XBEE1_RESET_PORT, &amp;GPIO_InitStruct);
  
  /* SLEEP_RQ PIN */
  GPIO_InitStruct.Pin = XBEE1_SLEEP_RQ_PIN;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_PULLUP;
  GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
  HAL_GPIO_Init(XBEE1_SLEEP_RQ_PORT, &amp;GPIO_InitStruct);
  
  
  
  __USART2_CLK_ENABLE();
  
  uart.Instance = USART2;
  uart.Init.BaudRate = baud;
  uart.Init.WordLength = UART_WORDLENGTH_8B;
  uart.Init.StopBits = UART_STOPBITS_1;
  uart.Init.Parity = UART_PARITY_NONE;
  uart.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  uart.Init.Mode = UART_MODE_TX_RX;
  
  if (HAL_UART_Init(&amp;uart) != HAL_OK) {
      Error_Handler(XBEE1_ERROR);
  }
  
  //clear pending IRQs
  __HAL_UART_CLEAR_FLAG(&amp;uart, UART_FLAG_RXNE);
  __HAL_UART_CLEAR_FLAG(&amp;uart, USART_FLAG_TC);
  __HAL_UART_CLEAR_FLAG(&amp;uart, USART_FLAG_ORE);
  __HAL_UART_CLEAR_FLAG(&amp;uart, USART_FLAG_PE);
  __HAL_UART_CLEAR_FLAG(&amp;uart, USART_FLAG_FE);
  __HAL_UART_CLEAR_FLAG(&amp;uart, USART_FLAG_NE);
  __HAL_UART_CLEAR_FLAG(&amp;uart, USART_FLAG_TXE);
  
  /* NVIC */
  HAL_NVIC_SetPriority(USART2_IRQn, 6, 0);
  HAL_NVIC_EnableIRQ(USART2_IRQn);
  </code></pre>
  
  <p>The Transmit</p>
  
  <pre><code>HAL_StatusTypeDef UART_Xbee1::send( uint8_t* pdata, size_t sz ) {
      return HAL_UART_Transmit_IT(&amp;uart, pdata, sz);
  }
  </code></pre>
  
  <p>ISR</p>
  
  <pre><code>extern "C" void USART2_IRQHandler(void){
      testpin1.on();
      UART_HandleTypeDef* uart_c = &amp;(Argos::xbee1-&gt;uart);
      uint32_t tmp1 = 0;
      uint32_t tmp2 = 0;
      tmp1 = __HAL_UART_GET_FLAG(uart_c, UART_FLAG_RXNE);
      tmp2 = __HAL_UART_GET_IT_SOURCE(uart_c, UART_IT_RXNE);
      if((tmp1 != RESET) &amp;&amp; (tmp2 != RESET)){
          uint8_t in = (uint8_t)(uart_c-&gt;Instance-&gt;DR &amp; (uint8_t)0x00FF);
          *uart_c-&gt;pRxBuffPtr++ = in;
  
          //overwrite expected bytes, when packet size is known
          if(xbee1-&gt;inApiRecMode){
              if( (uart_c-&gt;RxXferSize-uart_c-&gt;RxXferCount) == 1 ){
                  xbee1-&gt;apiSize = 0;
                  xbee1-&gt;apiSize = in &lt;&lt; 8;
              }else if( (uart_c-&gt;RxXferSize-uart_c-&gt;RxXferCount) == 2 ){
                  xbee1-&gt;apiSize |= in;
                  uart_c-&gt;RxXferCount = xbee1-&gt;apiSize + 2;
              }
          }
  
          if( ((uart_c-&gt;RxXferCount)-1) == 0){
              (uart_c-&gt;RxXferCount)--;
                __HAL_UART_DISABLE_IT(uart_c, UART_IT_RXNE);
  
                /* Check if a transmit process is ongoing or not */
                if(uart_c-&gt;State == HAL_UART_STATE_BUSY_TX_RX){
                    uart_c-&gt;State   = HAL_UART_STATE_BUSY_TX;
                }else{
                  /* Disable the UART Parity Error Interrupt */
                  __HAL_UART_DISABLE_IT(uart_c, UART_IT_PE);
  
                  /* Disable the UART Error Interrupt: (Frame error, noise error, overrun error) */
                  __HAL_UART_DISABLE_IT(uart_c, UART_IT_ERR);
  
                  uart_c-&gt;State = HAL_UART_STATE_READY;
                }
  
                Message* msg = &amp;(xbee1-&gt;msg_callBack);
                msg-&gt;code = (uint8_t) XbeeContext::MessageType::RECEIVE_EVENT;
                msg-&gt;value = 0;
                xbee1-&gt;rcvCallback-&gt;sendMsg(msg);
              }else if( (uart_c-&gt;RxXferCount) == 0){
                  Error_Handler(XBEE1_ERROR);
              }else{
                  (uart_c-&gt;RxXferCount)--;
              }
      }else{
  
          //other cases
          HAL_UART_IRQHandler( uart_c );
      }
      testpin1.off();
  }
  </code></pre>