Exemple #1
0
void uart3_init( void ) {

  /* init RCC */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);

  /* Enable USART3 interrupts */
  NVIC_InitTypeDef nvic;
  nvic.NVIC_IRQChannel = USART3_IRQn;
  nvic.NVIC_IRQChannelPreemptionPriority = 2;
  nvic.NVIC_IRQChannelSubPriority = 1;
  nvic.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&nvic);

  /* Init GPIOS */
  GPIO_PinRemapConfig(GPIO_PartialRemap_USART3, ENABLE);
  GPIO_InitTypeDef gpio;
  /* GPIOC: GPIO_Pin_10 USART3 Tx push-pull */
  gpio.GPIO_Pin   = UART3_TxPin;
  gpio.GPIO_Mode  = GPIO_Mode_AF_PP;
  gpio.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(UART3_TxPort, &gpio);
  /* GPIOC: GPIO_Pin_11 USART3 Rx pin as floating input */
  gpio.GPIO_Pin   = UART3_RxPin;
  gpio.GPIO_Mode  = GPIO_Mode_IN_FLOATING;
  GPIO_Init(UART3_RxPort, &gpio);

  /* Configure USART3 */
  USART_InitTypeDef usart;
  usart.USART_BaudRate            = UART3_BAUD;
  usart.USART_WordLength          = USART_WordLength_8b;
  usart.USART_StopBits            = USART_StopBits_1;
  usart.USART_Parity              = USART_Parity_No;
  usart.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  usart.USART_Mode                = USART_Mode_Rx | USART_Mode_Tx;
  USART_Init(USART3, &usart);
  /* Enable USART3 Receive interrupts */
  USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);

  pprz_usart_set_baudrate(USART3, UART3_BAUD);

  /* Enable the USART3 */
  USART_Cmd(USART3, ENABLE);

  // initialize the transmit data queue
  uart3_tx_extract_idx = 0;
  uart3_tx_insert_idx = 0;
  uart3_tx_running = FALSE;

  // initialize the receive data queuenn
  uart3_rx_extract_idx = 0;
  uart3_rx_insert_idx = 0;

}
Exemple #2
0
void uart_periph_set_baudrate(struct uart_periph* p, uint32_t baud) {

  /* Configure USART */
  USART_InitTypeDef usart;
  usart.USART_BaudRate            = baud;
  usart.USART_WordLength          = USART_WordLength_8b;
  usart.USART_StopBits            = USART_StopBits_1;
  usart.USART_Parity              = USART_Parity_No;
  usart.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  usart.USART_Mode                = USART_Mode_Rx | USART_Mode_Tx;
  USART_Init(p->reg_addr, &usart);
  /* Enable USART1 Receive interrupts */
  USART_ITConfig(p->reg_addr, USART_IT_RXNE, ENABLE);

  pprz_usart_set_baudrate(p->reg_addr, baud);

  /* Enable the USART */
  USART_Cmd(p->reg_addr, ENABLE);

}