Paparazzi UAS  v5.15_devel-208-g53ac83c
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
crazyflie.h
Go to the documentation of this file.
1 #ifndef CONFIG_CRAZYFLIE_2_1_H
2 #define CONFIG_CRAZYFLIE_2_1_H
3 
4 #define BOARD_CRAZYFLIE
5 
10 
15 /*
16  * AHB_CLK
17  */
18 #define AHB_CLK STM32_HCLK
19 
20 /*
21  * LEDs
22  */
23 #ifndef USE_LED_1
24 #define USE_LED_1 1
25 #endif
26 #define LED_1_GPIO LED_RED_R_PORT
27 #define LED_1_GPIO_PIN LED_RED_R
28 #define LED_1_GPIO_ON gpio_clear
29 #define LED_1_GPIO_OFF gpio_set
30 
31 #ifndef USE_LED_2
32 #define USE_LED_2 1
33 #endif
34 #define LED_2_GPIO LED_RED_L_PORT
35 #define LED_2_GPIO_PIN LED_RED_L
36 #define LED_2_GPIO_ON gpio_clear
37 #define LED_2_GPIO_OFF gpio_set
38 
39 #ifndef USE_LED_3
40 #define USE_LED_3 1
41 #endif
42 #define LED_3_GPIO LED_GREEN_R_PORT
43 #define LED_3_GPIO_PIN LED_GREEN_R
44 #define LED_3_GPIO_ON gpio_clear
45 #define LED_3_GPIO_OFF gpio_set
46 
47 #ifndef USE_LED_4
48 #define USE_LED_4 1
49 #endif
50 #define LED_4_GPIO LED_GREEN_L_PORT
51 #define LED_4_GPIO_PIN LED_GREEN_L
52 #define LED_4_GPIO_ON gpio_clear
53 #define LED_4_GPIO_OFF gpio_set
54 
55 #ifndef USE_LED_5
56 #define USE_LED_5 1
57 #endif
58 #define LED_5_GPIO LED_BLUE_L_PORT
59 #define LED_5_GPIO_PIN LED_BLUE_L
60 #define LED_5_GPIO_ON gpio_set
61 #define LED_5_GPIO_OFF gpio_clear
62 
63 /*
64  * ADCs
65  */
66 // TODO for AUX
67 // No VBAT monitoring ?
68 
69 /*
70  * PWM defines
71  */
72 
73 // SRVa connectors, activated in PWM mode by default
74 
75 #ifndef USE_PWM1
76 #define USE_PWM1 1
77 #endif
78 #if USE_PWM1
79 #define PWM_SERVO_1 1
80 #define PWM_SERVO_1_GPIO MOTOR1_PORT
81 #define PWM_SERVO_1_PIN MOTOR1
82 #define PWM_SERVO_1_AF AF_MOTOR1
83 #define PWM_SERVO_1_DRIVER PWMD2
84 #define PWM_SERVO_1_CHANNEL 1
85 #define PWM_SERVO_1_ACTIVE PWM_OUTPUT_ACTIVE_HIGH
86 #else
87 #define PWM_SERVO_1_ACTIVE PWM_OUTPUT_DISABLED
88 #endif
89 
90 #ifndef USE_PWM2
91 #define USE_PWM2 1
92 #endif
93 #if USE_PWM2
94 #define PWM_SERVO_2 2
95 #define PWM_SERVO_2_GPIO MOTOR2_PORT
96 #define PWM_SERVO_2_PIN MOTOR2
97 #define PWM_SERVO_2_AF AF_MOTOR2
98 #define PWM_SERVO_2_DRIVER PWMD2
99 #define PWM_SERVO_2_CHANNEL 3
100 #define PWM_SERVO_2_ACTIVE PWM_OUTPUT_ACTIVE_HIGH
101 #else
102 #define PWM_SERVO_2_ACTIVE PWM_OUTPUT_DISABLED
103 #endif
104 
105 #ifndef USE_PWM3
106 #define USE_PWM3 1
107 #endif
108 #if USE_PWM3
109 #define PWM_SERVO_3 3
110 #define PWM_SERVO_3_GPIO MOTOR3_PORT
111 #define PWM_SERVO_3_PIN MOTOR3
112 #define PWM_SERVO_3_AF AF_MOTOR3
113 #define PWM_SERVO_3_DRIVER PWMD2
114 #define PWM_SERVO_3_CHANNEL 0
115 #define PWM_SERVO_3_ACTIVE PWM_OUTPUT_ACTIVE_HIGH
116 #else
117 #define PWM_SERVO_3_ACTIVE PWM_OUTPUT_DISABLED
118 #endif
119 
120 #ifndef USE_PWM4
121 #define USE_PWM4 1
122 #endif
123 #if USE_PWM4
124 #define PWM_SERVO_4 4
125 #define PWM_SERVO_4_GPIO MOTOR4_PORT
126 #define PWM_SERVO_4_PIN MOTOR4
127 #define PWM_SERVO_4_AF AF_MOTOR4
128 #define PWM_SERVO_4_DRIVER PWMD4
129 #define PWM_SERVO_4_CHANNEL 3
130 #define PWM_SERVO_4_ACTIVE PWM_OUTPUT_ACTIVE_HIGH
131 #else
132 #define PWM_SERVO_4_ACTIVE PWM_OUTPUT_DISABLED
133 #endif
134 
135 // servo index starting at 1 + regular servos + aux servos
136 // so NB = 1+4
137 #define ACTUATORS_PWM_NB 5
138 
139 
140 // PWM control of brushed motors
141 // Freq = 84 MHz (corresponding to prescaler of 0)
142 // Period = 256 (corresponding to 8bit resolution for command at ~328 kHz))
143 // as indicated in Crazyflie source code, 328 kHz offers better natural filtering
144 // than 128 kHz
145 // It is also needed to redefined PWM_CMD_TO_US to get the proper converstion
146 // from command to clock pulses number
147 
148 #define PWM_CMD_TO_US(_t) (_t)
149 
150 #ifdef STM32_PWM_USE_TIM2
151 #define PWM_CONF_TIM2 STM32_PWM_USE_TIM2
152 #else
153 #define PWM_CONF_TIM2 1
154 #endif
155 #define PWM_CONF2_DEF { \
156  84000000, \
157  256, \
158  NULL, \
159  { \
160  { PWM_SERVO_3_ACTIVE, NULL }, \
161  { PWM_SERVO_1_ACTIVE, NULL }, \
162  { PWM_OUTPUT_DISABLED, NULL }, \
163  { PWM_SERVO_2_ACTIVE, NULL }, \
164  }, \
165  0, \
166  0 \
167 }
168 
169 #ifdef STM32_PWM_USE_TIM4
170 #define PWM_CONF_TIM4 STM32_PWM_USE_TIM4
171 #else
172 #define PWM_CONF_TIM4 1
173 #endif
174 #define PWM_CONF4_DEF { \
175  84000000, \
176  256, \
177  NULL, \
178  { \
179  { PWM_OUTPUT_DISABLED, NULL }, \
180  { PWM_OUTPUT_DISABLED, NULL }, \
181  { PWM_OUTPUT_DISABLED, NULL }, \
182  { PWM_SERVO_4_ACTIVE, NULL }, \
183  }, \
184  0, \
185  0 \
186 }
187 
191 #define UART2_GPIO_PORT_TX E_TX2_PORT
192 #define UART2_GPIO_TX E_TX2
193 #define UART2_GPIO_PORT_RX E_RX2_PORT
194 #define UART2_GPIO_RX E_RX2
195 #define UART2_GPIO_AF AF_E_RX2
196 #ifndef UART2_HW_FLOW_CONTROL
197 #define UART2_HW_FLOW_CONTROL FALSE
198 #endif
199 
203 #define UART3_GPIO_PORT_TX E_TX1_PORT
204 #define UART3_GPIO_TX E_TX1
205 #define UART3_GPIO_PORT_RX E_RX1_PORT
206 #define UART3_GPIO_RX E_RX1
207 #define UART3_GPIO_AF AF_E_RX1
208 
212 #define UART6_GPIO_PORT_TX NRF_TX_PORT
213 #define UART6_GPIO_TX NRF_TX
214 #define UART6_GPIO_PORT_RX NRF_RX_PORT
215 #define UART6_GPIO_RX NRF_RX
216 #define UART6_GPIO_AF AF_NRF_RX
217 #define UART6_GPIO_PORT_CTS NRF_FLOW_CTRL_PORT
218 #define UART6_GPIO_CTS NRF_FLOW_CTRL
219 
224 // Digital noise filter: 0 disabled, [0x1 - 0xF] enable up to n t_I2CCLK
225 #define STM32_CR1_DNF(n) ((n & 0x0f) << 8)
226 // Timing register
227 #define I2C_FAST_400KHZ_DNF0_100NS_PCLK54MHZ_TIMINGR (STM32_TIMINGR_PRESC(0U) | \
228  STM32_TIMINGR_SCLDEL(10U) | STM32_TIMINGR_SDADEL(0U) | \
229  STM32_TIMINGR_SCLH(34U) | STM32_TIMINGR_SCLL(86U))
230 #define I2C_STD_100KHZ_DNF0_100NS_PCLK54MHZ_TIMINGR (STM32_TIMINGR_PRESC(1U) | \
231  STM32_TIMINGR_SCLDEL(9U) | STM32_TIMINGR_SDADEL(0U) | \
232  STM32_TIMINGR_SCLH(105U) | STM32_TIMINGR_SCLL(153U))
233 
234 
235 // Internal I2C (IMU, baro)
236 
237 #ifndef I2C3_CLOCK_SPEED
238 #define I2C3_CLOCK_SPEED 400000
239 #endif
240 #if I2C3_CLOCK_SPEED == 400000
241 #define I2C3_DUTY_CYCLE FAST_DUTY_CYCLE_2
242 #elif I2C3_CLOCK_SPEED == 100000
243 #define I2C3_DUTY_CYCLE STD_DUTY_CYCLE
244 #else
245 #error "Invalid I2C3 clock speed"
246 #endif
247 #define I2C3_CFG_DEF { \
248  OPMODE_I2C, \
249  I2C3_CLOCK_SPEED, \
250  I2C3_DUTY_CYCLE, \
251  }
252 
253 // External I2C
254 
255 #ifndef I2C1_CLOCK_SPEED
256 #define I2C1_CLOCK_SPEED 400000
257 #endif
258 #if I2C1_CLOCK_SPEED == 400000
259 #define I2C1_DUTY_CYCLE FAST_DUTY_CYCLE_2
260 #elif I2C1_CLOCK_SPEED == 100000
261 #define I2C1_DUTY_CYCLE STD_DUTY_CYCLE
262 #else
263 #error "Invalid I2C1 clock speed"
264 #endif
265 #define I2C1_CFG_DEF { \
266  OPMODE_I2C, \
267  I2C1_CLOCK_SPEED, \
268  I2C1_DUTY_CYCLE, \
269  }
270 
271 /*
272 #ifndef I2C3_CLOCK_SPEED
273 #define I2C3_CLOCK_SPEED 400000
274 #endif
275 
276 #if I2C3_CLOCK_SPEED == 400000
277 #define I2C3_CFG_DEF { \
278  .timingr = I2C_FAST_400KHZ_DNF0_100NS_PCLK54MHZ_TIMINGR, \
279  .cr1 = STM32_CR1_DNF(0), \
280  .cr2 = 0 \
281 }
282 #elif I2C3_CLOCK_SPEED == 100000
283 #define I2C3_CFG_DEF { \
284  .timingr = I2C_STD_100KHZ_DNF0_100NS_PCLK54MHZ_TIMINGR, \
285  .cr1 = STM32_CR1_DNF(0), \
286  .cr2 = 0 \
287 }
288 #else
289 #error "Unknown I2C3 clock speed"
290 #endif
291 
292 // External I2C
293 
294 #ifndef I2C1_CLOCK_SPEED
295 #define I2C1_CLOCK_SPEED 400000
296 #endif
297 
298 #if I2C1_CLOCK_SPEED == 400000
299 #define I2C1_CFG_DEF { \
300  .timingr = I2C_FAST_400KHZ_DNF0_100NS_PCLK54MHZ_TIMINGR, \
301  .cr1 = STM32_CR1_DNF(0), \
302  .cr2 = 0 \
303 }
304 #elif I2C1_CLOCK_SPEED == 100000
305 #define I2C1_CFG_DEF { \
306  .timingr = I2C_STD_100KHZ_DNF0_100NS_PCLK54MHZ_TIMINGR, \
307  .cr1 = STM32_CR1_DNF(0), \
308  .cr2 = 0 \
309 }
310 #else
311 #error "Unknown I2C2 clock speed"
312 #endif
313 */
314 
319 // External SPI
320 #define SPI1_GPIO_AF AF_E_SCK
321 #define SPI1_GPIO_PORT_MISO E_MISO_PORT
322 #define SPI1_GPIO_MISO E_MISO
323 #define SPI1_GPIO_PORT_MOSI E_MOSI_PORT
324 #define SPI1_GPIO_MOSI E_MOSI
325 #define SPI1_GPIO_PORT_SCK E_SCK_PORT
326 #define SPI1_GPIO_SCK E_SCK
327 
328 #define SPI_SELECT_SLAVE0_PORT E_CS0_PORT
329 #define SPI_SELECT_SLAVE0_PIN E_CS0
330 #define SPI_SELECT_SLAVE1_PORT E_CS1_PORT
331 #define SPI_SELECT_SLAVE1_PIN E_CS1
332 #define SPI_SELECT_SLAVE2_PORT E_CS2_PORT
333 #define SPI_SELECT_SLAVE2_PIN E_CS2
334 #define SPI_SELECT_SLAVE3_PORT E_CS3_PORT
335 #define SPI_SELECT_SLAVE3_PIN E_CS3
336 
343 #ifndef USE_BARO_BOARD
344 #define USE_BARO_BOARD 0
345 #endif
346 
347 /*
348  * Actuators for fixedwing
349  */
350  /* Default actuators driver */
351 #define DEFAULT_ACTUATORS "subsystems/actuators/actuators_pwm.h"
352 #define ActuatorDefaultSet(_x,_y) ActuatorPwmSet(_x,_y)
353 #define ActuatorsDefaultInit() ActuatorsPwmInit()
354 #define ActuatorsDefaultCommit() ActuatorsPwmCommit()
355 
356 #endif /* CONFIG_TAWAKI_1_00_H */
357