NinjaFlight
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
serial_uart.h
Go to the documentation of this file.
1 /*
2  * This file is part of Ninjaflight.
3  *
4  * Ninjaflight is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * Ninjaflight is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Ninjaflight. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #pragma once
19 
20 #include "serial.h"
21 
22 // Since serial ports can be used for any function these buffer sizes should be equal
23 // The two largest things that need to be sent are: 1, MSP responses, 2, UBLOX SVINFO packet.
24 
25 // Size must be a power of two due to various optimizations which use 'and' instead of 'mod'
26 // Various serial routines return the buffer occupied size as uint8_t which would need to be extended in order to
27 // increase size further.
28 #define UART1_RX_BUFFER_SIZE 256
29 #define UART1_TX_BUFFER_SIZE 256
30 #define UART2_RX_BUFFER_SIZE 256
31 #define UART2_TX_BUFFER_SIZE 256
32 #define UART3_RX_BUFFER_SIZE 256
33 #define UART3_TX_BUFFER_SIZE 256
34 #define UART4_RX_BUFFER_SIZE 256
35 #define UART4_TX_BUFFER_SIZE 256
36 #define UART5_RX_BUFFER_SIZE 256
37 #define UART5_TX_BUFFER_SIZE 256
38 
39 // TODO: remove this once we remove dependency of pwm module on this uart crap
40 #ifdef STM32F10X
41  #ifndef UART1_GPIO
42  #define UART1_TX_PIN Pin_9 // PA9
43  #define UART1_RX_PIN Pin_10 // PA10
44  #define UART1_GPIO GPIOA
45  #define UART1_APB2_PERIPHERALS RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA
46  #define UART1_AHB_PERIPHERALS RCC_AHBPeriph_DMA1
47  #endif
48 
49  #ifndef UART2_GPIO
50  #define UART2_TX_PIN Pin_2 // PA2
51  #define UART2_RX_PIN Pin_3 // PA3
52  #define UART2_GPIO GPIOA
53  #define UART2_APB1_PERIPHERALS RCC_APB1Periph_USART2
54  #define UART2_APB2_PERIPHERALS RCC_APB2Periph_GPIOA
55  #define UART2_AHB_PERIPHERALS RCC_AHBPeriph_DMA1
56  #endif
57 
58  #ifndef UART3_GPIO
59  #define UART3_TX_PIN Pin_10 // PB10
60  #define UART3_RX_PIN Pin_11 // PB11
61  #define UART3_GPIO GPIOB
62  #define UART3_APB1_PERIPHERALS RCC_APB1Periph_USART3
63  #define UART3_APB2_PERIPHERALS RCC_APB2Periph_GPIOB
64  #endif
65 
66  // pins for UART4 are fixed by hardware
67  #define UART4_TX_PIN Pin_10 // PC10
68  #define UART4_RX_PIN Pin_11 // PC11
69  #define UART4_GPIO GPIOC
70  #define UART4_APB1_PERIPHERALS RCC_APB1Periph_UART4
71  #define UART4_APB2_PERIPHERALS RCC_APB2Periph_GPIOC
72 
73  // pins for UART5 are fixed by hardware and on GPIOC and D
74  #define UART5_TX_PIN Pin_12 // PC12
75  #define UART5_RX_PIN Pin_2 // PD2
76  #define UART5_GPIO_TX GPIOC
77  #define UART5_GPIO_RX GPIOD
78  #define UART5_APB1_PERIPHERALS RCC_APB1Periph_UART5
79  #define UART5_APB2_PERIPHERALS_TX RCC_APB2Periph_GPIOC
80  #define UART5_APB2_PERIPHERALS_RX RCC_APB2Periph_GPIOD
81 
82 #elif defined(STM32F303)
83 
84  #ifndef UART1_GPIO
85  #define UART1_TX_PIN GPIO_Pin_9 // PA9
86  #define UART1_RX_PIN GPIO_Pin_10 // PA10
87  #define UART1_GPIO GPIOA
88  #define UART1_GPIO_AF GPIO_AF_7
89  #define UART1_TX_PINSOURCE GPIO_PinSource9
90  #define UART1_RX_PINSOURCE GPIO_PinSource10
91  #endif
92 
93  #ifndef UART2_GPIO
94  #define UART2_TX_PIN GPIO_Pin_5 // PD5
95  #define UART2_RX_PIN GPIO_Pin_6 // PD6
96  #define UART2_GPIO GPIOD
97  #define UART2_GPIO_AF GPIO_AF_7
98  #define UART2_TX_PINSOURCE GPIO_PinSource5
99  #define UART2_RX_PINSOURCE GPIO_PinSource6
100  #endif
101 
102  #ifndef UART3_GPIO
103  #define UART3_TX_PIN GPIO_Pin_10 // PB10 (AF7)
104  #define UART3_RX_PIN GPIO_Pin_11 // PB11 (AF7)
105  #define UART3_GPIO_AF GPIO_AF_7
106  #define UART3_GPIO GPIOB
107  #define UART3_TX_PINSOURCE GPIO_PinSource10
108  #define UART3_RX_PINSOURCE GPIO_PinSource11
109  #endif
110 
111  // pins for UART4 are fixed by hardware
112  #define UART4_TX_PIN GPIO_Pin_10 // PC10
113  #define UART4_RX_PIN GPIO_Pin_11 // PC11
114  #define UART4_GPIO_AF GPIO_AF_5
115  #define UART4_GPIO GPIOC
116  #define UART4_APB1_PERIPHERALS RCC_APB1Periph_UART4
117  #define UART4_AHB_PERIPHERALS RCC_AHBPeriph_GPIOC
118  #define UART4_TX_PINSOURCE GPIO_PinSource10
119  #define UART4_RX_PINSOURCE GPIO_PinSource11
120 
121 
122  // pins for UART5 are fixed by hardware and on GPIOC and D
123  #define UART5_TX_PIN Pin_12 // PC12
124  #define UART5_RX_PIN Pin_2 // PD2
125  #define UART5_GPIO_AF GPIO_AF_5
126  #define UART5_GPIO_TX GPIOC
127  #define UART5_GPIO_RX GPIOD
128  #define UART5_APB1_PERIPHERALS RCC_APB1Periph_UART5
129  #define UART5_AHB_PERIPHERALS_TX RCC_AHBPeriph_GPIOC
130  #define UART5_AHB_PERIPHERALS_RX RCC_AHBPeriph_GPIOD
131  #define UART5_TX_PINSOURCE GPIO_PinSource12
132  #define UART5_RX_PINSOURCE GPIO_PinSource2
133 #endif
134 
135 // id starts from 1 (id 0 is invalid)!
136 serialPort_t *uartOpen(uint8_t id, serialReceiveCallbackPtr callback, uint32_t baudRate, portMode_t mode, portOptions_t options);
137 
138 void usartInitAllIOSignals(void);
139 
serialPort_t * uartOpen(uint8_t id, serialReceiveCallbackPtr callback, uint32_t baudRate, portMode_t mode, portOptions_t options)
Definition: serial_uart.c:249
uint8_t mode
Definition: gimbal.h:49
void usartInitAllIOSignals(void)
Definition: serial_uart_stm32f10x.c:66
portMode_t
Definition: serial.h:24
portOptions_t
Definition: serial.h:30
void(* serialReceiveCallbackPtr)(uint16_t data)
Definition: serial.h:41
Definition: serial.h:43