title: UART with STM32F407 (F4Discovery)
body: <p>I am having issues trying to use the UART (USART1) on my F4Discovery board (based on an STM32F407). I am pretty new to STM32 and Keil (the IDE I am using). Here's my code:</p>
  
  <pre><code>#include "stm32f4_discovery.h"
  #include "stm32f4xx_usart.h"
  #include "stm32f4xx.h"
  
  void usartSetup(void);
  void USART_PutChar(uint8_t ch);
  
  int main (void) {
      usartSetup();
  
      USART_PutChar(0);   //I realise this won't send a 0
      USART_PutChar(8);   //I realise this won't send an 8
      USART_PutChar(255);   //I realise this won't send a 255
  
      while (1) {
          //loop forever
      }
  }
  
  void usartSetup (void) {
      USART_InitTypeDef USART_InitStructure;
      //USART_StructInit(&amp;USART_InitStructure);
      USART_InitStructure.USART_BaudRate = 9600;
      USART_InitStructure.USART_WordLength = USART_WordLength_8b;
      USART_InitStructure.USART_StopBits = USART_StopBits_1;
      USART_InitStructure.USART_Parity = USART_Parity_No;
      USART_InitStructure.USART_HardwareFlowControl =  USART_HardwareFlowControl_None;
      USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
      USART_Init(USART1, &amp;USART_InitStructure);
      USART_Cmd(USART1, ENABLE);
  }
  
  void USART_PutChar(uint8_t ch) {
      USART_SendData(USART1, (uint16_t) 0x49);
      while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
      USART_SendData(USART1, (uint16_t) 0x49);
  }
  </code></pre>
  
  <p>I'd be very grateful if someone could help. It never sends the 0x49 out of the UART1 TX (have checked pin PA9 and PB6) and then gets endlessly stuck on the while(USART_GetFlagStatus...). I am observing using the Keil debugger and see it get stuck in the while.</p>
  
  <p>I am including the stm32f4xx_usart.c driver into the project.</p>
  
  <p>Thanks!</p>