From ccfecd4ad2d16fc78b87428877170d200bb82c3a Mon Sep 17 00:00:00 2001 From: Phillip Kocmoud Date: Tue, 14 Feb 2017 10:37:04 -0600 Subject: [PATCH] Add support for the ICM-20602 to the Pixracer FMUv4 (#6577) The current ICM-20608 is nearing EOL. I have tested on both ICM-20608 and ICM-20602 based Pixracers. --- ROMFS/px4fmu_common/init.d/rc.sensors | 5 ++++ src/drivers/boards/px4fmu-v4/board_config.h | 17 ++++++------- src/drivers/boards/px4fmu-v4/px4fmu_spi.c | 27 ++++++++++++--------- 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/ROMFS/px4fmu_common/init.d/rc.sensors b/ROMFS/px4fmu_common/init.d/rc.sensors index 0254cf8b8e..10e1c54e76 100644 --- a/ROMFS/px4fmu_common/init.d/rc.sensors +++ b/ROMFS/px4fmu_common/init.d/rc.sensors @@ -193,6 +193,11 @@ then then fi + # Internal SPI bus ICM-20602-G is rotated 90 deg yaw + if mpu6000 -R 2 -T 20602 start + then + fi + # Start either MPU9250 or BMI160. They are both connected to the same SPI bus and use the same # chip select pin. There are different boards with either one of them and the WHO_AM_I register # will prevent the incorrect driver from a successful initialization. diff --git a/src/drivers/boards/px4fmu-v4/board_config.h b/src/drivers/boards/px4fmu-v4/board_config.h index 80490b5565..f86d904aea 100644 --- a/src/drivers/boards/px4fmu-v4/board_config.h +++ b/src/drivers/boards/px4fmu-v4/board_config.h @@ -78,11 +78,11 @@ #define GPIO_SPI_CS_HMC5983 (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_2MHz|GPIO_OUTPUT_SET|GPIO_PORTE|GPIO_PIN15) #define GPIO_SPI_CS_LIS3MDL (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_2MHz|GPIO_OUTPUT_SET|GPIO_PORTE|GPIO_PIN15) #define GPIO_SPI_CS_MS5611 (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_2MHz|GPIO_OUTPUT_SET|GPIO_PORTD|GPIO_PIN7) -#define GPIO_SPI_CS_ICM_20608_G (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_2MHz|GPIO_OUTPUT_SET|GPIO_PORTC|GPIO_PIN15) +#define GPIO_SPI_CS_ICM_2060X (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_2MHz|GPIO_OUTPUT_SET|GPIO_PORTC|GPIO_PIN15) /* The BMI160 sensor replaces the MPU9250 on some boards. Only one is actually present and connected * to the second GPIO pin on port C. The wrong driver will fail during start becaus of an incorrect WHO_AM_I register.*/ -#define GPIO_SPI_CS_BMI160 (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_2MHz|GPIO_OUTPUT_SET|GPIO_PORTC|GPIO_PIN2) +#define GPIO_SPI_CS_BMI160 (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_2MHz|GPIO_OUTPUT_SET|GPIO_PORTC|GPIO_PIN2) #define GPIO_SPI_CS_FRAM (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_2MHz|GPIO_OUTPUT_SET|GPIO_PORTD|GPIO_PIN10) @@ -90,8 +90,7 @@ #define GPIO_DRDY_MPU9250 (GPIO_INPUT|GPIO_FLOAT|GPIO_EXTI|GPIO_PORTD|GPIO_PIN15) #define GPIO_DRDY_HMC5983 (GPIO_INPUT|GPIO_FLOAT|GPIO_EXTI|GPIO_PORTE|GPIO_PIN12) -#define GPIO_DRDY_ICM_20608_G (GPIO_INPUT|GPIO_FLOAT|GPIO_EXTI|GPIO_PORTC|GPIO_PIN14) - +#define GPIO_DRDY_ICM_2060X (GPIO_INPUT|GPIO_FLOAT|GPIO_EXTI|GPIO_PORTC|GPIO_PIN14) /* * Define the ability to shut off off the sensor signals @@ -104,13 +103,12 @@ #define GPIO_SPI_CS_OFF_HMC5983 _PIN_OFF(GPIO_SPI_CS_HMC5983) #define GPIO_SPI_CS_OFF_LIS3MDL _PIN_OFF(GPIO_SPI_CS_LIS3MDL) #define GPIO_SPI_CS_OFF_MS5611 _PIN_OFF(GPIO_SPI_CS_MS5611) -#define GPIO_SPI_CS_OFF_ICM_20608_G _PIN_OFF(GPIO_SPI_CS_ICM_20608_G) -#define GPIO_SPI_CS_OFF_BMI160 _PIN_OFF(GPIO_SPI_CS_BMI160) +#define GPIO_SPI_CS_OFF_ICM_2060X _PIN_OFF(GPIO_SPI_CS_ICM_2060X) +#define GPIO_SPI_CS_OFF_BMI160 _PIN_OFF(GPIO_SPI_CS_BMI160) #define GPIO_DRDY_OFF_MPU9250 _PIN_OFF(GPIO_DRDY_MPU9250) #define GPIO_DRDY_OFF_HMC5983 _PIN_OFF(GPIO_DRDY_HMC5983) -#define GPIO_DRDY_OFF_ICM_20608_G _PIN_OFF(GPIO_DRDY_ICM_20608_G) - +#define GPIO_DRDY_OFF_ICM_2060X _PIN_OFF(GPIO_DRDY_ICM_2060X) /* SPI1 off */ #define GPIO_SPI1_SCK_OFF _PIN_OFF(GPIO_SPI1_SCK) @@ -130,7 +128,8 @@ #define PX4_SPIDEV_LIS 7 #define PX4_SPIDEV_BMI 8 #define PX4_SPIDEV_BMA 9 -#define PX4_SPIDEV_ICM_20608 10 +#define PX4_SPIDEV_ICM_20608 10 +#define PX4_SPIDEV_ICM_20602 11 /* onboard MS5611 and FRAM are both on bus SPI2 * spi_dev_e:SPIDEV_FLASH has the value 2 and is used in the NuttX ramtron driver diff --git a/src/drivers/boards/px4fmu-v4/px4fmu_spi.c b/src/drivers/boards/px4fmu-v4/px4fmu_spi.c index b67ed1a712..677a2a42e1 100644 --- a/src/drivers/boards/px4fmu-v4/px4fmu_spi.c +++ b/src/drivers/boards/px4fmu-v4/px4fmu_spi.c @@ -75,12 +75,12 @@ __EXPORT void stm32_spiinitialize(void) px4_arch_configgpio(GPIO_SPI_CS_MPU9250); px4_arch_configgpio(GPIO_SPI_CS_HMC5983); px4_arch_configgpio(GPIO_SPI_CS_MS5611); - px4_arch_configgpio(GPIO_SPI_CS_ICM_20608_G); + px4_arch_configgpio(GPIO_SPI_CS_ICM_2060X); px4_arch_configgpio(GPIO_SPI_CS_BMI160); px4_arch_configgpio(GPIO_DRDY_MPU9250); px4_arch_configgpio(GPIO_DRDY_HMC5983); - px4_arch_configgpio(GPIO_DRDY_ICM_20608_G); + px4_arch_configgpio(GPIO_DRDY_ICM_2060X); #endif #ifdef CONFIG_STM32_SPI2 @@ -96,6 +96,9 @@ __EXPORT void stm32_spi1select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, switch (devid) { case PX4_SPIDEV_ICM: + /* intended fallthrough */ + case PX4_SPIDEV_ICM_20602: + /* intended fallthrough */ case PX4_SPIDEV_ICM_20608: /* Making sure the other peripherals are not selected */ @@ -103,7 +106,7 @@ __EXPORT void stm32_spi1select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, px4_arch_gpiowrite(GPIO_SPI_CS_MPU9250, 1); px4_arch_gpiowrite(GPIO_SPI_CS_HMC5983, 1); px4_arch_gpiowrite(GPIO_SPI_CS_MS5611, 1); - px4_arch_gpiowrite(GPIO_SPI_CS_ICM_20608_G, !selected); + px4_arch_gpiowrite(GPIO_SPI_CS_ICM_2060X, !selected); break; case PX4_SPIDEV_ACCEL_MAG: @@ -116,7 +119,7 @@ __EXPORT void stm32_spi1select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, px4_arch_gpiowrite(GPIO_SPI_CS_MPU9250, 1); px4_arch_gpiowrite(GPIO_SPI_CS_HMC5983, 1); px4_arch_gpiowrite(GPIO_SPI_CS_MS5611, !selected); - px4_arch_gpiowrite(GPIO_SPI_CS_ICM_20608_G, 1); + px4_arch_gpiowrite(GPIO_SPI_CS_ICM_2060X, 1); break; case PX4_SPIDEV_HMC: @@ -125,7 +128,7 @@ __EXPORT void stm32_spi1select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, px4_arch_gpiowrite(GPIO_SPI_CS_MPU9250, 1); px4_arch_gpiowrite(GPIO_SPI_CS_HMC5983, !selected); px4_arch_gpiowrite(GPIO_SPI_CS_MS5611, 1); - px4_arch_gpiowrite(GPIO_SPI_CS_ICM_20608_G, 1); + px4_arch_gpiowrite(GPIO_SPI_CS_ICM_2060X, 1); break; case PX4_SPIDEV_MPU: @@ -134,7 +137,7 @@ __EXPORT void stm32_spi1select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, px4_arch_gpiowrite(GPIO_SPI_CS_MPU9250, !selected); px4_arch_gpiowrite(GPIO_SPI_CS_HMC5983, 1); px4_arch_gpiowrite(GPIO_SPI_CS_MS5611, 1); - px4_arch_gpiowrite(GPIO_SPI_CS_ICM_20608_G, 1); + px4_arch_gpiowrite(GPIO_SPI_CS_ICM_2060X, 1); break; case PX4_SPIDEV_BMI: @@ -142,7 +145,7 @@ __EXPORT void stm32_spi1select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, px4_arch_gpiowrite(GPIO_SPI_CS_MPU9250, 1); px4_arch_gpiowrite(GPIO_SPI_CS_HMC5983, 1); px4_arch_gpiowrite(GPIO_SPI_CS_MS5611, 1); - px4_arch_gpiowrite(GPIO_SPI_CS_ICM_20608_G, 1); + px4_arch_gpiowrite(GPIO_SPI_CS_ICM_2060X, 1); px4_arch_gpiowrite(GPIO_SPI_CS_BMI160, !selected); break; @@ -193,13 +196,13 @@ __EXPORT void board_spi_reset(int ms) px4_arch_configgpio(GPIO_SPI_CS_OFF_MPU9250); px4_arch_configgpio(GPIO_SPI_CS_OFF_HMC5983); px4_arch_configgpio(GPIO_SPI_CS_OFF_MS5611); - px4_arch_configgpio(GPIO_SPI_CS_OFF_ICM_20608_G); + px4_arch_configgpio(GPIO_SPI_CS_OFF_ICM_2060X); px4_arch_configgpio(GPIO_SPI_CS_OFF_BMI160); px4_arch_gpiowrite(GPIO_SPI_CS_OFF_MPU9250, 0); px4_arch_gpiowrite(GPIO_SPI_CS_OFF_HMC5983, 0); px4_arch_gpiowrite(GPIO_SPI_CS_OFF_MS5611, 0); - px4_arch_gpiowrite(GPIO_SPI_CS_OFF_ICM_20608_G, 0); + px4_arch_gpiowrite(GPIO_SPI_CS_OFF_ICM_2060X, 0); px4_arch_gpiowrite(GPIO_SPI_CS_OFF_BMI160, 0); stm32_configgpio(GPIO_SPI1_SCK_OFF); @@ -212,11 +215,11 @@ __EXPORT void board_spi_reset(int ms) stm32_configgpio(GPIO_DRDY_OFF_MPU9250); stm32_configgpio(GPIO_DRDY_OFF_HMC5983); - stm32_configgpio(GPIO_DRDY_OFF_ICM_20608_G); + stm32_configgpio(GPIO_DRDY_OFF_ICM_2060X); stm32_gpiowrite(GPIO_DRDY_OFF_MPU9250, 0); stm32_gpiowrite(GPIO_DRDY_OFF_HMC5983, 0); - stm32_gpiowrite(GPIO_DRDY_OFF_ICM_20608_G, 0); + stm32_gpiowrite(GPIO_DRDY_OFF_ICM_2060X, 0); /* set the sensor rail off */ stm32_configgpio(GPIO_VDD_3V3_SENSORS_EN); @@ -239,7 +242,7 @@ __EXPORT void board_spi_reset(int ms) px4_arch_configgpio(GPIO_SPI_CS_MPU9250); px4_arch_configgpio(GPIO_SPI_CS_HMC5983); px4_arch_configgpio(GPIO_SPI_CS_MS5611); - px4_arch_configgpio(GPIO_SPI_CS_ICM_20608_G); + px4_arch_configgpio(GPIO_SPI_CS_ICM_2060X); px4_arch_configgpio(GPIO_SPI_CS_BMI160); stm32_configgpio(GPIO_SPI1_SCK);