mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-26 01:35:41 +03:00
STM32F3: Discovery target fixes
This commit is contained in:
parent
9ad4f169ea
commit
aa4c078593
2 changed files with 22 additions and 30 deletions
|
@ -25,7 +25,7 @@
|
||||||
#include "common/maths.h"
|
#include "common/maths.h"
|
||||||
|
|
||||||
#include "system.h"
|
#include "system.h"
|
||||||
#include "gpio.h"
|
#include "io.h"
|
||||||
#include "bus_spi.h"
|
#include "bus_spi.h"
|
||||||
|
|
||||||
#include "sensor.h"
|
#include "sensor.h"
|
||||||
|
@ -66,22 +66,20 @@
|
||||||
|
|
||||||
#define BOOT ((uint8_t)0x80)
|
#define BOOT ((uint8_t)0x80)
|
||||||
|
|
||||||
|
#define ENABLE_L3GD20 IOLo(mpul3gd20CsPin)
|
||||||
|
#define DISABLE_L3GD20 IOHi(mpul3gd20CsPin)
|
||||||
|
|
||||||
|
static IO_t mpul3gd20CsPin = IO_NONE;
|
||||||
|
|
||||||
static void l3gd20SpiInit(SPI_TypeDef *SPIx)
|
static void l3gd20SpiInit(SPI_TypeDef *SPIx)
|
||||||
{
|
{
|
||||||
UNUSED(SPIx); // FIXME
|
UNUSED(SPIx); // FIXME
|
||||||
GPIO_InitTypeDef GPIO_InitStructure;
|
|
||||||
|
|
||||||
RCC_AHBPeriphClockCmd(L3GD20_CS_GPIO_CLK_PERIPHERAL, ENABLE);
|
mpul3gd20CsPin = IOGetByTag(IO_TAG(L3GD20_CS_PIN));
|
||||||
|
IOInit(mpul3gd20CsPin, OWNER_SYSTEM, RESOURCE_SPI);
|
||||||
|
IOConfigGPIO(mpul3gd20CsPin, SPI_IO_CS_CFG);
|
||||||
|
|
||||||
GPIO_InitStructure.GPIO_Pin = L3GD20_CS_PIN;
|
DISABLE_L3GD20;
|
||||||
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(L3GD20_CS_GPIO, &GPIO_InitStructure);
|
|
||||||
|
|
||||||
GPIO_SetBits(L3GD20_CS_GPIO, L3GD20_CS_PIN);
|
|
||||||
|
|
||||||
spiSetDivisor(L3GD20_SPI, SPI_9MHZ_CLOCK_DIVIDER);
|
spiSetDivisor(L3GD20_SPI, SPI_9MHZ_CLOCK_DIVIDER);
|
||||||
}
|
}
|
||||||
|
@ -92,32 +90,32 @@ void l3gd20GyroInit(uint8_t lpf)
|
||||||
|
|
||||||
l3gd20SpiInit(L3GD20_SPI);
|
l3gd20SpiInit(L3GD20_SPI);
|
||||||
|
|
||||||
GPIO_ResetBits(L3GD20_CS_GPIO, L3GD20_CS_PIN);
|
ENABLE_L3GD20;
|
||||||
|
|
||||||
spiTransferByte(L3GD20_SPI, CTRL_REG5_ADDR);
|
spiTransferByte(L3GD20_SPI, CTRL_REG5_ADDR);
|
||||||
spiTransferByte(L3GD20_SPI, BOOT);
|
spiTransferByte(L3GD20_SPI, BOOT);
|
||||||
|
|
||||||
GPIO_SetBits(L3GD20_CS_GPIO, L3GD20_CS_PIN);
|
DISABLE_L3GD20;
|
||||||
|
|
||||||
delayMicroseconds(100);
|
delayMicroseconds(100);
|
||||||
|
|
||||||
GPIO_ResetBits(L3GD20_CS_GPIO, L3GD20_CS_PIN);
|
ENABLE_L3GD20;
|
||||||
|
|
||||||
spiTransferByte(L3GD20_SPI, CTRL_REG1_ADDR);
|
spiTransferByte(L3GD20_SPI, CTRL_REG1_ADDR);
|
||||||
|
|
||||||
spiTransferByte(L3GD20_SPI, MODE_ACTIVE | OUTPUT_DATARATE_3 | AXES_ENABLE | BANDWIDTH_3);
|
spiTransferByte(L3GD20_SPI, MODE_ACTIVE | OUTPUT_DATARATE_3 | AXES_ENABLE | BANDWIDTH_3);
|
||||||
//spiTransferByte(L3GD20_SPI, MODE_ACTIVE | OUTPUT_DATARATE_4 | AXES_ENABLE | BANDWIDTH_4);
|
//spiTransferByte(L3GD20_SPI, MODE_ACTIVE | OUTPUT_DATARATE_4 | AXES_ENABLE | BANDWIDTH_4);
|
||||||
|
|
||||||
GPIO_SetBits(L3GD20_CS_GPIO, L3GD20_CS_PIN);
|
DISABLE_L3GD20;
|
||||||
|
|
||||||
delayMicroseconds(1);
|
delayMicroseconds(1);
|
||||||
|
|
||||||
GPIO_ResetBits(L3GD20_CS_GPIO, L3GD20_CS_PIN);
|
ENABLE_L3GD20;
|
||||||
|
|
||||||
spiTransferByte(L3GD20_SPI, CTRL_REG4_ADDR);
|
spiTransferByte(L3GD20_SPI, CTRL_REG4_ADDR);
|
||||||
spiTransferByte(L3GD20_SPI, BLOCK_DATA_UPDATE_CONTINUOUS | BLE_MSB | FULLSCALE_2000);
|
spiTransferByte(L3GD20_SPI, BLOCK_DATA_UPDATE_CONTINUOUS | BLE_MSB | FULLSCALE_2000);
|
||||||
|
|
||||||
GPIO_SetBits(L3GD20_CS_GPIO, L3GD20_CS_PIN);
|
DISABLE_L3GD20;
|
||||||
|
|
||||||
delay(100);
|
delay(100);
|
||||||
}
|
}
|
||||||
|
@ -126,7 +124,7 @@ static bool l3gd20GyroRead(int16_t *gyroADC)
|
||||||
{
|
{
|
||||||
uint8_t buf[6];
|
uint8_t buf[6];
|
||||||
|
|
||||||
GPIO_ResetBits(L3GD20_CS_GPIO, L3GD20_CS_PIN);
|
ENABLE_L3GD20;
|
||||||
spiTransferByte(L3GD20_SPI, OUT_X_L_ADDR | READ_CMD | MULTIPLEBYTE_CMD);
|
spiTransferByte(L3GD20_SPI, OUT_X_L_ADDR | READ_CMD | MULTIPLEBYTE_CMD);
|
||||||
|
|
||||||
uint8_t index;
|
uint8_t index;
|
||||||
|
@ -134,7 +132,7 @@ static bool l3gd20GyroRead(int16_t *gyroADC)
|
||||||
buf[index] = spiTransferByte(L3GD20_SPI, DUMMY_BYTE);
|
buf[index] = spiTransferByte(L3GD20_SPI, DUMMY_BYTE);
|
||||||
}
|
}
|
||||||
|
|
||||||
GPIO_SetBits(L3GD20_CS_GPIO, L3GD20_CS_PIN);
|
DISABLE_L3GD20;
|
||||||
|
|
||||||
gyroADC[0] = (int16_t)((buf[0] << 8) | buf[1]);
|
gyroADC[0] = (int16_t)((buf[0] << 8) | buf[1]);
|
||||||
gyroADC[1] = (int16_t)((buf[2] << 8) | buf[3]);
|
gyroADC[1] = (int16_t)((buf[2] << 8) | buf[3]);
|
||||||
|
|
|
@ -31,16 +31,10 @@
|
||||||
#define USE_SPI_DEVICE_1
|
#define USE_SPI_DEVICE_1
|
||||||
#define USE_SPI_DEVICE_2
|
#define USE_SPI_DEVICE_2
|
||||||
|
|
||||||
#define SPI2_GPIO GPIOB
|
#define SPI2_NSS_PIN PB12
|
||||||
#define SPI2_GPIO_PERIPHERAL RCC_AHBPeriph_GPIOB
|
#define SPI2_SCK_PIN PB13
|
||||||
#define SPI2_NSS_PIN Pin_12
|
#define SPI2_MISO_PIN PB14
|
||||||
#define SPI2_NSS_PIN_SOURCE GPIO_PinSource12
|
#define SPI2_MOSI_PIN PB15
|
||||||
#define SPI2_SCK_PIN Pin_13
|
|
||||||
#define SPI2_SCK_PIN_SOURCE GPIO_PinSource13
|
|
||||||
#define SPI2_MISO_PIN Pin_14
|
|
||||||
#define SPI2_MISO_PIN_SOURCE GPIO_PinSource14
|
|
||||||
#define SPI2_MOSI_PIN Pin_15
|
|
||||||
#define SPI2_MOSI_PIN_SOURCE GPIO_PinSource15
|
|
||||||
|
|
||||||
#define USE_SD_CARD
|
#define USE_SD_CARD
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue