targets/TARGET_STMBLUE/Periph_Driver/src/BlueNRG1_uart.c
void UART_Init(UART_InitType* UART_InitStruct)
{
  uint32_t divider;
  uint16_t ibrd, fbrd;

  /* Check the parameters */
  assert_param(IS_UART_BAUDRATE(UART_InitStruct->UART_BaudRate));  
  assert_param(IS_UART_WORD_LENGTH(UART_InitStruct->UART_WordLengthTransmit));
  assert_param(IS_UART_WORD_LENGTH(UART_InitStruct->UART_WordLengthReceive));
  assert_param(IS_UART_STOPBITS(UART_InitStruct->UART_StopBits));
  assert_param(IS_UART_PARITY(UART_InitStruct->UART_Parity));
  assert_param(IS_UART_MODE(UART_InitStruct->UART_Mode));
  assert_param(IS_UART_HW_FLOW_CONTROL(UART_InitStruct->UART_HardwareFlowControl));
  assert_param(IS_FUNCTIONAL_STATE(UART_InitStruct->UART_FifoEnable));
  
  /*---------------------------- UART BaudRate Configuration -----------------------*/
  
  if (UART->CR_b.OVSFACT == 0)
    divider = (UART_CLOCK<<7) / (UART_CLOCK_CYCLE16 * UART_InitStruct->UART_BaudRate);
  else
    divider = (UART_CLOCK<<7) / (UART_CLOCK_CYCLE8 * UART_InitStruct->UART_BaudRate);
  
  ibrd = divider >> 7;
  UART->IBRD = ibrd;
  fbrd = ((divider - (ibrd <<7) + 1) >> 1);
  if (fbrd > 0x3f) {
    ibrd++;
    fbrd = (fbrd - 0x3F) & 0x3F;
  }
  UART->FBRD = fbrd;
  
  /*---------------------------- UART Word Length Configuration -----------------------*/
  UART->LCRH_TX_b.WLEN_TX = UART_InitStruct->UART_WordLengthTransmit;
  UART->LCRH_RX_b.WLEN_RX = UART_InitStruct->UART_WordLengthReceive;
  
  /*---------------------------- UART Stop Bits Configuration -----------------------*/
  UART->LCRH_TX_b.STP2_TX = UART_InitStruct->UART_StopBits;
  UART->LCRH_RX_b.STP2_RX = UART_InitStruct->UART_StopBits;
  
  /*---------------------------- UART Parity Configuration -----------------------*/
  if(UART_InitStruct->UART_Parity == UART_Parity_No) {
    UART->LCRH_TX_b.PEN_TX = RESET;
    UART->LCRH_RX_b.PEN_RX = RESET;
  }
  else if(UART_InitStruct->UART_Parity == UART_Parity_Odd) {
    UART->LCRH_TX_b.PEN_TX = SET;
    UART->LCRH_TX_b.EPS_TX = RESET;
    UART->LCRH_RX_b.PEN_RX = SET;
    UART->LCRH_RX_b.EPS_RX = RESET;
  }
  else {
    UART->LCRH_TX_b.PEN_TX = SET;
    UART->LCRH_TX_b.EPS_TX = SET;    
    UART->LCRH_RX_b.PEN_RX = SET;
    UART->LCRH_RX_b.EPS_RX = SET;    
  }

  /*---------------------------- UART Mode Configuration -----------------------*/
  UART->CR_b.RXE = UART_InitStruct->UART_Mode&1;
  UART->CR_b.TXE = (UART_InitStruct->UART_Mode>>1)&1;

  /*---------------------------- UART Hardware flow control Configuration -----------------------*/
  UART->CR_b.RTSEN = UART_InitStruct->UART_HardwareFlowControl&1;
  UART->CR_b.CTSEN = (UART_InitStruct->UART_HardwareFlowControl>>1)&1;

  /*---------------------------- UART Fifo Configuration -----------------------*/
  UART->LCRH_TX_b.FEN_TX = (uint8_t)UART_InitStruct->UART_FifoEnable;
  UART->LCRH_RX_b.FEN_RX = (uint8_t)UART_InitStruct->UART_FifoEnable;

}
/**
  * @brief  Initializes the UART peripheral according to the specified
  *         parameters in the UART_InitStruct.
  * @param  UART_InitStruct: pointer to a @ref UART_InitType structure
  *         that contains the configuration information for the specified UART.
  * @retval None
  */
@brief  Initializes the UART peripheral according to the specified
parameters in the UART_InitStruct.
@param  UART_InitStruct: pointer to a @ref UART_InitType structure
that contains the configuration information for the specified UART.
@retval None
@brief Initializes the UART peripheral according to the specified parameters in the UART_InitStruct . @param UART_InitStruct : pointer to a @ref UART_InitType structure that contains the configuration information for the specified UART . @retval None
void UART_Init(UART_InitType* UART_InitStruct)
{
  uint32_t divider;
  uint16_t ibrd, fbrd;
  assert_param(IS_UART_BAUDRATE(UART_InitStruct->UART_BaudRate));  
  assert_param(IS_UART_WORD_LENGTH(UART_InitStruct->UART_WordLengthTransmit));
  assert_param(IS_UART_WORD_LENGTH(UART_InitStruct->UART_WordLengthReceive));
  assert_param(IS_UART_STOPBITS(UART_InitStruct->UART_StopBits));
  assert_param(IS_UART_PARITY(UART_InitStruct->UART_Parity));
  assert_param(IS_UART_MODE(UART_InitStruct->UART_Mode));
  assert_param(IS_UART_HW_FLOW_CONTROL(UART_InitStruct->UART_HardwareFlowControl));
  assert_param(IS_FUNCTIONAL_STATE(UART_InitStruct->UART_FifoEnable));
  if (UART->CR_b.OVSFACT == 0)
    divider = (UART_CLOCK<<7) / (UART_CLOCK_CYCLE16 * UART_InitStruct->UART_BaudRate);
  else
    divider = (UART_CLOCK<<7) / (UART_CLOCK_CYCLE8 * UART_InitStruct->UART_BaudRate);
  ibrd = divider >> 7;
  UART->IBRD = ibrd;
  fbrd = ((divider - (ibrd <<7) + 1) >> 1);
  if (fbrd > 0x3f) {
    ibrd++;
    fbrd = (fbrd - 0x3F) & 0x3F;
  }
  UART->FBRD = fbrd;
  UART->LCRH_TX_b.WLEN_TX = UART_InitStruct->UART_WordLengthTransmit;
  UART->LCRH_RX_b.WLEN_RX = UART_InitStruct->UART_WordLengthReceive;
  UART->LCRH_TX_b.STP2_TX = UART_InitStruct->UART_StopBits;
  UART->LCRH_RX_b.STP2_RX = UART_InitStruct->UART_StopBits;
  if(UART_InitStruct->UART_Parity == UART_Parity_No) {
    UART->LCRH_TX_b.PEN_TX = RESET;
    UART->LCRH_RX_b.PEN_RX = RESET;
  }
  else if(UART_InitStruct->UART_Parity == UART_Parity_Odd) {
    UART->LCRH_TX_b.PEN_TX = SET;
    UART->LCRH_TX_b.EPS_TX = RESET;
    UART->LCRH_RX_b.PEN_RX = SET;
    UART->LCRH_RX_b.EPS_RX = RESET;
  }
  else {
    UART->LCRH_TX_b.PEN_TX = SET;
    UART->LCRH_TX_b.EPS_TX = SET;    
    UART->LCRH_RX_b.PEN_RX = SET;
    UART->LCRH_RX_b.EPS_RX = SET;    
  }
  UART->CR_b.RXE = UART_InitStruct->UART_Mode&1;
  UART->CR_b.TXE = (UART_InitStruct->UART_Mode>>1)&1;
  UART->CR_b.RTSEN = UART_InitStruct->UART_HardwareFlowControl&1;
  UART->CR_b.CTSEN = (UART_InitStruct->UART_HardwareFlowControl>>1)&1;
  UART->LCRH_TX_b.FEN_TX = (uint8_t)UART_InitStruct->UART_FifoEnable;
  UART->LCRH_RX_b.FEN_RX = (uint8_t)UART_InitStruct->UART_FifoEnable;
}
void UART_Init ( UART_InitType * UART_InitStruct ) { uint32_t divider ; uint16_t ibrd , fbrd ; assert_param ( IS_UART_BAUDRATE ( UART_InitStruct -> UART_BaudRate ) ) ; assert_param ( IS_UART_WORD_LENGTH ( UART_InitStruct -> UART_WordLengthTransmit ) ) ; assert_param ( IS_UART_WORD_LENGTH ( UART_InitStruct -> UART_WordLengthReceive ) ) ; assert_param ( IS_UART_STOPBITS ( UART_InitStruct -> UART_StopBits ) ) ; assert_param ( IS_UART_PARITY ( UART_InitStruct -> UART_Parity ) ) ; assert_param ( IS_UART_MODE ( UART_InitStruct -> UART_Mode ) ) ; assert_param ( IS_UART_HW_FLOW_CONTROL ( UART_InitStruct -> UART_HardwareFlowControl ) ) ; assert_param ( IS_FUNCTIONAL_STATE ( UART_InitStruct -> UART_FifoEnable ) ) ; if ( UART -> CR_b . OVSFACT == 0 ) divider = ( UART_CLOCK << 7 ) / ( UART_CLOCK_CYCLE16 * UART_InitStruct -> UART_BaudRate ) ; else divider = ( UART_CLOCK << 7 ) / ( UART_CLOCK_CYCLE8 * UART_InitStruct -> UART_BaudRate ) ; ibrd = divider >> 7 ; UART -> IBRD = ibrd ; fbrd = ( ( divider - ( ibrd << 7 ) + 1 ) >> 1 ) ; if ( fbrd > 0x3f ) { ibrd ++ ; fbrd = ( fbrd - 0x3F ) & 0x3F ; } UART -> FBRD = fbrd ; UART -> LCRH_TX_b . WLEN_TX = UART_InitStruct -> UART_WordLengthTransmit ; UART -> LCRH_RX_b . WLEN_RX = UART_InitStruct -> UART_WordLengthReceive ; UART -> LCRH_TX_b . STP2_TX = UART_InitStruct -> UART_StopBits ; UART -> LCRH_RX_b . STP2_RX = UART_InitStruct -> UART_StopBits ; if ( UART_InitStruct -> UART_Parity == UART_Parity_No ) { UART -> LCRH_TX_b . PEN_TX = RESET ; UART -> LCRH_RX_b . PEN_RX = RESET ; } else if ( UART_InitStruct -> UART_Parity == UART_Parity_Odd ) { UART -> LCRH_TX_b . PEN_TX = SET ; UART -> LCRH_TX_b . EPS_TX = RESET ; UART -> LCRH_RX_b . PEN_RX = SET ; UART -> LCRH_RX_b . EPS_RX = RESET ; } else { UART -> LCRH_TX_b . PEN_TX = SET ; UART -> LCRH_TX_b . EPS_TX = SET ; UART -> LCRH_RX_b . PEN_RX = SET ; UART -> LCRH_RX_b . EPS_RX = SET ; } UART -> CR_b . RXE = UART_InitStruct -> UART_Mode & 1 ; UART -> CR_b . TXE = ( UART_InitStruct -> UART_Mode >> 1 ) & 1 ; UART -> CR_b . RTSEN = UART_InitStruct -> UART_HardwareFlowControl & 1 ; UART -> CR_b . CTSEN = ( UART_InitStruct -> UART_HardwareFlowControl >> 1 ) & 1 ; UART -> LCRH_TX_b . FEN_TX = ( uint8_t ) UART_InitStruct -> UART_FifoEnable ; UART -> LCRH_RX_b . FEN_RX = ( uint8_t ) UART_InitStruct -> UART_FifoEnable ; }
@brief  Initializes the UART peripheral according to the specified
         parameters in the UART_InitStruct.
@brief Initializes the UART peripheral according to the specified parameters in the UART_InitStruct .
/* Check the parameters */ /*---------------------------- UART BaudRate Configuration -----------------------*/ /*---------------------------- UART Word Length Configuration -----------------------*/ /*---------------------------- UART Stop Bits Configuration -----------------------*/ /*---------------------------- UART Parity Configuration -----------------------*/ /*---------------------------- UART Mode Configuration -----------------------*/ /*---------------------------- UART Hardware flow control Configuration -----------------------*/ /*---------------------------- UART Fifo Configuration -----------------------*/