drv_uart.h
Go to the documentation of this file.
1 /*
2  drv_uart.h : UART support for STM32F103CB
3 
4  Adapted from https://github.com/multiwii/baseflight/blob/master/src/drv_uart.h
5 
6  This file is part of BreezySTM32.
7 
8  BreezySTM32 is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  BreezySTM32 is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with BreezySTM32. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #pragma once
23 
24 #define UART_BUFFER_SIZE 64
25 
26 #define UART1_RX_BUFFER_SIZE 256
27 #define UART1_TX_BUFFER_SIZE 256
28 #define UART2_RX_BUFFER_SIZE 128
29 #define UART2_TX_BUFFER_SIZE 64
30 #define UART3_RX_BUFFER_SIZE 256
31 #define UART3_TX_BUFFER_SIZE 256
32 #define MAX_SERIAL_PORTS 3
33 
34 // FIXME this is a uart_t really. Move the generic properties into a separate structure (serialPort_t) and update the code to use it
35 typedef struct {
37 
38  // FIXME these are uart specific and do not belong in here
41 
42  uint32_t rxDMAIrq;
43  uint32_t txDMAIrq;
44 
45  uint32_t rxDMAPos;
46  bool txDMAEmpty;
47 
49 } uartPort_t;
50 
51 extern const struct serialPortVTable uartVTable[];
52 
53 serialPort_t *uartOpen(USART_TypeDef *USARTx, serialReceiveCallbackPtr callback, uint32_t baudRate, portMode_t mode);
54 
55 // serialPort API
56 void uartWrite(serialPort_t *instance, uint8_t ch);
57 uint8_t uartTotalBytesWaiting(serialPort_t *instance);
58 uint8_t uartRead(serialPort_t *instance);
59 void uartSetBaudRate(serialPort_t *s, uint32_t baudRate);
portMode_t
Definition: drv_serial.h:26
Universal Synchronous Asynchronous Receiver Transmitter.
Definition: stm32f4xx.h:1710
bool isUartTransmitBufferEmpty(serialPort_t *s)
Definition: drv_uart.c:220
void uartWrite(serialPort_t *instance, uint8_t ch)
Definition: drv_uart.c:246
uint8_t uartTotalBytesWaiting(serialPort_t *instance)
Definition: drv_uart.c:209
uint32_t rxDMAIrq
Definition: drv_uart.h:42
USART_TypeDef * USARTx
Definition: drv_uart.h:48
uint32_t txDMAIrq
Definition: drv_uart.h:43
serialPort_t * uartOpen(USART_TypeDef *USARTx, serialReceiveCallbackPtr callback, uint32_t baudRate, portMode_t mode)
Definition: drv_uart.c:80
bool txDMAEmpty
Definition: drv_uart.h:46
void uartSetBaudRate(serialPort_t *s, uint32_t baudRate)
Definition: drv_uart.c:167
void(* serialReceiveCallbackPtr)(uint16_t data)
Definition: drv_serial.h:24
uint8_t uartRead(serialPort_t *instance)
Definition: drv_uart.c:229
DMA_Channel_TypeDef * rxDMAChannel
Definition: drv_uart.h:39
const struct serialPortVTable uartVTable[]
Definition: drv_uart.c:260
uint32_t rxDMAPos
Definition: drv_uart.h:45
serialPort_t port
Definition: drv_uart.h:36
DMA Controller.
Definition: stm32f10x.h:798
DMA_Channel_TypeDef * txDMAChannel
Definition: drv_uart.h:40


rosflight_firmware
Author(s): Daniel Koch , James Jackson
autogenerated on Thu Apr 15 2021 05:07:46