mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-26 01:35:41 +03:00
AlienFligth F3 V2 support
Updated SPI driver (SPI3 on F3 targets) AK8963 Mag support (part of MPU9250) MPU9250 SPI support via MPU6500 driver Updated LED driver for alternative LED sets Enable gyro intterupt for AlienFlight F3 targets Update AlienWii/AlienFlight documentation Rename AlienWii to AlienFlight
This commit is contained in:
parent
b1476c05f8
commit
7634e4c635
36 changed files with 771 additions and 247 deletions
|
@ -35,10 +35,12 @@ static volatile uint16_t spi3ErrorCount = 0;
|
|||
#ifdef USE_SPI_DEVICE_1
|
||||
|
||||
#ifndef SPI1_GPIO
|
||||
#define SPI1_GPIO GPIOA
|
||||
#define SPI1_GPIO_PERIPHERAL RCC_AHBPeriph_GPIOA
|
||||
#define SPI1_NSS_GPIO GPIOA
|
||||
#define SPI1_NSS_PERIPHERAL RCC_AHBPeriph_GPIOA
|
||||
#define SPI1_NSS_PIN GPIO_Pin_4
|
||||
#define SPI1_NSS_PIN_SOURCE GPIO_PinSource4
|
||||
#define SPI1_GPIO GPIOA
|
||||
#define SPI1_GPIO_PERIPHERAL RCC_AHBPeriph_GPIOA
|
||||
#define SPI1_SCK_PIN GPIO_Pin_5
|
||||
#define SPI1_SCK_PIN_SOURCE GPIO_PinSource5
|
||||
#define SPI1_MISO_PIN GPIO_Pin_6
|
||||
|
@ -71,7 +73,10 @@ void initSpi1(void)
|
|||
GPIO_PinAFConfig(SPI1_GPIO, SPI1_SCK_PIN_SOURCE, GPIO_AF_5);
|
||||
GPIO_PinAFConfig(SPI1_GPIO, SPI1_MISO_PIN_SOURCE, GPIO_AF_5);
|
||||
GPIO_PinAFConfig(SPI1_GPIO, SPI1_MOSI_PIN_SOURCE, GPIO_AF_5);
|
||||
|
||||
#ifdef SPI1_NSS_PIN_SOURCE
|
||||
RCC_AHBPeriphClockCmd(SPI1_NSS_PERIPHERAL, ENABLE);
|
||||
|
||||
GPIO_PinAFConfig(SPI1_GPIO, SPI1_NSS_PIN_SOURCE, GPIO_AF_5);
|
||||
#endif
|
||||
// Init pins
|
||||
|
@ -89,7 +94,7 @@ void initSpi1(void)
|
|||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||
|
||||
GPIO_Init(SPI1_GPIO, &GPIO_InitStructure);
|
||||
GPIO_Init(SPI1_NSS_GPIO, &GPIO_InitStructure);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -100,20 +105,20 @@ void initSpi1(void)
|
|||
gpio.mode = Mode_AF_PP;
|
||||
gpio.pin = SPI1_MOSI_PIN | SPI1_SCK_PIN;
|
||||
gpio.speed = Speed_50MHz;
|
||||
gpioInit(GPIOA, &gpio);
|
||||
gpioInit(SPI1_GPIO, &gpio);
|
||||
// MISO as input
|
||||
gpio.pin = SPI1_MISO_PIN;
|
||||
gpio.mode = Mode_IN_FLOATING;
|
||||
gpioInit(GPIOA, &gpio);
|
||||
gpioInit(SPI1_GPIO, &gpio);
|
||||
#ifdef SPI1_NSS_PIN
|
||||
// NSS as gpio slave select
|
||||
gpio.pin = SPI1_NSS_PIN;
|
||||
gpio.mode = Mode_Out_PP;
|
||||
gpioInit(GPIOA, &gpio);
|
||||
gpioInit(SPI1_NSS_GPIO, &gpio);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Init SPI hardware
|
||||
// Init SPI1 hardware
|
||||
SPI_I2S_DeInit(SPI1);
|
||||
|
||||
spi.SPI_Mode = SPI_Mode_Master;
|
||||
|
@ -133,16 +138,23 @@ void initSpi1(void)
|
|||
|
||||
SPI_Init(SPI1, &spi);
|
||||
SPI_Cmd(SPI1, ENABLE);
|
||||
|
||||
#ifdef SPI1_NSS_PIN
|
||||
// Drive NSS high to disable connected SPI device.
|
||||
GPIO_SetBits(SPI1_NSS_GPIO, SPI1_NSS_PIN);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef USE_SPI_DEVICE_2
|
||||
|
||||
#ifndef SPI2_GPIO
|
||||
#define SPI2_GPIO GPIOB
|
||||
#define SPI2_GPIO_PERIPHERAL RCC_AHBPeriph_GPIOB
|
||||
#define SPI2_NSS_GPIO GPIOB
|
||||
#define SPI2_NSS_PERIPHERAL RCC_AHBPeriph_GPIOB
|
||||
#define SPI2_NSS_PIN GPIO_Pin_12
|
||||
#define SPI2_NSS_PIN_SOURCE GPIO_PinSource12
|
||||
#define SPI2_GPIO GPIOB
|
||||
#define SPI2_GPIO_PERIPHERAL RCC_AHBPeriph_GPIOB
|
||||
#define SPI2_SCK_PIN GPIO_Pin_13
|
||||
#define SPI2_SCK_PIN_SOURCE GPIO_PinSource13
|
||||
#define SPI2_MISO_PIN GPIO_Pin_14
|
||||
|
@ -175,7 +187,10 @@ void initSpi2(void)
|
|||
GPIO_PinAFConfig(SPI2_GPIO, SPI2_SCK_PIN_SOURCE, GPIO_AF_5);
|
||||
GPIO_PinAFConfig(SPI2_GPIO, SPI2_MISO_PIN_SOURCE, GPIO_AF_5);
|
||||
GPIO_PinAFConfig(SPI2_GPIO, SPI2_MOSI_PIN_SOURCE, GPIO_AF_5);
|
||||
|
||||
#ifdef SPI2_NSS_PIN_SOURCE
|
||||
RCC_AHBPeriphClockCmd(SPI2_NSS_PERIPHERAL, ENABLE);
|
||||
|
||||
GPIO_PinAFConfig(SPI2_GPIO, SPI2_NSS_PIN_SOURCE, GPIO_AF_5);
|
||||
#endif
|
||||
|
||||
|
@ -193,14 +208,13 @@ void initSpi2(void)
|
|||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||
|
||||
GPIO_Init(SPI2_GPIO, &GPIO_InitStructure);
|
||||
GPIO_Init(SPI2_NSS_GPIO, &GPIO_InitStructure);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef STM32F10X
|
||||
gpio_config_t gpio;
|
||||
|
||||
// MOSI + SCK as output
|
||||
gpio.mode = Mode_AF_PP;
|
||||
gpio.pin = SPI2_SCK_PIN | SPI2_MOSI_PIN;
|
||||
|
@ -210,45 +224,135 @@ void initSpi2(void)
|
|||
gpio.pin = SPI2_MISO_PIN;
|
||||
gpio.mode = Mode_IN_FLOATING;
|
||||
gpioInit(SPI2_GPIO, &gpio);
|
||||
|
||||
#ifdef SPI2_NSS_PIN
|
||||
// NSS as gpio slave select
|
||||
gpio.pin = SPI2_NSS_PIN;
|
||||
gpio.mode = Mode_Out_PP;
|
||||
gpioInit(SPI2_GPIO, &gpio);
|
||||
gpioInit(SPI2_NSS_GPIO, &gpio);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Init SPI2 hardware
|
||||
SPI_I2S_DeInit(SPI2);
|
||||
|
||||
spi.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
|
||||
spi.SPI_Mode = SPI_Mode_Master;
|
||||
spi.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
|
||||
spi.SPI_DataSize = SPI_DataSize_8b;
|
||||
spi.SPI_CPOL = SPI_CPOL_High;
|
||||
spi.SPI_CPHA = SPI_CPHA_2Edge;
|
||||
spi.SPI_NSS = SPI_NSS_Soft;
|
||||
spi.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8;
|
||||
spi.SPI_FirstBit = SPI_FirstBit_MSB;
|
||||
spi.SPI_CRCPolynomial = 7;
|
||||
spi.SPI_CPOL = SPI_CPOL_High;
|
||||
spi.SPI_CPHA = SPI_CPHA_2Edge;
|
||||
spi.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8;
|
||||
|
||||
#ifdef STM32F303xC
|
||||
// Configure for 8-bit reads.
|
||||
SPI_RxFIFOThresholdConfig(SPI2, SPI_RxFIFOThreshold_QF);
|
||||
#endif
|
||||
|
||||
SPI_Init(SPI2, &spi);
|
||||
SPI_Cmd(SPI2, ENABLE);
|
||||
|
||||
#ifdef SPI2_NSS_PIN
|
||||
// Drive NSS high to disable connected SPI device.
|
||||
GPIO_SetBits(SPI2_GPIO, SPI2_NSS_PIN);
|
||||
GPIO_SetBits(SPI2_NSS_GPIO, SPI2_NSS_PIN);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(USE_SPI_DEVICE_3) && defined(STM32F303xC)
|
||||
|
||||
#ifndef SPI3_GPIO
|
||||
#define SPI3_NSS_GPIO GPIOA
|
||||
#define SPI3_NSS_PERIPHERAL RCC_AHBPeriph_GPIOA
|
||||
#define SPI3_NSS_PIN GPIO_Pin_15
|
||||
#define SPI3_NSS_PIN_SOURCE GPIO_PinSource15
|
||||
#define SPI3_GPIO GPIOB
|
||||
#define SPI3_GPIO_PERIPHERAL RCC_AHBPeriph_GPIOB
|
||||
#define SPI3_SCK_PIN GPIO_Pin_3
|
||||
#define SPI3_SCK_PIN_SOURCE GPIO_PinSource3
|
||||
#define SPI3_MISO_PIN GPIO_Pin_4
|
||||
#define SPI3_MISO_PIN_SOURCE GPIO_PinSource4
|
||||
#define SPI3_MOSI_PIN GPIO_Pin_5
|
||||
#define SPI3_MOSI_PIN_SOURCE GPIO_PinSource5
|
||||
#endif
|
||||
|
||||
void initSpi3(void)
|
||||
{
|
||||
// Specific to the STM32F303 (AF6)
|
||||
// SPI3 Driver
|
||||
// PA15 38 SPI3_NSS
|
||||
// PB3 39 SPI3_SCK
|
||||
// PB4 40 SPI3_MISO
|
||||
// PB5 41 SPI3_MOSI
|
||||
|
||||
SPI_InitTypeDef spi;
|
||||
|
||||
// Enable SPI3 clock
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI3, ENABLE);
|
||||
RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI3, ENABLE);
|
||||
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
|
||||
RCC_AHBPeriphClockCmd(SPI3_GPIO_PERIPHERAL, ENABLE);
|
||||
|
||||
GPIO_PinAFConfig(SPI3_GPIO, SPI3_SCK_PIN_SOURCE, GPIO_AF_6);
|
||||
GPIO_PinAFConfig(SPI3_GPIO, SPI3_MISO_PIN_SOURCE, GPIO_AF_6);
|
||||
GPIO_PinAFConfig(SPI3_GPIO, SPI3_MOSI_PIN_SOURCE, GPIO_AF_6);
|
||||
|
||||
#ifdef SPI2_NSS_PIN_SOURCE
|
||||
RCC_AHBPeriphClockCmd(SPI3_NSS_PERIPHERAL, ENABLE);
|
||||
|
||||
GPIO_PinAFConfig(SPI3_NSS_GPIO, SPI3_NSS_PIN_SOURCE, GPIO_AF_6);
|
||||
#endif
|
||||
|
||||
// Init pins
|
||||
GPIO_InitStructure.GPIO_Pin = SPI3_SCK_PIN | SPI3_MISO_PIN | SPI3_MOSI_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||
GPIO_Init(SPI3_GPIO, &GPIO_InitStructure);
|
||||
|
||||
#ifdef SPI3_NSS_PIN
|
||||
GPIO_InitStructure.GPIO_Pin = SPI3_NSS_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||
|
||||
GPIO_Init(SPI3_NSS_GPIO, &GPIO_InitStructure);
|
||||
#endif
|
||||
|
||||
// Init SPI hardware
|
||||
SPI_I2S_DeInit(SPI3);
|
||||
|
||||
spi.SPI_Mode = SPI_Mode_Master;
|
||||
spi.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
|
||||
spi.SPI_DataSize = SPI_DataSize_8b;
|
||||
spi.SPI_NSS = SPI_NSS_Soft;
|
||||
spi.SPI_FirstBit = SPI_FirstBit_MSB;
|
||||
spi.SPI_CRCPolynomial = 7;
|
||||
spi.SPI_CPOL = SPI_CPOL_High;
|
||||
spi.SPI_CPHA = SPI_CPHA_2Edge;
|
||||
spi.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8;
|
||||
|
||||
// Configure for 8-bit reads.
|
||||
SPI_RxFIFOThresholdConfig(SPI3, SPI_RxFIFOThreshold_QF);
|
||||
|
||||
SPI_Init(SPI3, &spi);
|
||||
SPI_Cmd(SPI3, ENABLE);
|
||||
|
||||
#ifdef SPI3_NSS_PIN
|
||||
// Drive NSS high to disable connected SPI device.
|
||||
GPIO_SetBits(SPI3_NSS_GPIO, SPI3_NSS_PIN);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
bool spiInit(SPI_TypeDef *instance)
|
||||
{
|
||||
#if (!(defined(USE_SPI_DEVICE_1) && defined(USE_SPI_DEVICE_2)))
|
||||
#if (!(defined(USE_SPI_DEVICE_1) && defined(USE_SPI_DEVICE_2) && defined(USE_SPI_DEVICE_3)))
|
||||
UNUSED(instance);
|
||||
#endif
|
||||
|
||||
|
@ -263,6 +367,12 @@ bool spiInit(SPI_TypeDef *instance)
|
|||
initSpi2();
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
#if defined(USE_SPI_DEVICE_3) && defined(STM32F303xC)
|
||||
if (instance == SPI3) {
|
||||
initSpi3();
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
@ -271,15 +381,16 @@ uint32_t spiTimeoutUserCallback(SPI_TypeDef *instance)
|
|||
{
|
||||
if (instance == SPI1) {
|
||||
spi1ErrorCount++;
|
||||
return spi1ErrorCount;
|
||||
} else if (instance == SPI2) {
|
||||
spi2ErrorCount++;
|
||||
}
|
||||
return spi2ErrorCount;
|
||||
#ifdef STM32F303xC
|
||||
else {
|
||||
} else if (instance == SPI3) {
|
||||
spi3ErrorCount++;
|
||||
return spi3ErrorCount;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -412,6 +523,10 @@ uint16_t spiGetErrorCounter(SPI_TypeDef *instance)
|
|||
return spi1ErrorCount;
|
||||
} else if (instance == SPI2) {
|
||||
return spi2ErrorCount;
|
||||
#ifdef STM32F303xC
|
||||
} else if (instance == SPI3) {
|
||||
return spi3ErrorCount;
|
||||
#endif
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -422,6 +537,10 @@ void spiResetErrorCounter(SPI_TypeDef *instance)
|
|||
spi1ErrorCount = 0;
|
||||
} else if (instance == SPI2) {
|
||||
spi2ErrorCount = 0;
|
||||
#ifdef STM32F303xC
|
||||
} else if (instance == SPI3) {
|
||||
spi3ErrorCount = 0;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue