From 4a7d81ed018da6c961b6fdcb942e5ca5a5843ab2 Mon Sep 17 00:00:00 2001 From: Alessio Morale Date: Mon, 18 May 2015 21:28:26 +0200 Subject: [PATCH] REVONANO - Fix gyro spi config and include MPU9250 support --- .../targets/boards/revonano/board_hw_defs.c | 6 +- .../targets/boards/revonano/firmware/Makefile | 2 +- .../boards/revonano/firmware/UAVObjects.inc | 2 +- .../revonano/firmware/inc/pios_config.h | 3 + .../boards/revonano/firmware/pios_board.c | 64 ++++++++++--------- 5 files changed, 42 insertions(+), 35 deletions(-) diff --git a/flight/targets/boards/revonano/board_hw_defs.c b/flight/targets/boards/revonano/board_hw_defs.c index 5a3c54e56..ef21b6019 100644 --- a/flight/targets/boards/revonano/board_hw_defs.c +++ b/flight/targets/boards/revonano/board_hw_defs.c @@ -136,7 +136,7 @@ static const struct pios_spi_cfg pios_spi_gyro_cfg = { .irq = { .flags = (DMA_IT_TCIF0 | DMA_IT_TEIF0 | DMA_IT_HTIF0), .init = { - .NVIC_IRQChannel = DMA1_Stream3_IRQn, + .NVIC_IRQChannel = DMA1_Stream4_IRQn, .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH, .NVIC_IRQChannelSubPriority = 0, .NVIC_IRQChannelCmd = ENABLE, @@ -147,7 +147,7 @@ static const struct pios_spi_cfg pios_spi_gyro_cfg = { .channel = DMA1_Stream3, .init = { .DMA_Channel = DMA_Channel_0, - .DMA_PeripheralBaseAddr = (uint32_t)&(SPI1->DR), + .DMA_PeripheralBaseAddr = (uint32_t)&(SPI2->DR), .DMA_DIR = DMA_DIR_PeripheralToMemory, .DMA_PeripheralInc = DMA_PeripheralInc_Disable, .DMA_MemoryInc = DMA_MemoryInc_Enable, @@ -165,7 +165,7 @@ static const struct pios_spi_cfg pios_spi_gyro_cfg = { .channel = DMA1_Stream4, .init = { .DMA_Channel = DMA_Channel_0, - .DMA_PeripheralBaseAddr = (uint32_t)&(SPI1->DR), + .DMA_PeripheralBaseAddr = (uint32_t)&(SPI2->DR), .DMA_DIR = DMA_DIR_MemoryToPeripheral, .DMA_PeripheralInc = DMA_PeripheralInc_Disable, .DMA_MemoryInc = DMA_MemoryInc_Enable, diff --git a/flight/targets/boards/revonano/firmware/Makefile b/flight/targets/boards/revonano/firmware/Makefile index 32181d95c..a37e9021d 100644 --- a/flight/targets/boards/revonano/firmware/Makefile +++ b/flight/targets/boards/revonano/firmware/Makefile @@ -27,7 +27,7 @@ include $(ROOT_DIR)/make/firmware-defs.mk USE_DSP_LIB ?= NO # List of mandatory modules to include -#MODULES += Sensors +MODULES += Sensors #MODULES += StateEstimation MODULES += Altitude/revolution #MODULES += Airspeed diff --git a/flight/targets/boards/revonano/firmware/UAVObjects.inc b/flight/targets/boards/revonano/firmware/UAVObjects.inc index 60ac23651..cd9a3672c 100644 --- a/flight/targets/boards/revonano/firmware/UAVObjects.inc +++ b/flight/targets/boards/revonano/firmware/UAVObjects.inc @@ -114,7 +114,7 @@ UAVOBJSRCFILENAMES += waypoint UAVOBJSRCFILENAMES += waypointactive UAVOBJSRCFILENAMES += poilocation UAVOBJSRCFILENAMES += poilearnsettings -UAVOBJSRCFILENAMES += mpu6000settings +UAVOBJSRCFILENAMES += mpu9250settings UAVOBJSRCFILENAMES += txpidsettings UAVOBJSRCFILENAMES += takeofflocation UAVOBJSRCFILENAMES += perfcounter diff --git a/flight/targets/boards/revonano/firmware/inc/pios_config.h b/flight/targets/boards/revonano/firmware/inc/pios_config.h index 8f7e418e5..867313882 100644 --- a/flight/targets/boards/revonano/firmware/inc/pios_config.h +++ b/flight/targets/boards/revonano/firmware/inc/pios_config.h @@ -91,6 +91,9 @@ // #define PIOS_INCLUDE_MPXV // #define PIOS_INCLUDE_ETASV3 // #define PIOS_INCLUDE_MS4525DO +#define PIOS_INCLUDE_MPU9250 +#define PIOS_MPU9250_ACCEL +#define PIOS_MPU9250_MAG #define PIOS_SENSOR_RATE 500.0f diff --git a/flight/targets/boards/revonano/firmware/pios_board.c b/flight/targets/boards/revonano/firmware/pios_board.c index 9deb74dcf..3b0703751 100644 --- a/flight/targets/boards/revonano/firmware/pios_board.c +++ b/flight/targets/boards/revonano/firmware/pios_board.c @@ -103,18 +103,18 @@ static const struct pios_ms5611_cfg pios_ms5611_cfg = { #endif /* PIOS_INCLUDE_MS5611 */ /** - * Configuration for the MPU6000 chip + * Configuration for the MPU9250 chip */ -#if defined(PIOS_INCLUDE_MPU6000) -#include "pios_mpu6000.h" -#include "pios_mpu6000_config.h" -static const struct pios_exti_cfg pios_exti_mpu6000_cfg __exti_config = { - .vector = PIOS_MPU6000_IRQHandler, - .line = EXTI_Line4, +#if defined(PIOS_INCLUDE_MPU9250) +#include "pios_mpu9250.h" +#include "pios_mpu9250_config.h" +static const struct pios_exti_cfg pios_exti_mpu9250_cfg __exti_config = { + .vector = PIOS_MPU9250_IRQHandler, + .line = EXTI_Line15, .pin = { - .gpio = GPIOC, + .gpio = GPIOA, .init = { - .GPIO_Pin = GPIO_Pin_4, + .GPIO_Pin = GPIO_Pin_15, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_Mode = GPIO_Mode_IN, .GPIO_OType = GPIO_OType_OD, @@ -123,7 +123,7 @@ static const struct pios_exti_cfg pios_exti_mpu6000_cfg __exti_config = { }, .irq = { .init = { - .NVIC_IRQChannel = EXTI4_IRQn, + .NVIC_IRQChannel = EXTI15_10_IRQn, .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH, .NVIC_IRQChannelSubPriority = 0, .NVIC_IRQChannelCmd = ENABLE, @@ -131,7 +131,7 @@ static const struct pios_exti_cfg pios_exti_mpu6000_cfg __exti_config = { }, .exti = { .init = { - .EXTI_Line = EXTI_Line4, // matches above GPIO pin + .EXTI_Line = EXTI_Line15, // matches above GPIO pin .EXTI_Mode = EXTI_Mode_Interrupt, .EXTI_Trigger = EXTI_Trigger_Rising, .EXTI_LineCmd = ENABLE, @@ -139,23 +139,27 @@ static const struct pios_exti_cfg pios_exti_mpu6000_cfg __exti_config = { }, }; -static const struct pios_mpu6000_cfg pios_mpu6000_cfg = { - .exti_cfg = &pios_exti_mpu6000_cfg, - .Fifo_store = PIOS_MPU6000_FIFO_TEMP_OUT | PIOS_MPU6000_FIFO_GYRO_X_OUT | PIOS_MPU6000_FIFO_GYRO_Y_OUT | PIOS_MPU6000_FIFO_GYRO_Z_OUT, - // Clock at 8 khz, downsampled by 12 for 666Hz - .Smpl_rate_div_no_dlp = 11, - // with dlp on output rate is 500Hz - .Smpl_rate_div_dlp = 1, - .interrupt_cfg = PIOS_MPU6000_INT_CLR_ANYRD, - .interrupt_en = PIOS_MPU6000_INTEN_DATA_RDY, - .User_ctl = PIOS_MPU6000_USERCTL_FIFO_EN | PIOS_MPU6000_USERCTL_DIS_I2C, - .Pwr_mgmt_clk = PIOS_MPU6000_PWRMGMT_PLL_X_CLK, - .accel_range = PIOS_MPU6000_ACCEL_8G, - .gyro_range = PIOS_MPU6000_SCALE_2000_DEG, - .filter = PIOS_MPU6000_LOWPASS_256_HZ, - .orientation = PIOS_MPU6000_TOP_180DEG +static const struct pios_mpu9250_cfg pios_mpu9250_cfg = { + .exti_cfg = &pios_exti_mpu9250_cfg, + .Fifo_store = PIOS_MPU9250_FIFO_TEMP_OUT | PIOS_MPU9250_FIFO_GYRO_X_OUT | PIOS_MPU9250_FIFO_GYRO_Y_OUT | PIOS_MPU9250_FIFO_GYRO_Z_OUT, + // Clock at 8 khz + .Smpl_rate_div_no_dlp = 0, + // with dlp on output rate is 1000Hz + .Smpl_rate_div_dlp = 0, + .interrupt_cfg = PIOS_MPU9250_INT_CLR_ANYRD | PIOS_MPU9250_INT_LATCH_EN, + .interrupt_en = PIOS_MPU9250_INTEN_DATA_RDY, + .User_ctl = PIOS_MPU9250_USERCTL_DIS_I2C | PIOS_MPU9250_USERCTL_I2C_MST_EN, + .Pwr_mgmt_clk = PIOS_MPU9250_PWRMGMT_PLL_X_CLK, + .accel_range = PIOS_MPU9250_ACCEL_8G, + .gyro_range = PIOS_MPU9250_SCALE_2000_DEG, + .filter = PIOS_MPU9250_LOWPASS_256_HZ, + .orientation = PIOS_MPU9250_TOP_180DEG, + .fast_prescaler = PIOS_SPI_PRESCALER_64, + .std_prescaler = PIOS_SPI_PRESCALER_64, + .max_downsample = 16, }; -#endif /* PIOS_INCLUDE_MPU6000 */ +#endif /* PIOS_INCLUDE_MPU9250 */ + /* One slot per selectable receiver group. * eg. PWM, PPM, GCS, SPEKTRUM1, SPEKTRUM2, SBUS @@ -737,9 +741,9 @@ void PIOS_Board_Init(void) PIOS_MS5611_Init(&pios_ms5611_cfg, pios_i2c_pressure_adapter_id); #endif -#if defined(PIOS_INCLUDE_MPU6000) - PIOS_MPU6000_Init(pios_spi_gyro_id, 0, &pios_mpu6000_cfg); - PIOS_MPU6000_CONFIG_Configure(); +#if defined(PIOS_INCLUDE_MPU9250) + PIOS_MPU9250_Init(pios_spi_gyro_id, 0, &pios_mpu9250_cfg); + PIOS_MPU9250_CONFIG_Configure(); #endif #ifdef PIOS_INCLUDE_WS2811