From 56e916932c7cda7c3fffb14eeaa4408e4455ef0c Mon Sep 17 00:00:00 2001 From: conkerkh Date: Fri, 23 Mar 2018 08:18:48 +0100 Subject: [PATCH] Add DiscF407 target for developers (#5442) * Add DiscF407 target for developers * Requested changes --- src/main/target/STM32F4DISCOVERY/target.c | 37 ++++++ src/main/target/STM32F4DISCOVERY/target.h | 127 +++++++++++++++++++++ src/main/target/STM32F4DISCOVERY/target.mk | 12 ++ 3 files changed, 176 insertions(+) create mode 100644 src/main/target/STM32F4DISCOVERY/target.c create mode 100644 src/main/target/STM32F4DISCOVERY/target.h create mode 100644 src/main/target/STM32F4DISCOVERY/target.mk diff --git a/src/main/target/STM32F4DISCOVERY/target.c b/src/main/target/STM32F4DISCOVERY/target.c new file mode 100644 index 0000000000..3449153d36 --- /dev/null +++ b/src/main/target/STM32F4DISCOVERY/target.c @@ -0,0 +1,37 @@ +/* + * This file is part of Cleanflight. + * + * Cleanflight is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Cleanflight is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Cleanflight. If not, see . + */ + +#include + +#include +#include "drivers/io.h" + +#include "drivers/dma.h" +#include "drivers/timer.h" +#include "drivers/timer_def.h" + +const timerHardware_t timerHardware[USABLE_TIMER_CHANNEL_COUNT] = { + + DEF_TIM(TIM4, CH4, PB9, TIM_USE_PPM | TIM_USE_LED, 1, 0 ), // PPM IN + DEF_TIM(TIM3, CH4, PB1, TIM_USE_MOTOR, 0, 0 ), // S1_OUT - TIM3_UP - BURST + DEF_TIM(TIM3, CH3, PB0, TIM_USE_MOTOR, 0, 0 ), // S2_OUT - TIM3_UP - BURST + DEF_TIM(TIM2, CH3, PA2, TIM_USE_MOTOR, 0, 0 ), // S3_OUT - TIM2_UP - BURST + DEF_TIM(TIM2, CH4, PA3, TIM_USE_MOTOR, 0, 1 ), // S4_OUT - TIM2_UP - BURST + DEF_TIM(TIM1, CH3, PA10, TIM_USE_MOTOR, 0, 1 ), // S5_OUT - TIM1_UP - BURST + DEF_TIM(TIM1, CH1, PA8, TIM_USE_MOTOR, 0, 1 ), // S6_OUT - TIM1_UP - BURST +}; + diff --git a/src/main/target/STM32F4DISCOVERY/target.h b/src/main/target/STM32F4DISCOVERY/target.h new file mode 100644 index 0000000000..ab1e60ee6e --- /dev/null +++ b/src/main/target/STM32F4DISCOVERY/target.h @@ -0,0 +1,127 @@ +/* + * This file is part of Cleanflight. + * + * Cleanflight is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Cleanflight is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Cleanflight. If not, see . + */ + +#pragma once + +#define TARGET_BOARD_IDENTIFIER "SDF4" +#define USBD_PRODUCT_STRING "DISCF4" + +//LEDs +#define LED0_PIN PD12 +#define LED1_PIN PD13 + +#define LED0_INVERTED +#define LED1_INVERTED + +#define USE_DSHOT_DMAR + +// MPU6500 interrupt +#define USE_EXTI +#define MPU_INT_EXTI PC4 +#define USE_MPU_DATA_READY_SIGNAL +//#define DEBUG_MPU_DATA_READY_INTERRUPT + +#define MPU6500_CS_PIN PC4 +#define MPU6500_SPI_INSTANCE SPI1 + +// ACC section -- start +#define USE_ACC +#define USE_FAKE_ACC +#define USE_ACC_MPU6500 +#define USE_ACC_SPI_MPU6500 +#define ACC_MPU6500_ALIGN CW180_DEG_FLIP +// ACC section -- end + +// GYRO section -- start +#define USE_GYRO +#define USE_FAKE_GYRO +#define USE_GYRO_MPU6500 +#define USE_GYRO_SPI_MPU6500 +#define GYRO_MPU6500_ALIGN CW180_DEG_FLIP +// GYRO section -- end + +#define USE_VCP +#define USB_MSC +#define MSC_BUTTON PA0 +#define VBUS_SENSING_PIN PA9 +#define VBUS_SENSING_ENABLED + +#define USE_UART1 +#define UART1_RX_PIN PB7 +#define UART1_TX_PIN PB6 + +#define USE_UART2 +#define UART2_RX_PIN PA3 +#define UART2_TX_PIN PA2 + +#define USE_UART3 +#define UART3_RX_PIN PB11 +#define UART3_TX_PIN PB10 + +#define USE_UART4 +#define UART4_RX_PIN PA1 +#define UART4_TX_PIN PA0 + +#define USE_UART6 +#define UART6_RX_PIN PC7 +#define UART6_TX_PIN PC6 + +#define SERIAL_PORT_COUNT 6 //VCP, USART1, USART3, USART4, USART6 + +#define USE_ESCSERIAL +#define ESCSERIAL_TIMER_TX_HARDWARE 0 // PWM 1 + +//SPI +#define USE_SPI + +#define USE_SPI_DEVICE_1 + +#define USE_SPI_DEVICE_2 +#define SPI2_SCK_PIN PB13 +#define SPI2_MISO_PIN PB14 +#define SPI2_MOSI_PIN PB15 + +#define USE_SDCARD +#define SDCARD_SPI_INSTANCE SPI2 +#define SDCARD_SPI_CS_PIN PD8 +// SPI2 is on the APB1 bus whose clock runs at 84MHz. Divide to under 400kHz for init: +#define SDCARD_SPI_INITIALIZATION_CLOCK_DIVIDER 256 // 328kHz +// Divide to under 25MHz for normal operation: +#define SDCARD_SPI_FULL_SPEED_CLOCK_DIVIDER 4 // 5,5MHz + +#define SDCARD_DMA_CHANNEL_TX DMA1_Stream5 +#define SDCARD_DMA_CHANNEL 0 + +#define USE_ADC +#define DEFAULT_VOLTAGE_METER_SOURCE VOLTAGE_METER_ADC +#define DEFAULT_CURRENT_METER_SOURCE CURRENT_METER_ADC +#define BOARD_HAS_VOLTAGE_DIVIDER +#define VBAT_ADC_PIN PC1 +#define CURRENT_METER_ADC_PIN PC2 + +#define DEFAULT_RX_FEATURE FEATURE_RX_SERIAL +#define SERIALRX_PROVIDER SERIALRX_SBUS + +#define USE_SERIAL_4WAY_BLHELI_INTERFACE + +#define TARGET_IO_PORTA 0xffff +#define TARGET_IO_PORTB 0xffff +#define TARGET_IO_PORTC 0xffff +#define TARGET_IO_PORTD 0xffff + +#define USABLE_TIMER_CHANNEL_COUNT 7 +#define USED_TIMERS ( TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(4) | TIM_N(5) | TIM_N(8)) diff --git a/src/main/target/STM32F4DISCOVERY/target.mk b/src/main/target/STM32F4DISCOVERY/target.mk new file mode 100644 index 0000000000..c3619efdb4 --- /dev/null +++ b/src/main/target/STM32F4DISCOVERY/target.mk @@ -0,0 +1,12 @@ +F405_TARGETS += $(TARGET) +FEATURES += VCP SDCARD MSC + +TARGET_SRC = \ + drivers/accgyro/accgyro_fake.c \ + drivers/accgyro/accgyro_mpu.c \ + drivers/accgyro/accgyro_mpu6500.c \ + drivers/accgyro/accgyro_spi_mpu6500.c + +TARGET_SRC += \ + msc/usbd_storage_sd_spi.c \ + msc/usbd_msc_desc.c