MAV'RIC
|
00001 /******************************************************************************* 00002 * Copyright (c) 2009-2016, MAV'RIC Development Team 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions are met: 00007 * 00008 * 1. Redistributions of source code must retain the above copyright notice, 00009 * this list of conditions and the following disclaimer. 00010 * 00011 * 2. Redistributions in binary form must reproduce the above copyright notice, 00012 * this list of conditions and the following disclaimer in the documentation 00013 * and/or other materials provided with the distribution. 00014 * 00015 * 3. Neither the name of the copyright holder nor the names of its contributors 00016 * may be used to endorse or promote products derived from this software without 00017 * specific prior written permission. 00018 * 00019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00020 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00021 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00022 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 00023 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00024 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00025 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00026 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00027 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00028 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00029 * POSSIBILITY OF SUCH DAMAGE. 00030 ******************************************************************************/ 00031 00032 /******************************************************************************* 00033 * \file sparky_v2.hpp 00034 * 00035 * \author MAV'RIC Team 00036 * \author Jean-Francois Burnier 00037 * 00038 * \brief Autopilot for Sparky board based on STM32 00039 * 00040 ******************************************************************************/ 00041 00042 00043 #ifndef SPARKY_V2_HPP_ 00044 #define SPARKY_V2_HPP_ 00045 00046 #include "hal/dummy/pwm_dummy.hpp" 00047 00048 #include "hal/stm32/gpio_stm32.hpp" 00049 #include "hal/stm32/pwm_stm32.hpp" 00050 #include "hal/stm32/serial_stm32.hpp" 00051 #include "hal/stm32/serial_usb_stm32.hpp" 00052 #include "hal/stm32/spi_stm32.hpp" 00053 #include "hal/stm32/i2c_stm32.hpp" 00054 00055 #include "drivers/mpu_9250.hpp" 00056 #include "drivers/servo.hpp" 00057 #include "drivers/state_display_sparky_v2.hpp" 00058 #include "drivers/barometer_ms5611.hpp" 00059 00060 #include "hal/dummy/serial_dummy.hpp" 00061 #include "hal/dummy/gpio_dummy.hpp" 00062 #include "hal/common/led_gpio.hpp" 00063 00064 #include "sensing/imu.hpp" 00065 00066 extern "C" 00067 { 00068 #include "util/streams.h" 00069 } 00070 00071 00072 // Preprocessor definitions 00073 00074 /* 00075 * Should the ESC be calibrated? 00076 * 0 for false (normal flight) 00077 * 1 for true (calibration) 00078 * !!!IMPORTANT!!! 00079 * IF CALIBRATING, TAKE OFF PROPS 00080 */ 00081 #define CALIBRATE_ESC 0 00082 00083 00084 00085 00090 class Sparky_v2 00091 { 00092 public: 00093 00094 static const uint8_t PWM_COUNT = 10; 00095 00099 struct conf_t 00100 { 00101 gpio_stm32_conf_t dsm_receiver_gpio_config; 00102 gpio_stm32_conf_t dsm_power_gpio_config; 00103 gpio_stm32_conf_t led_err_gpio_config; 00104 gpio_stm32_conf_t led_stat_gpio_config; 00105 gpio_stm32_conf_t led_rf_gpio_config; 00106 gpio_stm32_conf_t nss_gpio_config[3]; 00107 imu_conf_t imu_config; 00108 Pwm_stm32::config_t pwm_config[PWM_COUNT]; 00109 serial_stm32_conf_t serial_1_config; 00110 Serial_usb_stm32::conf_t serial_usb_config; 00111 servo_conf_t servo_config[PWM_COUNT]; 00112 spi_stm32_conf_t spi_config[2]; 00113 }; 00114 00120 static inline conf_t default_config(); 00121 00122 00128 Sparky_v2(conf_t config = default_config()); 00129 00130 00136 bool init(void); 00137 00141 Gpio_stm32 led_err_gpio_; 00142 Gpio_stm32 led_stat_gpio_; 00143 Gpio_stm32 led_rf_gpio_; 00144 Led_gpio led_err_; 00145 Led_gpio led_stat_; 00146 Led_gpio led_rf_; 00147 Serial_stm32 serial_1_; 00148 Serial_usb_stm32 serial_; 00149 Pwm_stm32 pwm_[PWM_COUNT]; 00150 Servo servo_[PWM_COUNT]; 00151 Spi_stm32 spi_1_; 00152 Spi_stm32 spi_3_; 00153 Gpio_stm32 nss_1_gpio_; 00154 Gpio_stm32 nss_2_gpio_; 00155 Gpio_stm32 nss_3_gpio_; 00156 State_display_sparky_v2 state_display_sparky_v2_; 00157 Mpu_9250 mpu_9250_; 00158 Imu imu_; 00159 00160 private: 00161 byte_stream_t dbg_stream_; 00162 }; 00163 00164 00170 Sparky_v2::conf_t Sparky_v2::default_config() 00171 { 00172 conf_t conf = {}; 00173 00174 // ------------------------------------------------------------------------- 00175 // GPIO config 00176 // ------------------------------------------------------------------------- 00177 // Error Led 00178 conf.led_err_gpio_config.port = GPIO_STM32_PORT_B; 00179 conf.led_err_gpio_config.pin = GPIO_STM32_PIN_4; 00180 conf.led_err_gpio_config.dir = GPIO_OUTPUT; 00181 conf.led_err_gpio_config.pull = GPIO_PULL_UPDOWN_NONE; 00182 00183 // Status Led 00184 conf.led_stat_gpio_config.port = GPIO_STM32_PORT_B; 00185 conf.led_stat_gpio_config.pin = GPIO_STM32_PIN_5; 00186 conf.led_stat_gpio_config.dir = GPIO_OUTPUT; 00187 conf.led_stat_gpio_config.pull = GPIO_PULL_UPDOWN_NONE; 00188 00189 // Rf Led 00190 conf.led_rf_gpio_config.port = GPIO_STM32_PORT_B; 00191 conf.led_rf_gpio_config.pin = GPIO_STM32_PIN_6; 00192 conf.led_rf_gpio_config.dir = GPIO_OUTPUT; 00193 conf.led_rf_gpio_config.pull = GPIO_PULL_UPDOWN_NONE; 00194 00195 // ------------------------------------------------------------------------- 00196 // Imu config 00197 // ------------------------------------------------------------------------- 00198 conf.imu_config = imu_default_config(); 00199 // Accelerometer 00200 00201 // Axis and sign 00202 conf.imu_config.accelerometer.sign[0] = -1.0f; 00203 conf.imu_config.accelerometer.sign[1] = -1.0f; 00204 conf.imu_config.accelerometer.sign[2] = -1.0f; 00205 conf.imu_config.accelerometer.axis[0] = 1; 00206 conf.imu_config.accelerometer.axis[1] = 0; 00207 conf.imu_config.accelerometer.axis[2] = 2; 00208 00209 // Gyroscope 00210 00211 // Axis and sign 00212 conf.imu_config.gyroscope.sign[0] = -1.0f; 00213 conf.imu_config.gyroscope.sign[1] = -1.0f; 00214 conf.imu_config.gyroscope.sign[2] = -1.0f; 00215 conf.imu_config.gyroscope.axis[0] = 1; 00216 conf.imu_config.gyroscope.axis[1] = 0; 00217 conf.imu_config.gyroscope.axis[2] = 2; 00218 00219 // Magnetometer 00220 00221 // Scale 00222 conf.imu_config.magnetometer.scale_factor[0] = 250.0f; 00223 conf.imu_config.magnetometer.scale_factor[1] = 250.0f; 00224 conf.imu_config.magnetometer.scale_factor[2] = 300.0f; 00225 00226 // Axis and sign 00227 conf.imu_config.magnetometer.sign[0] = -1.0f; 00228 conf.imu_config.magnetometer.sign[1] = -1.0f; 00229 conf.imu_config.magnetometer.sign[2] = +1.0f; 00230 conf.imu_config.magnetometer.axis[0] = 0; 00231 conf.imu_config.magnetometer.axis[1] = 1; 00232 conf.imu_config.magnetometer.axis[2] = 2; 00233 00234 // ------------------------------------------------------------------------- 00235 // PWM config 00236 // ------------------------------------------------------------------------- 00237 // Warning the PWM configuration is different from the one on the Sparky_V2 datasheet 00238 // 00239 // Configuration of PWMs on the servo connectors: 00240 // ID Pin Timer Channel 00241 // --------------------- 00242 // 0 PB0 TIM3 CH3 00243 // 1 PB1 TIM3 CH4 00244 // 2 PA3 TIM9 CH2 00245 // 3 PA2 TIM9 CH1 00246 // 4 PA1 TIM5 CH2 00247 // 5 PA0 TIM5 CH1 00248 // 00249 // Configuration of PWMs on the servo connectors: 00250 // ID Pin Timer Channel 00251 // --------------------- 00252 // 6 PC9 TIM8 CH4 00253 // 7 PC8 TIM8 CH3 00254 // 8 PB15 TIM12 CH2 00255 // 9 PB14 TIM12 CH1 00256 00257 conf.pwm_config[0].gpio_config.port = GPIO_STM32_PORT_B; 00258 conf.pwm_config[0].gpio_config.pin = GPIO_STM32_PIN_0; 00259 conf.pwm_config[0].gpio_config.dir = GPIO_OUTPUT; 00260 conf.pwm_config[0].gpio_config.pull = GPIO_PULL_UPDOWN_NONE; 00261 conf.pwm_config[0].gpio_config.alt_fct = GPIO_STM32_AF_2; 00262 conf.pwm_config[0].timer = TIM3; 00263 conf.pwm_config[0].rcc_timer = RCC_TIM3; 00264 conf.pwm_config[0].channel = Pwm_stm32::PWM_STM32_CHANNEL_3; 00265 conf.pwm_config[0].prescaler = 84; // max timer clock freq of TIM3 is 84MHz 00266 conf.pwm_config[0].period = 20000; // 50Hz 00267 conf.pwm_config[0].pulse_us = 5000; 00268 00269 conf.pwm_config[1].gpio_config.port = GPIO_STM32_PORT_B; 00270 conf.pwm_config[1].gpio_config.pin = GPIO_STM32_PIN_1; 00271 conf.pwm_config[1].gpio_config.dir = GPIO_OUTPUT; 00272 conf.pwm_config[1].gpio_config.pull = GPIO_PULL_UPDOWN_NONE; 00273 conf.pwm_config[1].gpio_config.alt_fct = GPIO_STM32_AF_2; 00274 conf.pwm_config[1].timer = TIM3; 00275 conf.pwm_config[1].rcc_timer = RCC_TIM3; 00276 conf.pwm_config[1].channel = Pwm_stm32::PWM_STM32_CHANNEL_4; 00277 conf.pwm_config[1].prescaler = 84; // max timer clock freq of TIM3 is 84MHz 00278 conf.pwm_config[1].period = 20000; // 50Hz 00279 conf.pwm_config[1].pulse_us = 5000; 00280 00281 conf.pwm_config[2].gpio_config.port = GPIO_STM32_PORT_A; 00282 conf.pwm_config[2].gpio_config.pin = GPIO_STM32_PIN_3; 00283 conf.pwm_config[2].gpio_config.dir = GPIO_OUTPUT; 00284 conf.pwm_config[2].gpio_config.pull = GPIO_PULL_UPDOWN_NONE; 00285 conf.pwm_config[2].gpio_config.alt_fct = GPIO_STM32_AF_3; 00286 conf.pwm_config[2].timer = TIM9; 00287 conf.pwm_config[2].rcc_timer = RCC_TIM9; 00288 conf.pwm_config[2].channel = Pwm_stm32::PWM_STM32_CHANNEL_2; 00289 conf.pwm_config[2].prescaler = 168; // max timer clock freq of TIM9 is 168MHz 00290 conf.pwm_config[2].period = 20000; // 50Hz 00291 conf.pwm_config[2].pulse_us = 5000; 00292 00293 conf.pwm_config[3].gpio_config.port = GPIO_STM32_PORT_A; 00294 conf.pwm_config[3].gpio_config.pin = GPIO_STM32_PIN_2; 00295 conf.pwm_config[3].gpio_config.dir = GPIO_OUTPUT; 00296 conf.pwm_config[3].gpio_config.pull = GPIO_PULL_UPDOWN_NONE; 00297 conf.pwm_config[3].gpio_config.alt_fct = GPIO_STM32_AF_3; 00298 conf.pwm_config[3].timer = TIM9; 00299 conf.pwm_config[3].rcc_timer = RCC_TIM9; 00300 conf.pwm_config[3].channel = Pwm_stm32::PWM_STM32_CHANNEL_1; 00301 conf.pwm_config[3].prescaler = 168; // max timer clock freq of TIM9 is 168MHz 00302 conf.pwm_config[3].period = 20000; // 50Hz 00303 conf.pwm_config[3].pulse_us = 5000; 00304 00305 conf.pwm_config[4].gpio_config.port = GPIO_STM32_PORT_A; 00306 conf.pwm_config[4].gpio_config.pin = GPIO_STM32_PIN_1; 00307 conf.pwm_config[4].gpio_config.dir = GPIO_OUTPUT; 00308 conf.pwm_config[4].gpio_config.pull = GPIO_PULL_UPDOWN_NONE; 00309 conf.pwm_config[4].gpio_config.alt_fct = GPIO_STM32_AF_2; 00310 conf.pwm_config[4].timer = TIM5; 00311 conf.pwm_config[4].rcc_timer = RCC_TIM5; 00312 conf.pwm_config[4].channel = Pwm_stm32::PWM_STM32_CHANNEL_2; 00313 conf.pwm_config[4].prescaler = 84; // max timer clock freq of TIM5 is 84MHz 00314 conf.pwm_config[4].period = 20000; // 50Hz 00315 conf.pwm_config[4].pulse_us = 5000; 00316 00317 conf.pwm_config[5].gpio_config.port = GPIO_STM32_PORT_A; 00318 conf.pwm_config[5].gpio_config.pin = GPIO_STM32_PIN_0; 00319 conf.pwm_config[5].gpio_config.dir = GPIO_OUTPUT; 00320 conf.pwm_config[5].gpio_config.pull = GPIO_PULL_UPDOWN_NONE; 00321 conf.pwm_config[5].gpio_config.alt_fct = GPIO_STM32_AF_2; 00322 conf.pwm_config[5].timer = TIM5; 00323 conf.pwm_config[5].rcc_timer = RCC_TIM5; 00324 conf.pwm_config[5].channel = Pwm_stm32::PWM_STM32_CHANNEL_1; 00325 conf.pwm_config[5].prescaler = 84; // max timer clock freq of TIM5 is 84MHz 00326 conf.pwm_config[5].period = 20000; // 50Hz 00327 conf.pwm_config[5].pulse_us = 5000; 00328 00329 conf.pwm_config[9].gpio_config.port = GPIO_STM32_PORT_C; 00330 conf.pwm_config[9].gpio_config.pin = GPIO_STM32_PIN_9; 00331 conf.pwm_config[9].gpio_config.dir = GPIO_OUTPUT; 00332 conf.pwm_config[9].gpio_config.pull = GPIO_PULL_UPDOWN_NONE; 00333 conf.pwm_config[9].gpio_config.alt_fct = GPIO_STM32_AF_2; 00334 conf.pwm_config[9].timer = TIM8; 00335 conf.pwm_config[9].rcc_timer = RCC_TIM8; 00336 conf.pwm_config[9].channel = Pwm_stm32::PWM_STM32_CHANNEL_4; 00337 conf.pwm_config[9].prescaler = 84; // max timer clock freq of TIM8 is 84MHz 00338 conf.pwm_config[9].period = 20000; // 50Hz 00339 conf.pwm_config[9].pulse_us = 5000; 00340 00341 conf.pwm_config[8].gpio_config.port = GPIO_STM32_PORT_C; 00342 conf.pwm_config[8].gpio_config.pin = GPIO_STM32_PIN_8; 00343 conf.pwm_config[8].gpio_config.dir = GPIO_OUTPUT; 00344 conf.pwm_config[8].gpio_config.pull = GPIO_PULL_UPDOWN_NONE; 00345 conf.pwm_config[8].gpio_config.alt_fct = GPIO_STM32_AF_3; 00346 conf.pwm_config[8].timer = TIM8; 00347 conf.pwm_config[8].rcc_timer = RCC_TIM8; 00348 conf.pwm_config[8].channel = Pwm_stm32::PWM_STM32_CHANNEL_3; 00349 conf.pwm_config[8].prescaler = 84; // max timer clock freq of TIM8 is 84MHz 00350 conf.pwm_config[8].period = 20000; // 50Hz 00351 conf.pwm_config[8].pulse_us = 5000; 00352 00353 conf.pwm_config[7].gpio_config.port = GPIO_STM32_PORT_B; 00354 conf.pwm_config[7].gpio_config.pin = GPIO_STM32_PIN_15; 00355 conf.pwm_config[7].gpio_config.dir = GPIO_OUTPUT; 00356 conf.pwm_config[7].gpio_config.pull = GPIO_PULL_UPDOWN_NONE; 00357 conf.pwm_config[7].gpio_config.alt_fct = GPIO_STM32_AF_9; 00358 conf.pwm_config[7].timer = TIM12; 00359 conf.pwm_config[7].rcc_timer = RCC_TIM12; 00360 conf.pwm_config[7].channel = Pwm_stm32::PWM_STM32_CHANNEL_2; 00361 conf.pwm_config[7].prescaler = 84; // max timer clock freq of TIM12 is 84MHz 00362 conf.pwm_config[7].period = 20000; // 50Hz 00363 conf.pwm_config[7].pulse_us = 5000; 00364 00365 conf.pwm_config[6].gpio_config.port = GPIO_STM32_PORT_B; 00366 conf.pwm_config[6].gpio_config.pin = GPIO_STM32_PIN_14; 00367 conf.pwm_config[6].gpio_config.dir = GPIO_OUTPUT; 00368 conf.pwm_config[6].gpio_config.pull = GPIO_PULL_UPDOWN_NONE; 00369 conf.pwm_config[6].gpio_config.alt_fct = GPIO_STM32_AF_9; 00370 conf.pwm_config[6].timer = TIM12; 00371 conf.pwm_config[6].rcc_timer = RCC_TIM12; 00372 conf.pwm_config[6].channel = Pwm_stm32::PWM_STM32_CHANNEL_1; 00373 conf.pwm_config[6].prescaler = 84; // max timer clock freq of TIM12 is 84MHz 00374 conf.pwm_config[6].period = 20000; // 50Hz 00375 conf.pwm_config[6].pulse_us = 5000; 00376 00377 00378 // ------------------------------------------------------------------------- 00379 // Servo config 00380 // ------------------------------------------------------------------------- 00381 // conf.servo_config[0] = servo_default_config_brush_motor(); 00382 // // with a 2S battery we need to divide the duty cycle by 2 not to over-heat 00383 // conf.servo_config[0].pulse_center_us = 62; 00384 // conf.servo_config[0].pulse_magnitude_us = 62; // duty cycle: 0 to 100% 00385 // conf.servo_config[1] = servo_default_config_brush_motor(); 00386 // conf.servo_config[1].pulse_center_us = 62; 00387 // conf.servo_config[1].pulse_magnitude_us = 62; // duty cycle: 0 to 100% 00388 // conf.servo_config[2] = servo_default_config_brush_motor(); 00389 // conf.servo_config[2].pulse_center_us = 62; 00390 // conf.servo_config[2].pulse_magnitude_us = 62; // duty cycle: 0 to 100% 00391 // conf.servo_config[3] = servo_default_config_brush_motor(); 00392 // conf.servo_config[3].pulse_center_us = 62; 00393 // conf.servo_config[3].pulse_magnitude_us = 62; // duty cycle: 0 to 100% 00394 // conf.servo_config[4] = servo_default_config_esc(); 00395 // conf.servo_config[5] = servo_default_config_esc(); 00396 // conf.servo_config[6] = servo_default_config_esc(); 00397 // conf.servo_config[7] = servo_default_config_esc(); 00398 for (size_t i = 0; i < 8; i++) 00399 { 00400 conf.servo_config[i] = servo_default_config_esc(); 00401 } 00402 00403 // ------------------------------------------------------------------------- 00404 // Serial 1 config 00405 // ------------------------------------------------------------------------- 00406 conf.serial_1_config = serial_stm32_default_config(); 00407 conf.serial_1_config.device = SERIAL_STM32_1; 00408 conf.serial_1_config.baudrate = 57600; 00409 conf.serial_1_config.databits = SERIAL_STM32_DATABITS_8; 00410 conf.serial_1_config.stopbits = SERIAL_STM32_STOPBITS_1; 00411 conf.serial_1_config.parity = SERIAL_STM32_PARITY_NONE; 00412 conf.serial_1_config.mode = SERIAL_STM32_MODE_TX_RX; 00413 conf.serial_1_config.flow_control = SERIAL_STM32_FLOWCONTROL_NONE; 00414 conf.serial_1_config.rx_port = GPIO_STM32_PORT_A; 00415 conf.serial_1_config.rx_pin = GPIO_STM32_PIN_10; 00416 conf.serial_1_config.rx_af = GPIO_STM32_AF_7; 00417 conf.serial_1_config.tx_port = GPIO_STM32_PORT_A; 00418 conf.serial_1_config.tx_pin = GPIO_STM32_PIN_9; 00419 conf.serial_1_config.tx_af = GPIO_STM32_AF_7; 00420 00421 // ------------------------------------------------------------------------- 00422 // USB config 00423 // ------------------------------------------------------------------------- 00424 conf.serial_usb_config = Serial_usb_stm32::default_config(); 00425 00426 // ------------------------------------------------------------------------- 00427 // SPI config 00428 // ------------------------------------------------------------------------- 00429 00430 // SPI 1 config 00431 conf.spi_config[0].spi_device = STM32_SPI1; 00432 conf.spi_config[0].mode = STM32_SPI_MODE_CPOL1_CPHA1; 00433 conf.spi_config[0].clk_div = SPI_CR1_BAUDRATE_FPCLK_DIV_128; 00434 conf.spi_config[0].ss_mode_hard = true; 00435 00436 conf.spi_config[0].miso_gpio_config.port = GPIO_STM32_PORT_A; 00437 conf.spi_config[0].miso_gpio_config.pin = GPIO_STM32_PIN_6; 00438 conf.spi_config[0].miso_gpio_config.dir = GPIO_INPUT; 00439 conf.spi_config[0].miso_gpio_config.pull = GPIO_PULL_UPDOWN_UP; 00440 conf.spi_config[0].miso_gpio_config.alt_fct = GPIO_STM32_AF_5; 00441 00442 conf.spi_config[0].mosi_gpio_config.port = GPIO_STM32_PORT_A; 00443 conf.spi_config[0].mosi_gpio_config.pin = GPIO_STM32_PIN_7; 00444 conf.spi_config[0].mosi_gpio_config.dir = GPIO_OUTPUT; 00445 conf.spi_config[0].mosi_gpio_config.pull = GPIO_PULL_UPDOWN_UP; 00446 conf.spi_config[0].mosi_gpio_config.alt_fct = GPIO_STM32_AF_5; 00447 00448 conf.spi_config[0].sck_gpio_config.port = GPIO_STM32_PORT_A; 00449 conf.spi_config[0].sck_gpio_config.pin = GPIO_STM32_PIN_5; 00450 conf.spi_config[0].sck_gpio_config.dir = GPIO_OUTPUT; 00451 conf.spi_config[0].sck_gpio_config.pull = GPIO_PULL_UPDOWN_UP; 00452 conf.spi_config[0].sck_gpio_config.alt_fct = GPIO_STM32_AF_5; 00453 00454 // SPI 1 slave select config 00455 conf.nss_gpio_config[0].port = GPIO_STM32_PORT_C; 00456 conf.nss_gpio_config[0].pin = GPIO_STM32_PIN_4; 00457 conf.nss_gpio_config[0].dir = GPIO_OUTPUT; 00458 conf.nss_gpio_config[0].pull = GPIO_PULL_UPDOWN_UP; 00459 00460 // SPI 3 config 00461 conf.spi_config[1].spi_device = STM32_SPI3; 00462 conf.spi_config[1].mode = STM32_SPI_MODE_CPOL1_CPHA1; 00463 conf.spi_config[1].clk_div = SPI_CR1_BAUDRATE_FPCLK_DIV_64; 00464 conf.spi_config[1].ss_mode_hard = true; 00465 00466 conf.spi_config[1].miso_gpio_config.port = GPIO_STM32_PORT_C; 00467 conf.spi_config[1].miso_gpio_config.pin = GPIO_STM32_PIN_11; 00468 conf.spi_config[1].miso_gpio_config.dir = GPIO_INPUT; 00469 conf.spi_config[1].miso_gpio_config.pull = GPIO_PULL_UPDOWN_DOWN; 00470 conf.spi_config[1].miso_gpio_config.alt_fct = GPIO_STM32_AF_6; 00471 00472 conf.spi_config[1].mosi_gpio_config.port = GPIO_STM32_PORT_C; 00473 conf.spi_config[1].mosi_gpio_config.pin = GPIO_STM32_PIN_12; 00474 conf.spi_config[1].mosi_gpio_config.dir = GPIO_OUTPUT; 00475 conf.spi_config[1].mosi_gpio_config.pull = GPIO_PULL_UPDOWN_DOWN; 00476 conf.spi_config[1].mosi_gpio_config.alt_fct = GPIO_STM32_AF_6; 00477 00478 conf.spi_config[1].sck_gpio_config.port = GPIO_STM32_PORT_C; 00479 conf.spi_config[1].sck_gpio_config.pin = GPIO_STM32_PIN_10; 00480 conf.spi_config[1].sck_gpio_config.dir = GPIO_OUTPUT; 00481 conf.spi_config[1].sck_gpio_config.pull = GPIO_PULL_UPDOWN_DOWN; 00482 conf.spi_config[1].sck_gpio_config.alt_fct = GPIO_STM32_AF_6; 00483 00484 // SPI 3 slaves select config 00485 conf.nss_gpio_config[1].port = GPIO_STM32_PORT_A; 00486 conf.nss_gpio_config[1].pin = GPIO_STM32_PIN_15; 00487 conf.nss_gpio_config[1].dir = GPIO_OUTPUT; 00488 conf.nss_gpio_config[1].pull = GPIO_PULL_UPDOWN_NONE; 00489 00490 conf.nss_gpio_config[2].port = GPIO_STM32_PORT_B; 00491 conf.nss_gpio_config[2].pin = GPIO_STM32_PIN_3; 00492 conf.nss_gpio_config[2].dir = GPIO_OUTPUT; 00493 conf.nss_gpio_config[2].pull = GPIO_PULL_UPDOWN_NONE; 00494 00495 return conf; 00496 } 00497 00498 00499 #endif /* SPARKY_HPP_ */