boards: add new spi+i2c config

Chip-select and SPI initialization uses the new config, whereas the drivers
still use the existing defines.

The configuration in board_config.h can be removed after all drivers are
updated.
This commit is contained in:
Beat Küng
2020-02-18 17:14:10 +01:00
committed by Daniel Agar
parent 06712450a7
commit 1851665fab
142 changed files with 2607 additions and 5655 deletions
+3 -2
View File
@@ -33,10 +33,10 @@
add_library(drivers_board
can.c
i2c.c
i2c.cpp
init.c
led.c
spi.c
spi.cpp
timer_config.cpp
usb.c
manifest.c
@@ -44,6 +44,7 @@ add_library(drivers_board
target_link_libraries(drivers_board
PRIVATE
arch_spi
drivers__led # drv_led_start
nuttx_arch # sdio
nuttx_drivers # sdio
+16 -19
View File
@@ -60,6 +60,7 @@
#define HW_VER_FMUV2MINI_STATE 0xA /* PB12:PU:1 PB12:PD:0 PB4:PU:1 PB4PD:0 */
#define HW_VER_FMUV2X_STATE 0xB /* PB12:PU:1 PB12:PD:0 PB4:PU:1 PB4PD:1 */
#define HW_VER_TYPE_INIT {'V','2',0, 0}
#define BOARD_NUM_SPI_CFG_HW_VERSIONS 3
/****************************************************************************************************
* Definitions
@@ -87,12 +88,7 @@
#define GPIO_LED1 (GPIO_OUTPUT|GPIO_OPENDRAIN|GPIO_SPEED_50MHz|GPIO_OUTPUT_CLEAR|GPIO_PORTE|GPIO_PIN12)
#define BOARD_OVERLOAD_LED LED_AMBER
/*
* Define the ability to shut off off the sensor signals
* by changing the signals to inputs
*/
#define _PIN_OFF(def) (((def) & (GPIO_PORT_MASK | GPIO_PIN_MASK)) | (GPIO_INPUT|GPIO_PULLDOWN|GPIO_SPEED_50MHz))
#include <drivers/drv_sensor.h>
/* Due to inconsistent use of chip select and dry signal on
* different board that use this build. We are defining the GPIO
@@ -208,24 +204,27 @@
/* Use these to select a specific SPI device on SPI1 */
#define PX4_SPIDEV_GYRO PX4_MK_SPI_SEL(PX4_SPI_BUS_SENSORS, 1)
#define PX4_SPIDEV_ACCEL_MAG PX4_MK_SPI_SEL(PX4_SPI_BUS_SENSORS, 2)
#define PX4_SPIDEV_BARO PX4_MK_SPI_SEL(PX4_SPI_BUS_SENSORS, 3)
#define PX4_SPIDEV_MPU PX4_MK_SPI_SEL(PX4_SPI_BUS_SENSORS, 4)
#define PX4_SPIDEV_GYRO PX4_MK_SPI_SEL(0, DRV_GYR_DEVTYPE_L3GD20)
#define PX4_SPIDEV_ACCEL_MAG PX4_MK_SPI_SEL(0, DRV_ACC_DEVTYPE_LSM303D)
#define PX4_SPIDEV_BARO PX4_MK_SPI_SEL(0, DRV_BARO_DEVTYPE_MS5611)
#define PX4_SPIDEV_MPU PX4_MK_SPI_SEL(0, DRV_IMU_DEVTYPE_MPU6000)
/* FMUv3 SPI on external bus */
#define PX4_SPIDEV_EXT_GYRO PX4_MK_SPI_SEL(PX4_SPI_BUS_EXT, 1)
#define PX4_SPIDEV_EXT_ACCEL_MAG PX4_MK_SPI_SEL(PX4_SPI_BUS_EXT, 2)
#define PX4_SPIDEV_EXT_BARO PX4_MK_SPI_SEL(PX4_SPI_BUS_EXT, 3)
#define PX4_SPIDEV_EXT_MPU PX4_MK_SPI_SEL(PX4_SPI_BUS_EXT, 4)
#define PX4_SPIDEV_EXT_BMI PX4_MK_SPI_SEL(PX4_SPI_BUS_EXT, 5)
#define PX4_SPIDEV_EXT_GYRO PX4_MK_SPI_SEL(0, DRV_GYR_DEVTYPE_L3GD20)
#define PX4_SPIDEV_EXT_ACCEL_MAG PX4_MK_SPI_SEL(0, DRV_ACC_DEVTYPE_LSM303D)
#define PX4_SPIDEV_EXT_BARO PX4_MK_SPI_SEL(0, DRV_BARO_DEVTYPE_MS5611)
#define PX4_SPIDEV_EXT_MPU PX4_MK_SPI_SEL(0, DRV_IMU_DEVTYPE_MPU6000)
#define PX4_SPIDEV_EXT_BMI PX4_MK_SPI_SEL(0, DRV_GYR_DEVTYPE_BMI055)
/* I2C busses */
#define BOARD_OVERRIDE_I2C_BUS_EXTERNAL
#define PX4_I2C_BUS_EXPANSION 1
#define PX4_I2C_BUS_ONBOARD 2
#define PX4_I2C_BUS_LED PX4_I2C_BUS_ONBOARD
#define BOARD_SPI_BUS_MAX_BUS_ITEMS 3
/*----------------------------------------------------------*/
/* FMUv3 Cube SPI chip selects and DRDY */
/*----------------------------------------------------------*/
@@ -292,7 +291,7 @@
#define GPIO_SPI4_EXTERN_CS GPIO_SPI4_CS_PB1
/* PB1 is an External CS on V3 */
#define PX4_SPIDEV_HMC 5
#define PX4_SPIDEV_HMC PX4_MK_SPI_SEL(0, DRV_MAG_DEVTYPE_HMC5883)
/*----------------------------------------------------------*/
/* End FMUv3 Cube SPI chip selects and DRDY */
@@ -351,7 +350,7 @@
*/
#define GPIO_SPI1_EXTI_20608_DRDY_PC14 (GPIO_INPUT|GPIO_FLOAT|GPIO_EXTI|GPIO_PORTC|GPIO_PIN14)
#define PX4_SPIDEV_ICM_20608 6 /* ICM_20608 on PC15 */
#define PX4_SPIDEV_ICM_20608 PX4_MK_SPI_SEL(0, DRV_IMU_DEVTYPE_ICM20608)
@@ -379,7 +378,6 @@
#define GPIO_VDD_BRICK_VALID (GPIO_INPUT|GPIO_PULLUP|GPIO_PORTB|GPIO_PIN5)
#define GPIO_VDD_SERVO_VALID (GPIO_INPUT|GPIO_PULLUP|GPIO_PORTB|GPIO_PIN7)
#define GPIO_VDD_USB_VALID (GPIO_INPUT|GPIO_PULLUP|GPIO_PORTC|GPIO_PIN0)
#define GPIO_VDD_3V3_SENSORS_EN (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_2MHz|GPIO_OUTPUT_SET|GPIO_PORTE|GPIO_PIN3)
#define GPIO_VDD_5V_HIPOWER_OC (GPIO_INPUT|GPIO_PULLUP|GPIO_PORTE|GPIO_PIN10)
#define GPIO_VDD_5V_PERIPH_OC (GPIO_INPUT|GPIO_PULLUP|GPIO_PORTE|GPIO_PIN15)
@@ -463,7 +461,6 @@ extern void stm32_spiinitialize(void);
*
****************************************************************************************************/
void board_spi_reset(int ms);
extern void board_peripheral_reset(int ms);
/****************************************************************************************************
@@ -38,15 +38,23 @@
*/
#include "board_config.h"
#include <px4_platform_common/i2c.h>
#include <px4_arch/i2c_hw_description.h>
__EXPORT bool px4_i2c_bus_external(int bus)
constexpr px4_i2c_bus_t px4_i2c_buses[I2C_BUS_MAX_BUS_ITEMS] = {
initI2CBusExternal(1),
initI2CBusInternal(2),
};
bool px4_i2c_bus_external(const px4_i2c_bus_t &bus)
{
if (HW_VER_FMUV3 == board_get_hw_version()) {
/* All FMUV3 2.1 i2c buses are external */
return true;
} else {
if (bus != PX4_I2C_BUS_ONBOARD) {
if (bus.bus != 2) {
return true;
}
}
+10 -9
View File
@@ -160,7 +160,7 @@ __EXPORT void board_on_reset(int status)
up_mdelay(400);
/* on reboot (status >= 0) reset sensors and peripherals */
board_spi_reset(10);
board_spi_reset(10, 0xffff);
}
}
@@ -309,7 +309,8 @@ stm32_boardinitialize(void)
/* configure power supply control/sense pins */
stm32_configgpio(GPIO_VDD_5V_PERIPH_EN);
stm32_configgpio(GPIO_VDD_3V3_SENSORS_EN);
board_control_spi_sensors_power_configgpio();
board_control_spi_sensors_power(true, 0xffff);
stm32_configgpio(GPIO_VDD_BRICK_VALID);
stm32_configgpio(GPIO_VDD_SERVO_VALID);
stm32_configgpio(GPIO_VDD_USB_VALID);
@@ -419,7 +420,7 @@ __EXPORT int board_app_initialize(uintptr_t arg)
syslog(LOG_DEBUG, "\nFMUv2 ver 0x%1X : Rev %x %s\n", hw_version, hw_revision, hw_type);
}
/* configure SPI interfaces */
/* configure SPI interfaces (after the hw is determined) */
stm32_spiinitialize();
px4_platform_init();
@@ -457,10 +458,10 @@ __EXPORT int board_app_initialize(uintptr_t arg)
/* Configure SPI-based devices */
spi1 = stm32_spibus_initialize(PX4_SPI_BUS_SENSORS);
spi1 = stm32_spibus_initialize(1);
if (!spi1) {
syslog(LOG_ERR, "[boot] FAILED to initialize SPI port %d\n", PX4_SPI_BUS_SENSORS);
syslog(LOG_ERR, "[boot] FAILED to initialize SPI port %d\n", 1);
led_on(LED_AMBER);
return -ENODEV;
}
@@ -473,10 +474,10 @@ __EXPORT int board_app_initialize(uintptr_t arg)
/* Get the SPI port for the FRAM */
spi2 = stm32_spibus_initialize(PX4_SPI_BUS_RAMTRON);
spi2 = stm32_spibus_initialize(2);
if (!spi2) {
syslog(LOG_ERR, "[boot] FAILED to initialize SPI port %d\n", PX4_SPI_BUS_RAMTRON);
syslog(LOG_ERR, "[boot] FAILED to initialize SPI port %d\n", 2);
led_on(LED_AMBER);
return -ENODEV;
}
@@ -489,10 +490,10 @@ __EXPORT int board_app_initialize(uintptr_t arg)
SPI_SETBITS(spi2, 8);
SPI_SETMODE(spi2, SPIDEV_MODE3);
spi4 = stm32_spibus_initialize(PX4_SPI_BUS_EXT);
spi4 = stm32_spibus_initialize(4);
if (!spi4) {
syslog(LOG_ERR, "[boot] FAILED to initialize SPI port %d\n", PX4_SPI_BUS_EXT);
syslog(LOG_ERR, "[boot] FAILED to initialize SPI port %d\n", 4);
led_on(LED_AMBER);
return -ENODEV;
}
-461
View File
@@ -1,461 +0,0 @@
/****************************************************************************
*
* Copyright (C) 2012 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name PX4 nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/**
* @file px4fmu_spi.c
*
* Board-specific SPI functions.
*/
/************************************************************************************
* Included Files
************************************************************************************/
#include <px4_platform_common/px4_config.h>
#include <stdint.h>
#include <stdbool.h>
#include <debug.h>
#include <unistd.h>
#include <nuttx/spi/spi.h>
#include <arch/board/board.h>
#include <up_arch.h>
#include <chip.h>
#include <stm32.h>
#include "board_config.h"
/************************************************************************************
* Public Functions
************************************************************************************/
/************************************************************************************
* Name: stm32_spiinitialize
*
* Description:
* Called to configure SPI chip select GPIO pins for the PX4FMU board.
*
************************************************************************************/
#ifdef CONFIG_STM32_SPI1
/* Verification
* PA5 PA6 PA7 PB0 PB1 PB4 PC1 PC2 PC13 PC14 PC15 PD7 PD15 PE2 PE4 PE5 PE6
* driver X X X X X X
* local V2 v2 V2 V3 a V2 V2M V2x a a 4
*/
static void stm32_spi1_initialize(void)
{
stm32_configgpio(GPIO_SPI1_CS_PC2);
stm32_configgpio(GPIO_SPI1_CS_PD7);
stm32_configgpio(GPIO_SPI1_EXTI_DRDY_PD15);
if (HW_VER_FMUV2MINI == board_get_hw_version()) {
stm32_configgpio(GPIO_SPI1_EXTI_20608_DRDY_PC14);
stm32_configgpio(GPIO_SPI1_CS_PC15);
} else if (HW_VER_FMUV3 == board_get_hw_version()) {
stm32_configgpio(GPIO_SPI1_CS_PC1);
} else {
stm32_configgpio(GPIO_SPI1_EXTI_DRDY_PB0);
stm32_configgpio(GPIO_SPI1_EXTI_DRDY_PB1);
stm32_configgpio(GPIO_SPI1_EXTI_DRDY_PB4);
stm32_configgpio(GPIO_SPI1_CS_PC13);
stm32_configgpio(GPIO_SPI1_CS_PC15);
}
}
#endif // CONFIG_STM32_SPI1
#ifdef CONFIG_STM32_SPI4
/* Verification
* PA5 PA6 PA7 PB0 PB1 PB4 PC1 PC2 PC13 PC14 PC15 PD7 PD15 PE2 PE4 PE5 PE6
* driver X X X X X X
* local V3 V3 - V3 a V3 V23 V3 - -
*/
static void stm32_spi4_initialize(void)
{
stm32_configgpio(GPIO_SPI4_NSS_PE4);
if (HW_VER_FMUV3 == board_get_hw_version()) {
stm32_configgpio(GPIO_SPI4_EXTI_DRDY_PB0);
stm32_configgpio(GPIO_SPI4_CS_PB1);
stm32_configgpio(GPIO_SPI4_CS_PC13);
stm32_configgpio(GPIO_SPI4_CS_PC15);
}
if (HW_VER_FMUV2MINI != board_get_hw_version()) {
stm32_configgpio(GPIO_SPI4_GPIO_PC14);
}
}
#endif //CONFIG_STM32_SPI4
__EXPORT void stm32_spiinitialize(void)
{
#ifdef CONFIG_STM32_SPI1
stm32_spi1_initialize();
#endif
#ifdef CONFIG_STM32_SPI2
stm32_configgpio(GPIO_SPI2_CS_PD10);
#endif
#ifdef CONFIG_STM32_SPI4
stm32_spi4_initialize();
#endif
}
#ifdef CONFIG_STM32_SPI1
__EXPORT void stm32_spi1select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected)
{
/* SPI select is active low, so write !selected to select the device */
/* Verification
* PA5 PA6 PA7 PB0 PB1 PB4 PC1 PC2 PC13 PC14 PC15 PD7 PD15 PE2 PE4 PE5 PE6
* driver X X X X X X
* local - - - V3 a V2 - V2M a - -
*/
switch (devid) {
case PX4_SPIDEV_GYRO:
/* Making sure the other peripherals are not selected */
if (HW_VER_FMUV2 == board_get_hw_version()) {
stm32_gpiowrite(GPIO_SPI1_CS_PC13, !selected);
}
if (HW_VER_FMUV3 != board_get_hw_version()) {
stm32_gpiowrite(GPIO_SPI1_CS_PC15, 1);
}
stm32_gpiowrite(GPIO_SPI1_CS_PD7, 1);
stm32_gpiowrite(GPIO_SPI1_CS_PC2, 1);
if (HW_VER_FMUV3 == board_get_hw_version()) {
stm32_gpiowrite(GPIO_SPI1_CS_PC1, 1);
}
break;
case PX4_SPIDEV_ICM_20608:
case PX4_SPIDEV_ACCEL_MAG:
/* Making sure the other peripherals are not selected */
if (HW_VER_FMUV2 == board_get_hw_version()) {
stm32_gpiowrite(GPIO_SPI1_CS_PC13, 1);
}
if (HW_VER_FMUV3 != board_get_hw_version()) {
stm32_gpiowrite(GPIO_SPI1_CS_PC15, !selected);
}
stm32_gpiowrite(GPIO_SPI1_CS_PD7, 1);
stm32_gpiowrite(GPIO_SPI1_CS_PC2, 1);
if (HW_VER_FMUV3 == board_get_hw_version()) {
stm32_gpiowrite(GPIO_SPI1_CS_PC1, 1);
}
break;
case PX4_SPIDEV_BARO:
/* Making sure the other peripherals are not selected */
if (HW_VER_FMUV2 == board_get_hw_version()) {
stm32_gpiowrite(GPIO_SPI1_CS_PC13, 1);
}
if (HW_VER_FMUV3 != board_get_hw_version()) {
stm32_gpiowrite(GPIO_SPI1_CS_PC15, 1);
}
stm32_gpiowrite(GPIO_SPI1_CS_PD7, !selected);
stm32_gpiowrite(GPIO_SPI1_CS_PC2, 1);
if (HW_VER_FMUV3 == board_get_hw_version()) {
stm32_gpiowrite(GPIO_SPI1_CS_PC1, 1);
}
break;
case PX4_SPIDEV_MPU:
/* Making sure the other peripherals are not selected */
if (HW_VER_FMUV2 == board_get_hw_version()) {
stm32_gpiowrite(GPIO_SPI1_CS_PC13, 1);
}
if (HW_VER_FMUV3 != board_get_hw_version()) {
stm32_gpiowrite(GPIO_SPI1_CS_PC15, 1);
}
stm32_gpiowrite(GPIO_SPI1_CS_PD7, 1);
stm32_gpiowrite(GPIO_SPI1_CS_PC2, !selected);
if (HW_VER_FMUV3 == board_get_hw_version()) {
stm32_gpiowrite(GPIO_SPI1_CS_PC1, 1);
}
break;
case PX4_SPIDEV_HMC:
if (HW_VER_FMUV2 == board_get_hw_version()) {
stm32_gpiowrite(GPIO_SPI1_CS_PC13, 1);
}
if (HW_VER_FMUV3 != board_get_hw_version()) {
stm32_gpiowrite(GPIO_SPI1_CS_PC15, 1);
}
stm32_gpiowrite(GPIO_SPI1_CS_PD7, 1);
stm32_gpiowrite(GPIO_SPI1_CS_PC2, 1);
if (HW_VER_FMUV3 == board_get_hw_version()) {
stm32_gpiowrite(GPIO_SPI1_CS_PC1, !selected);
}
break;
default:
break;
}
}
__EXPORT uint8_t stm32_spi1status(FAR struct spi_dev_s *dev, uint32_t devid)
{
return SPI_STATUS_PRESENT;
}
#endif // CONFIG_STM32_SPI1
#ifdef CONFIG_STM32_SPI2
__EXPORT void stm32_spi2select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected)
{
/* there can only be one device on this bus, so always select it */
stm32_gpiowrite(GPIO_SPI2_CS_PD10, !selected);
}
__EXPORT uint8_t stm32_spi2status(FAR struct spi_dev_s *dev, uint32_t devid)
{
/* FRAM is always present */
return SPI_STATUS_PRESENT;
}
#endif
#ifdef CONFIG_STM32_SPI4
__EXPORT void stm32_spi4select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected)
{
/* SPI select is active low, so write !selected to select the device */
/* Verification
* PA5 PA6 PA7 PB0 PB1 PB4 PC1 PC2 PC13 PC14 PC15 PD7 PD15 PE2 PE4 PE5 PE6
* driver X X X X X X
* local - - - - - V3 !V2M V3 - - a
*/
switch (devid) {
case PX4_SPIDEV_EXT_MPU:
/* Making sure the other peripherals are not selected */
stm32_gpiowrite(GPIO_SPI4_NSS_PE4, !selected);
if (HW_VER_FMUV2MINI != board_get_hw_version()) {
stm32_gpiowrite(GPIO_SPI4_GPIO_PC14, 1);
}
if (HW_VER_FMUV3 == board_get_hw_version()) {
stm32_gpiowrite(GPIO_SPI4_CS_PC15, 1);
stm32_gpiowrite(GPIO_SPI4_CS_PC13, 1);
}
break;
case PX4_SPIDEV_EXT_BARO:
/* Making sure the other peripherals are not selected */
stm32_gpiowrite(GPIO_SPI4_NSS_PE4, 1);
if (HW_VER_FMUV2MINI != board_get_hw_version()) {
stm32_gpiowrite(GPIO_SPI4_GPIO_PC14, !selected);
}
if (HW_VER_FMUV3 == board_get_hw_version()) {
stm32_gpiowrite(GPIO_SPI4_CS_PC15, 1);
stm32_gpiowrite(GPIO_SPI4_CS_PC13, 1);
}
break;
case PX4_SPIDEV_ICM_20608:
case PX4_SPIDEV_EXT_ACCEL_MAG:
/* Making sure the other peripherals are not selected */
stm32_gpiowrite(GPIO_SPI4_NSS_PE4, 1);
if (HW_VER_FMUV2MINI != board_get_hw_version()) {
stm32_gpiowrite(GPIO_SPI4_GPIO_PC14, 1);
}
if (HW_VER_FMUV3 == board_get_hw_version()) {
stm32_gpiowrite(GPIO_SPI4_CS_PC15, !selected);
stm32_gpiowrite(GPIO_SPI4_CS_PC13, 1);
}
break;
case PX4_SPIDEV_EXT_BMI:
case PX4_SPIDEV_EXT_GYRO:
/* Making sure the other peripherals are not selected */
stm32_gpiowrite(GPIO_SPI4_NSS_PE4, 1);
if (HW_VER_FMUV2MINI != board_get_hw_version()) {
stm32_gpiowrite(GPIO_SPI4_GPIO_PC14, 1);
}
if (HW_VER_FMUV3 == board_get_hw_version()) {
stm32_gpiowrite(GPIO_SPI4_CS_PC15, 1);
stm32_gpiowrite(GPIO_SPI4_CS_PC13, !selected);
}
break;
default:
break;
}
}
__EXPORT uint8_t stm32_spi4status(FAR struct spi_dev_s *dev, uint32_t devid)
{
return SPI_STATUS_PRESENT;
}
#endif // CONFIG_STM32_SPI4
/* V2, V2M SPI1 All signals SPI4, V3 ALL signals */
/* Verification
* PA5 PA6 PA7 PB0 PB1 PB4 PC1 PC2 PC13 PC14 PC15 PD7 PD15 PE2 PE4 PE5 PE6
* local A A A A A A V3 A A !V2 A A A V3 V3 V3 V3
*/
__EXPORT void board_spi_reset(int ms)
{
/* disable SPI bus */
stm32_configgpio(_PIN_OFF(GPIO_SPI1_CS_PC2));
stm32_configgpio(_PIN_OFF(GPIO_SPI1_CS_PC13));
stm32_configgpio(_PIN_OFF(GPIO_SPI1_CS_PC15));
stm32_configgpio(_PIN_OFF(GPIO_SPI1_CS_PD7));
stm32_gpiowrite(_PIN_OFF(GPIO_SPI1_CS_PC2), 0);
stm32_gpiowrite(_PIN_OFF(GPIO_SPI1_CS_PC13), 0);
stm32_gpiowrite(_PIN_OFF(GPIO_SPI1_CS_PC15), 0);
stm32_gpiowrite(_PIN_OFF(GPIO_SPI1_CS_PD7), 0);
stm32_configgpio(_PIN_OFF(GPIO_SPI1_SCK));
stm32_configgpio(_PIN_OFF(GPIO_SPI1_MISO));
stm32_configgpio(_PIN_OFF(GPIO_SPI1_MOSI));
stm32_gpiowrite(_PIN_OFF(GPIO_SPI1_SCK), 0);
stm32_gpiowrite(_PIN_OFF(GPIO_SPI1_MISO), 0);
stm32_gpiowrite(_PIN_OFF(GPIO_SPI1_MOSI), 0);
stm32_configgpio(_PIN_OFF(GPIO_SPI1_EXTI_DRDY_PB0));
stm32_configgpio(_PIN_OFF(GPIO_SPI1_EXTI_DRDY_PB1));
stm32_configgpio(_PIN_OFF(GPIO_SPI1_EXTI_DRDY_PB4));
stm32_configgpio(_PIN_OFF(GPIO_SPI1_EXTI_DRDY_PD15));
stm32_gpiowrite(_PIN_OFF(GPIO_SPI1_EXTI_DRDY_PB0), 0);
stm32_gpiowrite(_PIN_OFF(GPIO_SPI1_EXTI_DRDY_PB1), 0);
stm32_gpiowrite(_PIN_OFF(GPIO_SPI1_EXTI_DRDY_PB4), 0);
stm32_gpiowrite(_PIN_OFF(GPIO_SPI1_EXTI_DRDY_PD15), 0);
if (HW_VER_FMUV2 != board_get_hw_version()) {
stm32_configgpio(_PIN_OFF(GPIO_SPI4_CS_PC14));
stm32_gpiowrite(_PIN_OFF(GPIO_SPI4_CS_PC14), 0);
}
if (HW_VER_FMUV3 == board_get_hw_version()) {
stm32_configgpio(_PIN_OFF(GPIO_SPI1_CS_PC1));
stm32_gpiowrite(_PIN_OFF(GPIO_SPI1_CS_PC1), 0);
stm32_configgpio(_PIN_OFF(GPIO_SPI4_NSS_PE4));
stm32_gpiowrite(_PIN_OFF(GPIO_SPI4_NSS_PE4), 0);
stm32_configgpio(_PIN_OFF(GPIO_SPI4_SCK));
stm32_configgpio(_PIN_OFF(GPIO_SPI4_MISO));
stm32_configgpio(_PIN_OFF(GPIO_SPI4_MOSI));
stm32_gpiowrite(_PIN_OFF(GPIO_SPI4_SCK), 0);
stm32_gpiowrite(_PIN_OFF(GPIO_SPI4_MISO), 0);
stm32_gpiowrite(_PIN_OFF(GPIO_SPI4_MOSI), 0);
}
/* set the sensor rail off */
stm32_configgpio(GPIO_VDD_3V3_SENSORS_EN);
stm32_gpiowrite(GPIO_VDD_3V3_SENSORS_EN, 0);
/* wait for the sensor rail to reach GND */
usleep(ms * 1000);
syslog(LOG_DEBUG, "reset done, %d ms\n", ms);
/* re-enable power */
/* switch the sensor rail back on */
stm32_gpiowrite(GPIO_VDD_3V3_SENSORS_EN, 1);
/* wait a bit before starting SPI, different times didn't influence results */
usleep(100);
/* reconfigure the SPI pins */
stm32_configgpio(GPIO_SPI1_SCK);
stm32_configgpio(GPIO_SPI1_MISO);
stm32_configgpio(GPIO_SPI1_MOSI);
if (HW_VER_FMUV3 == board_get_hw_version()) {
stm32_configgpio(GPIO_SPI4_SCK);
stm32_configgpio(GPIO_SPI4_MISO);
stm32_configgpio(GPIO_SPI4_MOSI);
stm32_spi4_initialize();
}
stm32_spi1_initialize();
}
__EXPORT bool px4_spi_bus_external(int bus)
{
if (HW_VER_FMUV3 == board_get_hw_version()) {
/* all FMUv3 2.1 spi buses are internal */
return false;
} else {
if (bus == PX4_SPI_BUS_EXT) {
return true;
}
}
return false;
}
+90
View File
@@ -0,0 +1,90 @@
/****************************************************************************
*
* Copyright (C) 2012 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name PX4 nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#include <nuttx/spi/spi.h>
#include <px4_arch/spi_hw_description.h>
#include <drivers/drv_sensor.h>
constexpr px4_spi_bus_all_hw_t px4_spi_buses_all_hw[BOARD_NUM_SPI_CFG_HW_VERSIONS] = {
initSPIHWVersion(HW_VER_FMUV2, {
initSPIBus(1, {
initSPIDevice(DRV_IMU_DEVTYPE_MPU6000, SPI::CS{GPIO::PortC, GPIO::Pin2}, SPI::DRDY{GPIO::PortD, GPIO::Pin15}),
initSPIDevice(DRV_IMU_DEVTYPE_MPU9250, SPI::CS{GPIO::PortC, GPIO::Pin2}, SPI::DRDY{GPIO::PortD, GPIO::Pin15}),
initSPIDevice(DRV_GYR_DEVTYPE_L3GD20, SPI::CS{GPIO::PortC, GPIO::Pin13}, SPI::DRDY{GPIO::PortB, GPIO::Pin0}),
initSPIDevice(DRV_ACC_DEVTYPE_LSM303D, SPI::CS{GPIO::PortC, GPIO::Pin15}),
initSPIDevice(DRV_BARO_DEVTYPE_MS5611, SPI::CS{GPIO::PortD, GPIO::Pin7}),
}, {GPIO::PortE, GPIO::Pin3}),
initSPIBus(2, {
initSPIDevice(SPIDEV_FLASH(0), SPI::CS{GPIO::PortD, GPIO::Pin10})
}),
initSPIBusExternal(4, {
initSPIConfigExternal(SPI::CS{GPIO::PortC, GPIO::Pin14}),
initSPIConfigExternal(SPI::CS{GPIO::PortE, GPIO::Pin4}),
}),
}),
initSPIHWVersion(HW_VER_FMUV3, {
initSPIBus(1, {
initSPIDevice(DRV_IMU_DEVTYPE_MPU6000, SPI::CS{GPIO::PortC, GPIO::Pin2}, SPI::DRDY{GPIO::PortD, GPIO::Pin15}),
initSPIDevice(DRV_IMU_DEVTYPE_MPU9250, SPI::CS{GPIO::PortC, GPIO::Pin2}, SPI::DRDY{GPIO::PortD, GPIO::Pin15}),
initSPIDevice(DRV_MAG_DEVTYPE_HMC5883, SPI::CS{GPIO::PortC, GPIO::Pin1}), // HMC5983
initSPIDevice(DRV_BARO_DEVTYPE_MS5611, SPI::CS{GPIO::PortD, GPIO::Pin7}),
}, {GPIO::PortE, GPIO::Pin3}),
initSPIBus(2, {
initSPIDevice(SPIDEV_FLASH(0), SPI::CS{GPIO::PortD, GPIO::Pin10})
}),
initSPIBus(4, {
initSPIDevice(DRV_IMU_DEVTYPE_MPU6000, SPI::CS{GPIO::PortE, GPIO::Pin4}),
initSPIDevice(DRV_IMU_DEVTYPE_MPU9250, SPI::CS{GPIO::PortE, GPIO::Pin4}),
initSPIDevice(DRV_GYR_DEVTYPE_L3GD20, SPI::CS{GPIO::PortC, GPIO::Pin13}),
initSPIDevice(DRV_BARO_DEVTYPE_MS5611, SPI::CS{GPIO::PortC, GPIO::Pin14}),
initSPIDevice(DRV_ACC_DEVTYPE_LSM303D, SPI::CS{GPIO::PortC, GPIO::Pin15}),
}),
}),
initSPIHWVersion(HW_VER_FMUV2MINI, {
initSPIBus(1, {
initSPIDevice(DRV_IMU_DEVTYPE_ICM20608, SPI::CS{GPIO::PortC, GPIO::Pin15}, SPI::DRDY{GPIO::PortC, GPIO::Pin14}),
initSPIDevice(DRV_BARO_DEVTYPE_MS5611, SPI::CS{GPIO::PortD, GPIO::Pin7}),
}, {GPIO::PortE, GPIO::Pin3}),
initSPIBus(2, {
initSPIDevice(SPIDEV_FLASH(0), SPI::CS{GPIO::PortD, GPIO::Pin10})
}),
initSPIBusExternal(4, { // unused, but we must at least define it here
}),
}),
// HW_VER_FMUV2X: treat as HW_VER_FMUV2
};
static constexpr bool unused = validateSPIConfig(px4_spi_buses_all_hw);
+3 -2
View File
@@ -33,10 +33,10 @@
add_library(drivers_board
can.c
i2c.c
i2c.cpp
init.c
led.c
spi.c
spi.cpp
timer_config.cpp
usb.c
manifest.c
@@ -44,6 +44,7 @@ add_library(drivers_board
target_link_libraries(drivers_board
PRIVATE
arch_spi
drivers__led # drv_led_start
nuttx_arch # sdio
nuttx_drivers # sdio
+16 -19
View File
@@ -60,6 +60,7 @@
#define HW_VER_FMUV2MINI_STATE 0xA /* PB12:PU:1 PB12:PD:0 PB4:PU:1 PB4PD:0 */
#define HW_VER_FMUV2X_STATE 0xB /* PB12:PU:1 PB12:PD:0 PB4:PU:1 PB4PD:1 */
#define HW_VER_TYPE_INIT {'V','2',0, 0}
#define BOARD_NUM_SPI_CFG_HW_VERSIONS 3
/****************************************************************************************************
* Definitions
@@ -87,12 +88,7 @@
#define GPIO_LED1 (GPIO_OUTPUT|GPIO_OPENDRAIN|GPIO_SPEED_50MHz|GPIO_OUTPUT_CLEAR|GPIO_PORTE|GPIO_PIN12)
#define BOARD_OVERLOAD_LED LED_AMBER
/*
* Define the ability to shut off off the sensor signals
* by changing the signals to inputs
*/
#define _PIN_OFF(def) (((def) & (GPIO_PORT_MASK | GPIO_PIN_MASK)) | (GPIO_INPUT|GPIO_PULLDOWN|GPIO_SPEED_50MHz))
#include <drivers/drv_sensor.h>
/* Due to inconsistent use of chip select and dry signal on
* different board that use this build. We are defining the GPIO
@@ -208,24 +204,27 @@
/* Use these to select a specific SPI device on SPI1 */
#define PX4_SPIDEV_GYRO PX4_MK_SPI_SEL(PX4_SPI_BUS_SENSORS, 1)
#define PX4_SPIDEV_ACCEL_MAG PX4_MK_SPI_SEL(PX4_SPI_BUS_SENSORS, 2)
#define PX4_SPIDEV_BARO PX4_MK_SPI_SEL(PX4_SPI_BUS_SENSORS, 3)
#define PX4_SPIDEV_MPU PX4_MK_SPI_SEL(PX4_SPI_BUS_SENSORS, 4)
#define PX4_SPIDEV_GYRO PX4_MK_SPI_SEL(0, DRV_GYR_DEVTYPE_L3GD20)
#define PX4_SPIDEV_ACCEL_MAG PX4_MK_SPI_SEL(0, DRV_ACC_DEVTYPE_LSM303D)
#define PX4_SPIDEV_BARO PX4_MK_SPI_SEL(0, DRV_BARO_DEVTYPE_MS5611)
#define PX4_SPIDEV_MPU PX4_MK_SPI_SEL(0, DRV_IMU_DEVTYPE_MPU6000)
/* FMUv3 SPI on external bus */
#define PX4_SPIDEV_EXT_GYRO PX4_MK_SPI_SEL(PX4_SPI_BUS_EXT, 1)
#define PX4_SPIDEV_EXT_ACCEL_MAG PX4_MK_SPI_SEL(PX4_SPI_BUS_EXT, 2)
#define PX4_SPIDEV_EXT_BARO PX4_MK_SPI_SEL(PX4_SPI_BUS_EXT, 3)
#define PX4_SPIDEV_EXT_MPU PX4_MK_SPI_SEL(PX4_SPI_BUS_EXT, 4)
#define PX4_SPIDEV_EXT_BMI PX4_MK_SPI_SEL(PX4_SPI_BUS_EXT, 5)
#define PX4_SPIDEV_EXT_GYRO PX4_MK_SPI_SEL(0, DRV_GYR_DEVTYPE_L3GD20)
#define PX4_SPIDEV_EXT_ACCEL_MAG PX4_MK_SPI_SEL(0, DRV_ACC_DEVTYPE_LSM303D)
#define PX4_SPIDEV_EXT_BARO PX4_MK_SPI_SEL(0, DRV_BARO_DEVTYPE_MS5611)
#define PX4_SPIDEV_EXT_MPU PX4_MK_SPI_SEL(0, DRV_IMU_DEVTYPE_MPU6000)
#define PX4_SPIDEV_EXT_BMI PX4_MK_SPI_SEL(0, DRV_GYR_DEVTYPE_BMI055)
/* I2C busses */
#define BOARD_OVERRIDE_I2C_BUS_EXTERNAL
#define PX4_I2C_BUS_EXPANSION 1
#define PX4_I2C_BUS_ONBOARD 2
#define PX4_I2C_BUS_LED PX4_I2C_BUS_ONBOARD
#define BOARD_SPI_BUS_MAX_BUS_ITEMS 3
/*----------------------------------------------------------*/
/* FMUv3 Cube SPI chip selects and DRDY */
/*----------------------------------------------------------*/
@@ -292,7 +291,7 @@
#define GPIO_SPI4_EXTERN_CS GPIO_SPI4_CS_PB1
/* PB1 is an External CS on V3 */
#define PX4_SPIDEV_HMC 5
#define PX4_SPIDEV_HMC PX4_MK_SPI_SEL(0, DRV_MAG_DEVTYPE_HMC5883)
/*----------------------------------------------------------*/
/* End FMUv3 Cube SPI chip selects and DRDY */
@@ -351,7 +350,7 @@
*/
#define GPIO_SPI1_EXTI_20608_DRDY_PC14 (GPIO_INPUT|GPIO_FLOAT|GPIO_EXTI|GPIO_PORTC|GPIO_PIN14)
#define PX4_SPIDEV_ICM_20608 6 /* ICM_20608 on PC15 */
#define PX4_SPIDEV_ICM_20608 PX4_MK_SPI_SEL(0, DRV_IMU_DEVTYPE_ICM20608)
@@ -379,7 +378,6 @@
#define GPIO_VDD_BRICK_VALID (GPIO_INPUT|GPIO_PULLUP|GPIO_PORTB|GPIO_PIN5)
#define GPIO_VDD_SERVO_VALID (GPIO_INPUT|GPIO_PULLUP|GPIO_PORTB|GPIO_PIN7)
#define GPIO_VDD_USB_VALID (GPIO_INPUT|GPIO_PULLUP|GPIO_PORTC|GPIO_PIN0)
#define GPIO_VDD_3V3_SENSORS_EN (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_2MHz|GPIO_OUTPUT_SET|GPIO_PORTE|GPIO_PIN3)
#define GPIO_VDD_5V_HIPOWER_OC (GPIO_INPUT|GPIO_PULLUP|GPIO_PORTE|GPIO_PIN10)
#define GPIO_VDD_5V_PERIPH_OC (GPIO_INPUT|GPIO_PULLUP|GPIO_PORTE|GPIO_PIN15)
@@ -463,7 +461,6 @@ extern void stm32_spiinitialize(void);
*
****************************************************************************************************/
void board_spi_reset(int ms);
extern void board_peripheral_reset(int ms);
/****************************************************************************************************
@@ -38,15 +38,23 @@
*/
#include "board_config.h"
#include <px4_platform_common/i2c.h>
#include <px4_arch/i2c_hw_description.h>
__EXPORT bool px4_i2c_bus_external(int bus)
constexpr px4_i2c_bus_t px4_i2c_buses[I2C_BUS_MAX_BUS_ITEMS] = {
initI2CBusExternal(1),
initI2CBusInternal(2),
};
bool px4_i2c_bus_external(const px4_i2c_bus_t &bus)
{
if (HW_VER_FMUV3 == board_get_hw_version()) {
/* All FMUV3 2.1 i2c buses are external */
return true;
} else {
if (bus != PX4_I2C_BUS_ONBOARD) {
if (bus.bus != 2) {
return true;
}
}
+10 -9
View File
@@ -160,7 +160,7 @@ __EXPORT void board_on_reset(int status)
up_mdelay(400);
/* on reboot (status >= 0) reset sensors and peripherals */
board_spi_reset(10);
board_spi_reset(10, 0xffff);
}
}
@@ -309,7 +309,8 @@ stm32_boardinitialize(void)
/* configure power supply control/sense pins */
stm32_configgpio(GPIO_VDD_5V_PERIPH_EN);
stm32_configgpio(GPIO_VDD_3V3_SENSORS_EN);
board_control_spi_sensors_power_configgpio();
board_control_spi_sensors_power(true, 0xffff);
stm32_configgpio(GPIO_VDD_BRICK_VALID);
stm32_configgpio(GPIO_VDD_SERVO_VALID);
stm32_configgpio(GPIO_VDD_USB_VALID);
@@ -419,7 +420,7 @@ __EXPORT int board_app_initialize(uintptr_t arg)
syslog(LOG_DEBUG, "\nFMUv2 ver 0x%1X : Rev %x %s\n", hw_version, hw_revision, hw_type);
}
/* configure SPI interfaces */
/* configure SPI interfaces (after the hw is determined) */
stm32_spiinitialize();
px4_platform_init();
@@ -457,10 +458,10 @@ __EXPORT int board_app_initialize(uintptr_t arg)
/* Configure SPI-based devices */
spi1 = stm32_spibus_initialize(PX4_SPI_BUS_SENSORS);
spi1 = stm32_spibus_initialize(1);
if (!spi1) {
syslog(LOG_ERR, "[boot] FAILED to initialize SPI port %d\n", PX4_SPI_BUS_SENSORS);
syslog(LOG_ERR, "[boot] FAILED to initialize SPI port %d\n", 1);
led_on(LED_AMBER);
return -ENODEV;
}
@@ -473,10 +474,10 @@ __EXPORT int board_app_initialize(uintptr_t arg)
/* Get the SPI port for the FRAM */
spi2 = stm32_spibus_initialize(PX4_SPI_BUS_RAMTRON);
spi2 = stm32_spibus_initialize(2);
if (!spi2) {
syslog(LOG_ERR, "[boot] FAILED to initialize SPI port %d\n", PX4_SPI_BUS_RAMTRON);
syslog(LOG_ERR, "[boot] FAILED to initialize SPI port %d\n", 2);
led_on(LED_AMBER);
return -ENODEV;
}
@@ -489,10 +490,10 @@ __EXPORT int board_app_initialize(uintptr_t arg)
SPI_SETBITS(spi2, 8);
SPI_SETMODE(spi2, SPIDEV_MODE3);
spi4 = stm32_spibus_initialize(PX4_SPI_BUS_EXT);
spi4 = stm32_spibus_initialize(4);
if (!spi4) {
syslog(LOG_ERR, "[boot] FAILED to initialize SPI port %d\n", PX4_SPI_BUS_EXT);
syslog(LOG_ERR, "[boot] FAILED to initialize SPI port %d\n", 4);
led_on(LED_AMBER);
return -ENODEV;
}
-461
View File
@@ -1,461 +0,0 @@
/****************************************************************************
*
* Copyright (C) 2012 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name PX4 nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/**
* @file px4fmu_spi.c
*
* Board-specific SPI functions.
*/
/************************************************************************************
* Included Files
************************************************************************************/
#include <px4_platform_common/px4_config.h>
#include <stdint.h>
#include <stdbool.h>
#include <debug.h>
#include <unistd.h>
#include <nuttx/spi/spi.h>
#include <arch/board/board.h>
#include <up_arch.h>
#include <chip.h>
#include <stm32.h>
#include "board_config.h"
/************************************************************************************
* Public Functions
************************************************************************************/
/************************************************************************************
* Name: stm32_spiinitialize
*
* Description:
* Called to configure SPI chip select GPIO pins for the PX4FMU board.
*
************************************************************************************/
#ifdef CONFIG_STM32_SPI1
/* Verification
* PA5 PA6 PA7 PB0 PB1 PB4 PC1 PC2 PC13 PC14 PC15 PD7 PD15 PE2 PE4 PE5 PE6
* driver X X X X X X
* local V2 v2 V2 V3 a V2 V2M V2x a a 4
*/
static void stm32_spi1_initialize(void)
{
stm32_configgpio(GPIO_SPI1_CS_PC2);
stm32_configgpio(GPIO_SPI1_CS_PD7);
stm32_configgpio(GPIO_SPI1_EXTI_DRDY_PD15);
if (HW_VER_FMUV2MINI == board_get_hw_version()) {
stm32_configgpio(GPIO_SPI1_EXTI_20608_DRDY_PC14);
stm32_configgpio(GPIO_SPI1_CS_PC15);
} else if (HW_VER_FMUV3 == board_get_hw_version()) {
stm32_configgpio(GPIO_SPI1_CS_PC1);
} else {
stm32_configgpio(GPIO_SPI1_EXTI_DRDY_PB0);
stm32_configgpio(GPIO_SPI1_EXTI_DRDY_PB1);
stm32_configgpio(GPIO_SPI1_EXTI_DRDY_PB4);
stm32_configgpio(GPIO_SPI1_CS_PC13);
stm32_configgpio(GPIO_SPI1_CS_PC15);
}
}
#endif // CONFIG_STM32_SPI1
#ifdef CONFIG_STM32_SPI4
/* Verification
* PA5 PA6 PA7 PB0 PB1 PB4 PC1 PC2 PC13 PC14 PC15 PD7 PD15 PE2 PE4 PE5 PE6
* driver X X X X X X
* local V3 V3 - V3 a V3 V23 V3 - -
*/
static void stm32_spi4_initialize(void)
{
stm32_configgpio(GPIO_SPI4_NSS_PE4);
if (HW_VER_FMUV3 == board_get_hw_version()) {
stm32_configgpio(GPIO_SPI4_EXTI_DRDY_PB0);
stm32_configgpio(GPIO_SPI4_CS_PB1);
stm32_configgpio(GPIO_SPI4_CS_PC13);
stm32_configgpio(GPIO_SPI4_CS_PC15);
}
if (HW_VER_FMUV2MINI != board_get_hw_version()) {
stm32_configgpio(GPIO_SPI4_GPIO_PC14);
}
}
#endif //CONFIG_STM32_SPI4
__EXPORT void stm32_spiinitialize(void)
{
#ifdef CONFIG_STM32_SPI1
stm32_spi1_initialize();
#endif
#ifdef CONFIG_STM32_SPI2
stm32_configgpio(GPIO_SPI2_CS_PD10);
#endif
#ifdef CONFIG_STM32_SPI4
stm32_spi4_initialize();
#endif
}
#ifdef CONFIG_STM32_SPI1
__EXPORT void stm32_spi1select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected)
{
/* SPI select is active low, so write !selected to select the device */
/* Verification
* PA5 PA6 PA7 PB0 PB1 PB4 PC1 PC2 PC13 PC14 PC15 PD7 PD15 PE2 PE4 PE5 PE6
* driver X X X X X X
* local - - - V3 a V2 - V2M a - -
*/
switch (devid) {
case PX4_SPIDEV_GYRO:
/* Making sure the other peripherals are not selected */
if (HW_VER_FMUV2 == board_get_hw_version()) {
stm32_gpiowrite(GPIO_SPI1_CS_PC13, !selected);
}
if (HW_VER_FMUV3 != board_get_hw_version()) {
stm32_gpiowrite(GPIO_SPI1_CS_PC15, 1);
}
stm32_gpiowrite(GPIO_SPI1_CS_PD7, 1);
stm32_gpiowrite(GPIO_SPI1_CS_PC2, 1);
if (HW_VER_FMUV3 == board_get_hw_version()) {
stm32_gpiowrite(GPIO_SPI1_CS_PC1, 1);
}
break;
case PX4_SPIDEV_ICM_20608:
case PX4_SPIDEV_ACCEL_MAG:
/* Making sure the other peripherals are not selected */
if (HW_VER_FMUV2 == board_get_hw_version()) {
stm32_gpiowrite(GPIO_SPI1_CS_PC13, 1);
}
if (HW_VER_FMUV3 != board_get_hw_version()) {
stm32_gpiowrite(GPIO_SPI1_CS_PC15, !selected);
}
stm32_gpiowrite(GPIO_SPI1_CS_PD7, 1);
stm32_gpiowrite(GPIO_SPI1_CS_PC2, 1);
if (HW_VER_FMUV3 == board_get_hw_version()) {
stm32_gpiowrite(GPIO_SPI1_CS_PC1, 1);
}
break;
case PX4_SPIDEV_BARO:
/* Making sure the other peripherals are not selected */
if (HW_VER_FMUV2 == board_get_hw_version()) {
stm32_gpiowrite(GPIO_SPI1_CS_PC13, 1);
}
if (HW_VER_FMUV3 != board_get_hw_version()) {
stm32_gpiowrite(GPIO_SPI1_CS_PC15, 1);
}
stm32_gpiowrite(GPIO_SPI1_CS_PD7, !selected);
stm32_gpiowrite(GPIO_SPI1_CS_PC2, 1);
if (HW_VER_FMUV3 == board_get_hw_version()) {
stm32_gpiowrite(GPIO_SPI1_CS_PC1, 1);
}
break;
case PX4_SPIDEV_MPU:
/* Making sure the other peripherals are not selected */
if (HW_VER_FMUV2 == board_get_hw_version()) {
stm32_gpiowrite(GPIO_SPI1_CS_PC13, 1);
}
if (HW_VER_FMUV3 != board_get_hw_version()) {
stm32_gpiowrite(GPIO_SPI1_CS_PC15, 1);
}
stm32_gpiowrite(GPIO_SPI1_CS_PD7, 1);
stm32_gpiowrite(GPIO_SPI1_CS_PC2, !selected);
if (HW_VER_FMUV3 == board_get_hw_version()) {
stm32_gpiowrite(GPIO_SPI1_CS_PC1, 1);
}
break;
case PX4_SPIDEV_HMC:
if (HW_VER_FMUV2 == board_get_hw_version()) {
stm32_gpiowrite(GPIO_SPI1_CS_PC13, 1);
}
if (HW_VER_FMUV3 != board_get_hw_version()) {
stm32_gpiowrite(GPIO_SPI1_CS_PC15, 1);
}
stm32_gpiowrite(GPIO_SPI1_CS_PD7, 1);
stm32_gpiowrite(GPIO_SPI1_CS_PC2, 1);
if (HW_VER_FMUV3 == board_get_hw_version()) {
stm32_gpiowrite(GPIO_SPI1_CS_PC1, !selected);
}
break;
default:
break;
}
}
__EXPORT uint8_t stm32_spi1status(FAR struct spi_dev_s *dev, uint32_t devid)
{
return SPI_STATUS_PRESENT;
}
#endif // CONFIG_STM32_SPI1
#ifdef CONFIG_STM32_SPI2
__EXPORT void stm32_spi2select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected)
{
/* there can only be one device on this bus, so always select it */
stm32_gpiowrite(GPIO_SPI2_CS_PD10, !selected);
}
__EXPORT uint8_t stm32_spi2status(FAR struct spi_dev_s *dev, uint32_t devid)
{
/* FRAM is always present */
return SPI_STATUS_PRESENT;
}
#endif
#ifdef CONFIG_STM32_SPI4
__EXPORT void stm32_spi4select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected)
{
/* SPI select is active low, so write !selected to select the device */
/* Verification
* PA5 PA6 PA7 PB0 PB1 PB4 PC1 PC2 PC13 PC14 PC15 PD7 PD15 PE2 PE4 PE5 PE6
* driver X X X X X X
* local - - - - - V3 !V2M V3 - - a
*/
switch (devid) {
case PX4_SPIDEV_EXT_MPU:
/* Making sure the other peripherals are not selected */
stm32_gpiowrite(GPIO_SPI4_NSS_PE4, !selected);
if (HW_VER_FMUV2MINI != board_get_hw_version()) {
stm32_gpiowrite(GPIO_SPI4_GPIO_PC14, 1);
}
if (HW_VER_FMUV3 == board_get_hw_version()) {
stm32_gpiowrite(GPIO_SPI4_CS_PC15, 1);
stm32_gpiowrite(GPIO_SPI4_CS_PC13, 1);
}
break;
case PX4_SPIDEV_EXT_BARO:
/* Making sure the other peripherals are not selected */
stm32_gpiowrite(GPIO_SPI4_NSS_PE4, 1);
if (HW_VER_FMUV2MINI != board_get_hw_version()) {
stm32_gpiowrite(GPIO_SPI4_GPIO_PC14, !selected);
}
if (HW_VER_FMUV3 == board_get_hw_version()) {
stm32_gpiowrite(GPIO_SPI4_CS_PC15, 1);
stm32_gpiowrite(GPIO_SPI4_CS_PC13, 1);
}
break;
case PX4_SPIDEV_ICM_20608:
case PX4_SPIDEV_EXT_ACCEL_MAG:
/* Making sure the other peripherals are not selected */
stm32_gpiowrite(GPIO_SPI4_NSS_PE4, 1);
if (HW_VER_FMUV2MINI != board_get_hw_version()) {
stm32_gpiowrite(GPIO_SPI4_GPIO_PC14, 1);
}
if (HW_VER_FMUV3 == board_get_hw_version()) {
stm32_gpiowrite(GPIO_SPI4_CS_PC15, !selected);
stm32_gpiowrite(GPIO_SPI4_CS_PC13, 1);
}
break;
case PX4_SPIDEV_EXT_BMI:
case PX4_SPIDEV_EXT_GYRO:
/* Making sure the other peripherals are not selected */
stm32_gpiowrite(GPIO_SPI4_NSS_PE4, 1);
if (HW_VER_FMUV2MINI != board_get_hw_version()) {
stm32_gpiowrite(GPIO_SPI4_GPIO_PC14, 1);
}
if (HW_VER_FMUV3 == board_get_hw_version()) {
stm32_gpiowrite(GPIO_SPI4_CS_PC15, 1);
stm32_gpiowrite(GPIO_SPI4_CS_PC13, !selected);
}
break;
default:
break;
}
}
__EXPORT uint8_t stm32_spi4status(FAR struct spi_dev_s *dev, uint32_t devid)
{
return SPI_STATUS_PRESENT;
}
#endif // CONFIG_STM32_SPI4
/* V2, V2M SPI1 All signals SPI4, V3 ALL signals */
/* Verification
* PA5 PA6 PA7 PB0 PB1 PB4 PC1 PC2 PC13 PC14 PC15 PD7 PD15 PE2 PE4 PE5 PE6
* local A A A A A A V3 A A !V2 A A A V3 V3 V3 V3
*/
__EXPORT void board_spi_reset(int ms)
{
/* disable SPI bus */
stm32_configgpio(_PIN_OFF(GPIO_SPI1_CS_PC2));
stm32_configgpio(_PIN_OFF(GPIO_SPI1_CS_PC13));
stm32_configgpio(_PIN_OFF(GPIO_SPI1_CS_PC15));
stm32_configgpio(_PIN_OFF(GPIO_SPI1_CS_PD7));
stm32_gpiowrite(_PIN_OFF(GPIO_SPI1_CS_PC2), 0);
stm32_gpiowrite(_PIN_OFF(GPIO_SPI1_CS_PC13), 0);
stm32_gpiowrite(_PIN_OFF(GPIO_SPI1_CS_PC15), 0);
stm32_gpiowrite(_PIN_OFF(GPIO_SPI1_CS_PD7), 0);
stm32_configgpio(_PIN_OFF(GPIO_SPI1_SCK));
stm32_configgpio(_PIN_OFF(GPIO_SPI1_MISO));
stm32_configgpio(_PIN_OFF(GPIO_SPI1_MOSI));
stm32_gpiowrite(_PIN_OFF(GPIO_SPI1_SCK), 0);
stm32_gpiowrite(_PIN_OFF(GPIO_SPI1_MISO), 0);
stm32_gpiowrite(_PIN_OFF(GPIO_SPI1_MOSI), 0);
stm32_configgpio(_PIN_OFF(GPIO_SPI1_EXTI_DRDY_PB0));
stm32_configgpio(_PIN_OFF(GPIO_SPI1_EXTI_DRDY_PB1));
stm32_configgpio(_PIN_OFF(GPIO_SPI1_EXTI_DRDY_PB4));
stm32_configgpio(_PIN_OFF(GPIO_SPI1_EXTI_DRDY_PD15));
stm32_gpiowrite(_PIN_OFF(GPIO_SPI1_EXTI_DRDY_PB0), 0);
stm32_gpiowrite(_PIN_OFF(GPIO_SPI1_EXTI_DRDY_PB1), 0);
stm32_gpiowrite(_PIN_OFF(GPIO_SPI1_EXTI_DRDY_PB4), 0);
stm32_gpiowrite(_PIN_OFF(GPIO_SPI1_EXTI_DRDY_PD15), 0);
if (HW_VER_FMUV2 != board_get_hw_version()) {
stm32_configgpio(_PIN_OFF(GPIO_SPI4_CS_PC14));
stm32_gpiowrite(_PIN_OFF(GPIO_SPI4_CS_PC14), 0);
}
if (HW_VER_FMUV3 == board_get_hw_version()) {
stm32_configgpio(_PIN_OFF(GPIO_SPI1_CS_PC1));
stm32_gpiowrite(_PIN_OFF(GPIO_SPI1_CS_PC1), 0);
stm32_configgpio(_PIN_OFF(GPIO_SPI4_NSS_PE4));
stm32_gpiowrite(_PIN_OFF(GPIO_SPI4_NSS_PE4), 0);
stm32_configgpio(_PIN_OFF(GPIO_SPI4_SCK));
stm32_configgpio(_PIN_OFF(GPIO_SPI4_MISO));
stm32_configgpio(_PIN_OFF(GPIO_SPI4_MOSI));
stm32_gpiowrite(_PIN_OFF(GPIO_SPI4_SCK), 0);
stm32_gpiowrite(_PIN_OFF(GPIO_SPI4_MISO), 0);
stm32_gpiowrite(_PIN_OFF(GPIO_SPI4_MOSI), 0);
}
/* set the sensor rail off */
stm32_configgpio(GPIO_VDD_3V3_SENSORS_EN);
stm32_gpiowrite(GPIO_VDD_3V3_SENSORS_EN, 0);
/* wait for the sensor rail to reach GND */
usleep(ms * 1000);
syslog(LOG_DEBUG, "reset done, %d ms\n", ms);
/* re-enable power */
/* switch the sensor rail back on */
stm32_gpiowrite(GPIO_VDD_3V3_SENSORS_EN, 1);
/* wait a bit before starting SPI, different times didn't influence results */
usleep(100);
/* reconfigure the SPI pins */
stm32_configgpio(GPIO_SPI1_SCK);
stm32_configgpio(GPIO_SPI1_MISO);
stm32_configgpio(GPIO_SPI1_MOSI);
if (HW_VER_FMUV3 == board_get_hw_version()) {
stm32_configgpio(GPIO_SPI4_SCK);
stm32_configgpio(GPIO_SPI4_MISO);
stm32_configgpio(GPIO_SPI4_MOSI);
stm32_spi4_initialize();
}
stm32_spi1_initialize();
}
__EXPORT bool px4_spi_bus_external(int bus)
{
if (HW_VER_FMUV3 == board_get_hw_version()) {
/* all FMUv3 2.1 spi buses are internal */
return false;
} else {
if (bus == PX4_SPI_BUS_EXT) {
return true;
}
}
return false;
}
+90
View File
@@ -0,0 +1,90 @@
/****************************************************************************
*
* Copyright (C) 2012 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name PX4 nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#include <nuttx/spi/spi.h>
#include <px4_arch/spi_hw_description.h>
#include <drivers/drv_sensor.h>
constexpr px4_spi_bus_all_hw_t px4_spi_buses_all_hw[BOARD_NUM_SPI_CFG_HW_VERSIONS] = {
initSPIHWVersion(HW_VER_FMUV2, {
initSPIBus(1, {
initSPIDevice(DRV_IMU_DEVTYPE_MPU6000, SPI::CS{GPIO::PortC, GPIO::Pin2}, SPI::DRDY{GPIO::PortD, GPIO::Pin15}),
initSPIDevice(DRV_IMU_DEVTYPE_MPU9250, SPI::CS{GPIO::PortC, GPIO::Pin2}, SPI::DRDY{GPIO::PortD, GPIO::Pin15}),
initSPIDevice(DRV_GYR_DEVTYPE_L3GD20, SPI::CS{GPIO::PortC, GPIO::Pin13}, SPI::DRDY{GPIO::PortB, GPIO::Pin0}),
initSPIDevice(DRV_ACC_DEVTYPE_LSM303D, SPI::CS{GPIO::PortC, GPIO::Pin15}),
initSPIDevice(DRV_BARO_DEVTYPE_MS5611, SPI::CS{GPIO::PortD, GPIO::Pin7}),
}, {GPIO::PortE, GPIO::Pin3}),
initSPIBus(2, {
initSPIDevice(SPIDEV_FLASH(0), SPI::CS{GPIO::PortD, GPIO::Pin10})
}),
initSPIBusExternal(4, {
initSPIConfigExternal(SPI::CS{GPIO::PortC, GPIO::Pin14}),
initSPIConfigExternal(SPI::CS{GPIO::PortE, GPIO::Pin4}),
}),
}),
initSPIHWVersion(HW_VER_FMUV3, {
initSPIBus(1, {
initSPIDevice(DRV_IMU_DEVTYPE_MPU6000, SPI::CS{GPIO::PortC, GPIO::Pin2}, SPI::DRDY{GPIO::PortD, GPIO::Pin15}),
initSPIDevice(DRV_IMU_DEVTYPE_MPU9250, SPI::CS{GPIO::PortC, GPIO::Pin2}, SPI::DRDY{GPIO::PortD, GPIO::Pin15}),
initSPIDevice(DRV_MAG_DEVTYPE_HMC5883, SPI::CS{GPIO::PortC, GPIO::Pin1}), // HMC5983
initSPIDevice(DRV_BARO_DEVTYPE_MS5611, SPI::CS{GPIO::PortD, GPIO::Pin7}),
}, {GPIO::PortE, GPIO::Pin3}),
initSPIBus(2, {
initSPIDevice(SPIDEV_FLASH(0), SPI::CS{GPIO::PortD, GPIO::Pin10})
}),
initSPIBus(4, {
initSPIDevice(DRV_IMU_DEVTYPE_MPU6000, SPI::CS{GPIO::PortE, GPIO::Pin4}),
initSPIDevice(DRV_IMU_DEVTYPE_MPU9250, SPI::CS{GPIO::PortE, GPIO::Pin4}),
initSPIDevice(DRV_GYR_DEVTYPE_L3GD20, SPI::CS{GPIO::PortC, GPIO::Pin13}),
initSPIDevice(DRV_BARO_DEVTYPE_MS5611, SPI::CS{GPIO::PortC, GPIO::Pin14}),
initSPIDevice(DRV_ACC_DEVTYPE_LSM303D, SPI::CS{GPIO::PortC, GPIO::Pin15}),
}),
}),
initSPIHWVersion(HW_VER_FMUV2MINI, {
initSPIBus(1, {
initSPIDevice(DRV_IMU_DEVTYPE_ICM20608, SPI::CS{GPIO::PortC, GPIO::Pin15}, SPI::DRDY{GPIO::PortC, GPIO::Pin14}),
initSPIDevice(DRV_BARO_DEVTYPE_MS5611, SPI::CS{GPIO::PortD, GPIO::Pin7}),
}, {GPIO::PortE, GPIO::Pin3}),
initSPIBus(2, {
initSPIDevice(SPIDEV_FLASH(0), SPI::CS{GPIO::PortD, GPIO::Pin10})
}),
initSPIBusExternal(4, { // unused, but we must at least define it here
}),
}),
// HW_VER_FMUV2X: treat as HW_VER_FMUV2
};
static constexpr bool unused = validateSPIConfig(px4_spi_buses_all_hw);
+3 -1
View File
@@ -33,15 +33,17 @@
add_library(drivers_board
can.c
i2c.cpp
init.c
led.c
spi.c
spi.cpp
timer_config.cpp
usb.c
)
target_link_libraries(drivers_board
PRIVATE
arch_spi
drivers__led # drv_led_start
nuttx_arch # sdio
nuttx_drivers # sdio
+10 -16
View File
@@ -143,25 +143,25 @@
# define SPI_BUS_INIT_MASK_EXT PX4_SPI_BUS_EXTERNAL
#endif /* CONFIG_STM32_SPI4 */
#define SPI_BUS_INIT_MASK (PX4_SPI_BUS_RAMTRON | PX4_SPI_BUS_SENSORS)
#include <drivers/drv_sensor.h>
/* Use these in place of the uint32_t enumeration to select a specific SPI device on SPI1 */
#define PX4_SPIDEV_MPU PX4_MK_SPI_SEL(PX4_SPI_BUS_SENSORS, 4)
#define PX4_SPIDEV_HMC PX4_MK_SPI_SEL(PX4_SPI_BUS_SENSORS, 5)
#define PX4_SPIDEV_LIS PX4_MK_SPI_SEL(PX4_SPI_BUS_SENSORS, 7)
#define PX4_SPIDEV_ICM_20608 PX4_MK_SPI_SEL(PX4_SPI_BUS_SENSORS, 10)
#define PX4_SPIDEV_ICM_20602 PX4_MK_SPI_SEL(PX4_SPI_BUS_SENSORS, 11)
#define PX4_SPIDEV_MPU2 PX4_MK_SPI_SEL(PX4_SPI_BUS_SENSORS, 14)
#define PX4_SPIDEV_MPU PX4_MK_SPI_SEL(0, DRV_IMU_DEVTYPE_MPU6000)
#define PX4_SPIDEV_HMC PX4_MK_SPI_SEL(0, DRV_MAG_DEVTYPE_HMC5883)
#define PX4_SPIDEV_LIS PX4_MK_SPI_SEL(0, DRV_MAG_DEVTYPE_LIS3MDL)
#define PX4_SPIDEV_ICM_20608 PX4_MK_SPI_SEL(0, DRV_IMU_DEVTYPE_ICM20608)
#define PX4_SPIDEV_ICM_20602 PX4_MK_SPI_SEL(0, DRV_IMU_DEVTYPE_ICM20602)
#define PX4_SPIDEV_MPU2 PX4_MK_SPI_SEL(0, DRV_IMU_DEVTYPE_MPU9250)
/**
* 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.
* PX4_MK_SPI_SEL differentiate by adding in PX4_SPI_DEVICE_ID.
*/
#define PX4_SPIDEV_BARO PX4_MK_SPI_SEL(PX4_SPI_BUS_BARO, 3)
#define PX4_SPIDEV_BARO PX4_MK_SPI_SEL(0, DRV_BARO_DEVTYPE_MS5611)
#ifdef CONFIG_STM32_SPI4
# define PX4_SPIDEV_EXTERNAL PX4_MK_SPI_SEL(PX4_SPI_BUS_EXTERNAL, 1)
# define PX4_SPIDEV_EXTERNAL PX4_MK_SPI_SEL(0, 0)
#endif /* CONFIG_STM32_SPI4 */
/* I2C busses. */
@@ -188,7 +188,6 @@
/* Power supply control and monitoring GPIOs. */
#define GPIO_VDD_BRICK_VALID (GPIO_INPUT|GPIO_PULLUP|GPIO_PORTB|GPIO_PIN5)
#define GPIO_VDD_USB_VALID (GPIO_INPUT|GPIO_PULLUP|GPIO_PORTC|GPIO_PIN0)
#define GPIO_VDD_3V3_SENSORS_EN (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_2MHz|GPIO_OUTPUT_CLEAR|GPIO_PORTE|GPIO_PIN3)
/* Tone alarm output. */
#define TONE_ALARM_TIMER 2 /* timer 2 */
@@ -307,14 +306,9 @@ __BEGIN_DECLS
* Description:
* Called to configure SPI chip select GPIO pins for the PX4FMU board.
*
* mask - is bus selection
* 1 - 1 << 0
* 2 - 1 << 1
*
****************************************************************************************************/
extern void stm32_spiinitialize(int mask);
void board_spi_reset(int ms);
extern void stm32_spiinitialize(void);
extern void stm32_usbinitialize(void);
+39
View File
@@ -0,0 +1,39 @@
/****************************************************************************
*
* Copyright (C) 2020 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name PX4 nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#include <px4_arch/i2c_hw_description.h>
constexpr px4_i2c_bus_t px4_i2c_buses[I2C_BUS_MAX_BUS_ITEMS] = {
initI2CBusExternal(1),
};
+4 -18
View File
@@ -148,7 +148,7 @@ __EXPORT void board_on_reset(int status)
px4_arch_configgpio(io_timer_channel_get_gpio_output(i));
}
/**
/*
* On resets invoked from system (not boot) insure we establish a low
* output state (discharge the pins) on PWM pins before they become inputs.
*/
@@ -193,12 +193,6 @@ stm32_boardinitialize(void)
stm32_configgpio(GPIO_VDD_BRICK_VALID);
stm32_configgpio(GPIO_VDD_USB_VALID);
/**
* Start with Sensor voltage off We will enable it
* in board_app_initialize.
*/
stm32_configgpio(GPIO_VDD_3V3_SENSORS_EN);
stm32_configgpio(GPIO_SBUS_INV);
stm32_configgpio(GPIO_SPEKTRUM_PWR_EN);
@@ -209,15 +203,10 @@ stm32_boardinitialize(void)
stm32_configgpio(GPIO_BTN_SAFETY);
stm32_configgpio(GPIO_PPM_IN);
int spi_init_mask = SPI_BUS_INIT_MASK;
#if defined(CONFIG_STM32_SPI4)
/* We have SPI4 is GPIO_8266_GPIO2 PB4 pin 3 Low */
if (stm32_gpioread(GPIO_8266_GPIO2) == 0) {
spi_init_mask |= SPI_BUS_INIT_MASK_EXT;
} else {
if (stm32_gpioread(GPIO_8266_GPIO2) != 0) {
#endif /* CONFIG_STM32_SPI4 */
stm32_configgpio(GPIO_8266_PD);
@@ -228,8 +217,8 @@ stm32_boardinitialize(void)
#endif /* CONFIG_STM32_SPI4 */
// Configure SPI all interfaces GPIO.
stm32_spiinitialize(spi_init_mask);
// Configure SPI all interfaces GPIO & enable power.
stm32_spiinitialize();
// Configure heater GPIO.
stm32_configgpio(GPIO_HEATER_INPUT);
@@ -304,9 +293,6 @@ __EXPORT int board_app_initialize(uintptr_t arg)
led_on(LED_RED);
}
// Power up the sensors.
stm32_gpiowrite(GPIO_VDD_3V3_SENSORS_EN, 1);
// Power down the heater.
stm32_gpiowrite(GPIO_HEATER_OUTPUT, 0);
-316
View File
@@ -1,316 +0,0 @@
/****************************************************************************
*
* Copyright (C) 2012 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name PX4 nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/**
* @file px4fmu_spi.c
*
* Board-specific SPI functions.
*/
/************************************************************************************
* Included Files
************************************************************************************/
#include <px4_platform_common/px4_config.h>
#include <stdint.h>
#include <stdbool.h>
#include <debug.h>
#include <unistd.h>
#include <nuttx/spi/spi.h>
#include <arch/board/board.h>
#include <up_arch.h>
#include <chip.h>
#include <stm32.h>
#include "board_config.h"
/************************************************************************************
* Public Functions
************************************************************************************/
__EXPORT bool board_has_bus(enum board_bus_types type, uint32_t bus)
{
bool rv = true;
switch (type) {
case BOARD_SPI_BUS:
#ifdef CONFIG_STM32_SPI4
rv = bus != PX4_SPI_BUS_EXTERNAL || (stm32_gpioread(GPIO_8266_GPIO2) == 0);
#endif /* CONFIG_STM32_SPI4 */
break;
case BOARD_I2C_BUS:
break;
}
return rv;
}
/************************************************************************************
* Name: stm32_spiinitialize
*
* Description:
* Called to configure SPI chip select GPIO pins for the PX4FMU board.
* mask - is bus selection
* 1 - 1 << 0
* 2 - 1 << 1
*
************************************************************************************/
__EXPORT void stm32_spiinitialize(int mask)
{
#ifdef CONFIG_STM32_SPI1
if (mask & PX4_SPI_BUS_SENSORS) {
stm32_configgpio(GPIO_SPI1_CS_PORTC_PIN2);
stm32_configgpio(GPIO_SPI1_CS_PORTC_PIN15);
stm32_configgpio(GPIO_SPI1_CS_PORTE_PIN15);
stm32_configgpio(GPIO_DRDY_PORTD_PIN15);
stm32_configgpio(GPIO_DRDY_PORTC_PIN14);
stm32_configgpio(GPIO_DRDY_PORTE_PIN12);
}
#endif
#ifdef CONFIG_STM32_SPI2
if (mask & (PX4_SPI_BUS_RAMTRON | PX4_SPI_BUS_BARO)) {
stm32_configgpio(GPIO_SPI2_CS_MS5611);
stm32_configgpio(GPIO_SPI2_CS_FRAM);
}
#endif
#ifdef CONFIG_STM32_SPI4
if (mask & PX4_SPI_BUS_EXTERNAL) {
stm32_configgpio(GPIO_SPI4_CS_1); //add cs
}
#endif /* CONFIG_STM32_SPI4 */
}
__EXPORT void stm32_spi1select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected)
{
/* SPI select is active low, so write !selected to select the device */
switch (devid) {
/* Shared PC2 CS devices */
case PX4_SPIDEV_MPU:
/* Making sure the other peripherals are not selected */
px4_arch_gpiowrite(GPIO_SPI1_CS_PORTC_PIN2, !selected);
px4_arch_gpiowrite(GPIO_SPI1_CS_PORTC_PIN15, 1);
px4_arch_gpiowrite(GPIO_SPI1_CS_PORTE_PIN15, 1);
break;
/* Shared PC15 CS devices */
case PX4_SPIDEV_ICM_20602:
case PX4_SPIDEV_ICM_20608:
case PX4_SPIDEV_MPU2:
/* Making sure the other peripherals are not selected */
px4_arch_gpiowrite(GPIO_SPI1_CS_PORTC_PIN2, 1);
px4_arch_gpiowrite(GPIO_SPI1_CS_PORTC_PIN15, !selected);
px4_arch_gpiowrite(GPIO_SPI1_CS_PORTE_PIN15, 1);
break;
/* Shared PE15 CS devices */
case PX4_SPIDEV_HMC:
case PX4_SPIDEV_LIS:
/* Making sure the other peripherals are not selected */
px4_arch_gpiowrite(GPIO_SPI1_CS_PORTC_PIN2, 1);
px4_arch_gpiowrite(GPIO_SPI1_CS_PORTC_PIN15, 1);
px4_arch_gpiowrite(GPIO_SPI1_CS_PORTE_PIN15, !selected);
break;
default:
break;
}
}
__EXPORT uint8_t stm32_spi1status(FAR struct spi_dev_s *dev, uint32_t devid)
{
return SPI_STATUS_PRESENT;
}
#ifdef CONFIG_STM32_SPI2
__EXPORT void stm32_spi2select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected)
{
/* SPI select is active low, so write !selected to select the device */
switch (devid) {
case SPIDEV_FLASH(0):
/* Making sure the other peripherals are not selected */
stm32_gpiowrite(GPIO_SPI2_CS_MS5611, 1);
stm32_gpiowrite(GPIO_SPI2_CS_FRAM, !selected);
break;
case PX4_SPIDEV_BARO:
/* Making sure the other peripherals are not selected */
stm32_gpiowrite(GPIO_SPI2_CS_FRAM, 1);
stm32_gpiowrite(GPIO_SPI2_CS_MS5611, !selected);
break;
default:
break;
}
}
__EXPORT uint8_t stm32_spi2status(FAR struct spi_dev_s *dev, uint32_t devid)
{
/* FRAM is always present */
return SPI_STATUS_PRESENT;
}
#endif
#ifdef CONFIG_STM32_SPI4
__EXPORT void stm32_spi4select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected)
{
if (devid == PX4_SPIDEV_EXTERNAL && stm32_gpioread(GPIO_8266_GPIO2) == 0) {
stm32_gpiowrite(GPIO_SPI4_CS_1, !selected); // add cs
}
}
__EXPORT uint8_t stm32_spi4status(FAR struct spi_dev_s *dev, uint32_t devid)
{
return SPI_STATUS_PRESENT;
}
#endif /* CONFIG_STM32_SPI4 */
__EXPORT void board_spi_reset(int ms)
{
/* disable SPI bus 1 DRDY */
stm32_configgpio(GPIO_DRDY_OFF_PORTD_PIN15);
stm32_configgpio(GPIO_DRDY_OFF_PORTC_PIN14);
stm32_configgpio(GPIO_DRDY_OFF_PORTE_PIN12);
stm32_gpiowrite(GPIO_DRDY_OFF_PORTD_PIN15, 0);
stm32_gpiowrite(GPIO_DRDY_OFF_PORTC_PIN14, 0);
stm32_gpiowrite(GPIO_DRDY_OFF_PORTE_PIN12, 0);
/* disable SPI bus 1 CS */
stm32_configgpio(GPIO_SPI1_CS_OFF_PORTC_PIN2);
stm32_configgpio(GPIO_SPI1_CS_OFF_PORTC_PIN15);
stm32_configgpio(GPIO_SPI1_CS_OFF_PORTE_PIN15);
stm32_gpiowrite(GPIO_SPI1_CS_OFF_PORTC_PIN2, 0);
stm32_gpiowrite(GPIO_SPI1_CS_OFF_PORTC_PIN15, 0);
stm32_gpiowrite(GPIO_SPI1_CS_OFF_PORTE_PIN15, 0);
/* disable SPI bus 1*/
stm32_configgpio(GPIO_SPI1_SCK_OFF);
stm32_configgpio(GPIO_SPI1_MISO_OFF);
stm32_configgpio(GPIO_SPI1_MOSI_OFF);
stm32_gpiowrite(GPIO_SPI1_SCK_OFF, 0);
stm32_gpiowrite(GPIO_SPI1_MISO_OFF, 0);
stm32_gpiowrite(GPIO_SPI1_MOSI_OFF, 0);
#ifdef CONFIG_STM32_SPI4
/* disable SPI bus 4*/
if (stm32_gpioread(GPIO_8266_GPIO2) == 0) {
stm32_configgpio(GPIO_SPI4_SCK_OFF);
stm32_configgpio(GPIO_SPI4_MISO_OFF);
stm32_configgpio(GPIO_SPI4_MOSI_OFF);
stm32_gpiowrite(GPIO_SPI4_SCK_OFF, 0);
stm32_gpiowrite(GPIO_SPI4_MISO_OFF, 0);
stm32_gpiowrite(GPIO_SPI4_MOSI_OFF, 0);
}
#endif /* CONFIG_STM32_SPI4 */
/* N.B we do not have control over the SPI 2 buss powered devices
* so the the ms5611 is not resetable.
*/
/* set the sensor rail off (default) */
stm32_configgpio(GPIO_VDD_3V3_SENSORS_EN);
#ifdef CONFIG_STM32_SPI4
if (stm32_gpioread(GPIO_8266_GPIO2) == 0) {
/* set the periph rail off (default) for SPI4 */
stm32_configgpio(GPIO_PERIPH_3V3_EN);
}
#endif /* CONFIG_STM32_SPI4 */
/* wait for the sensor rail to reach GND */
usleep(ms * 1000);
syslog(LOG_DEBUG, "reset done, %d ms\n", ms);
/* re-enable power */
#ifdef CONFIG_STM32_SPI4
if (stm32_gpioread(GPIO_8266_GPIO2) == 0) {
/* switch the periph rail back on */
stm32_gpiowrite(GPIO_PERIPH_3V3_EN, 1);
}
#endif /* CONFIG_STM32_SPI4 */
/* switch the sensor rail back on */
stm32_gpiowrite(GPIO_VDD_3V3_SENSORS_EN, 1);
/* wait a bit before starting SPI, different times didn't influence results */
usleep(100);
stm32_spiinitialize(PX4_SPI_BUS_SENSORS);
stm32_configgpio(GPIO_SPI1_SCK);
stm32_configgpio(GPIO_SPI1_MISO);
stm32_configgpio(GPIO_SPI1_MOSI);
#ifdef CONFIG_STM32_SPI4
if (stm32_gpioread(GPIO_8266_GPIO2) == 0) {
stm32_spiinitialize(PX4_SPI_BUS_EXTERNAL);
stm32_configgpio(GPIO_SPI4_SCK);
stm32_configgpio(GPIO_SPI4_MISO);
stm32_configgpio(GPIO_SPI4_MOSI);
}
#endif /* CONFIG_STM32_SPI4 */
}
+76
View File
@@ -0,0 +1,76 @@
/****************************************************************************
*
* Copyright (C) 2020 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name PX4 nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#include <px4_arch/spi_hw_description.h>
#include <drivers/drv_sensor.h>
#include <nuttx/spi/spi.h>
constexpr px4_spi_bus_t px4_spi_buses[SPI_BUS_MAX_BUS_ITEMS] = {
initSPIBus(1, {
initSPIDevice(DRV_IMU_DEVTYPE_MPU9250, SPI::CS{GPIO::PortC, GPIO::Pin2}, SPI::DRDY{GPIO::PortD, GPIO::Pin15}),
initSPIDevice(DRV_IMU_DEVTYPE_ICM20602, SPI::CS{GPIO::PortC, GPIO::Pin15}, SPI::DRDY{GPIO::PortC, GPIO::Pin14}),
initSPIDevice(DRV_IMU_DEVTYPE_ICM20608, SPI::CS{GPIO::PortC, GPIO::Pin15}, SPI::DRDY{GPIO::PortC, GPIO::Pin14}),
initSPIDevice(DRV_MAG_DEVTYPE_HMC5883, SPI::CS{GPIO::PortE, GPIO::Pin15}, SPI::DRDY{GPIO::PortE, GPIO::Pin12}), // hmc5983
initSPIDevice(DRV_MAG_DEVTYPE_LIS3MDL, SPI::CS{GPIO::PortE, GPIO::Pin15}, SPI::DRDY{GPIO::PortE, GPIO::Pin12}),
}, {GPIO::PortE, GPIO::Pin3}),
initSPIBus(2, {
initSPIDevice(SPIDEV_FLASH(0), SPI::CS{GPIO::PortD, GPIO::Pin10}),
initSPIDevice(DRV_BARO_DEVTYPE_MS5611, SPI::CS{GPIO::PortD, GPIO::Pin7}),
}),
initSPIBusExternal(4, {
initSPIConfigExternal(SPI::CS{GPIO::PortA, GPIO::Pin8}),
}),
};
static constexpr bool unused = validateSPIConfig(px4_spi_buses);
__EXPORT bool board_has_bus(enum board_bus_types type, uint32_t bus)
{
bool rv = true;
switch (type) {
case BOARD_SPI_BUS:
#ifdef CONFIG_STM32_SPI4
rv = bus != 4 || (stm32_gpioread(GPIO_8266_GPIO2) == 0);
#endif /* CONFIG_STM32_SPI4 */
break;
case BOARD_I2C_BUS:
break;
default: break;
}
return rv;
}
+3 -1
View File
@@ -33,14 +33,16 @@
add_library(drivers_board
can.c
i2c.cpp
init.c
led.c
spi.c
spi.cpp
timer_config.cpp
usb.c
)
target_link_libraries(drivers_board
PRIVATE
arch_spi
drivers__led # drv_led_start
nuttx_arch # sdio
nuttx_drivers # sdio
+10 -11
View File
@@ -162,16 +162,17 @@
/* Use these in place of the uint32_t enumeration to select a specific SPI device on SPI1 */
#define PX4_SPIDEV_BARO PX4_MK_SPI_SEL(PX4_SPI_BUS_SENSORS, 1)
#define PX4_SPIDEV_MPU PX4_MK_SPI_SEL(PX4_SPI_BUS_SENSORS, 2)
#define PX4_SPIDEV_HMC PX4_MK_SPI_SEL(PX4_SPI_BUS_SENSORS, 3)
#define PX4_SPIDEV_LIS PX4_MK_SPI_SEL(PX4_SPI_BUS_SENSORS, 4)
#define PX4_SPIDEV_EEPROM PX4_MK_SPI_SEL(PX4_SPI_BUS_SENSORS, 5)
#define PX4_SPIDEV_ICM_20608 PX4_MK_SPI_SEL(PX4_SPI_BUS_SENSORS, 6)
#define PX4_SPIDEV_ICM_20602 PX4_MK_SPI_SEL(PX4_SPI_BUS_SENSORS, 7)
#include <drivers/drv_sensor.h>
#define PX4_SPIDEV_BARO PX4_MK_SPI_SEL(0, DRV_BARO_DEVTYPE_MS5611)
#define PX4_SPIDEV_MPU PX4_MK_SPI_SEL(0, DRV_IMU_DEVTYPE_MPU9250)
#define PX4_SPIDEV_HMC PX4_MK_SPI_SEL(0, DRV_MAG_DEVTYPE_HMC5883)
#define PX4_SPIDEV_LIS PX4_MK_SPI_SEL(0, DRV_MAG_DEVTYPE_LIS3MDL)
#define PX4_SPIDEV_EEPROM PX4_MK_SPI_SEL(0, DRV_DEVTYPE_UNUSED)
#define PX4_SPIDEV_ICM_20608 PX4_MK_SPI_SEL(0, DRV_IMU_DEVTYPE_ICM20608)
#define PX4_SPIDEV_ICM_20602 PX4_MK_SPI_SEL(0, DRV_IMU_DEVTYPE_ICM20602)
#define PX4_SPIDEV_EXT0 PX4_MK_SPI_SEL(PX4_SPI_BUS_EXT0, 1)
#define PX4_SPIDEV_EXT1 PX4_MK_SPI_SEL(PX4_SPI_BUS_EXT1, 1)
#define PX4_SPIDEV_EXT0 PX4_MK_SPI_SEL(0, 0)
#define PX4_SPIDEV_EXT1 PX4_MK_SPI_SEL(0, 1)
#define PX4_SPIDEV_RM_EXT PX4_SPIDEV_EXT0
@@ -218,7 +219,6 @@
#define GPIO_nVDD_BRICK2_VALID (GPIO_INPUT|GPIO_PULLUP|GPIO_PORTG|GPIO_PIN5)
#define BOARD_NUMBER_BRICKS 2
#define GPIO_nVDD_USB_VALID (GPIO_INPUT|GPIO_PULLUP|GPIO_PORTC|GPIO_PIN0)
#define GPIO_VDD_3V3_SENSORS_EN (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_2MHz|GPIO_OUTPUT_CLEAR|GPIO_PORTE|GPIO_PIN3)
#define GPIO_VDD_3V3_PERIPH_EN (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_2MHz|GPIO_OUTPUT_SET|GPIO_PORTC|GPIO_PIN5)
#define GPIO_VDD_5V_PERIPH_EN (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_2MHz|GPIO_OUTPUT_CLEAR|GPIO_PORTG|GPIO_PIN10)
#define GPIO_VDD_5V_HIPOWER_EN (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_2MHz|GPIO_OUTPUT_CLEAR|GPIO_PORTF|GPIO_PIN4)
@@ -316,7 +316,6 @@ __BEGIN_DECLS
****************************************************************************************************/
extern void stm32_spiinitialize(void);
void board_spi_reset(int ms);
extern void stm32_usbinitialize(void);
+40
View File
@@ -0,0 +1,40 @@
/****************************************************************************
*
* Copyright (C) 2020 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name PX4 nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#include <px4_arch/i2c_hw_description.h>
constexpr px4_i2c_bus_t px4_i2c_buses[I2C_BUS_MAX_BUS_ITEMS] = {
initI2CBusInternal(1),
initI2CBusExternal(2),
};
+14 -14
View File
@@ -110,7 +110,7 @@ __EXPORT void board_peripheral_reset(int ms)
{
/* set the peripheral and sensor rails off */
stm32_gpiowrite(GPIO_VDD_3V3_PERIPH_EN, 0);
stm32_gpiowrite(GPIO_VDD_3V3_SENSORS_EN, 0);
board_control_spi_sensors_power(false, 0xffff);
stm32_gpiowrite(GPIO_VDD_5V_PERIPH_EN, 1);
stm32_gpiowrite(GPIO_VDD_5V_HIPOWER_EN, 1);
@@ -128,7 +128,7 @@ __EXPORT void board_peripheral_reset(int ms)
/* switch the peripheral rail back on */
// stm32_gpiowrite(GPIO_SPEKTRUM_PWR_EN, last);
stm32_gpiowrite(GPIO_VDD_3V3_PERIPH_EN, 1);
stm32_gpiowrite(GPIO_VDD_3V3_SENSORS_EN, 1);
board_control_spi_sensors_power(true, 0xffff);
stm32_gpiowrite(GPIO_VDD_5V_PERIPH_EN, 0);
stm32_gpiowrite(GPIO_VDD_5V_HIPOWER_EN, 0);
}
@@ -191,7 +191,7 @@ stm32_boardinitialize(void)
board_autoled_initialize();
/* Start with Power off */
stm32_configgpio(GPIO_VDD_3V3_SENSORS_EN);
board_control_spi_sensors_power_configgpio();
/* configure ADC pins */
stm32_configgpio(GPIO_ADC1_IN2); /* BATT_VOLTAGE_SENS */
@@ -270,13 +270,13 @@ static struct sdio_dev_s *sdio;
__EXPORT int board_app_initialize(uintptr_t arg)
{
/* Bring up the Sensor power */
stm32_gpiowrite(GPIO_VDD_3V3_SENSORS_EN, 1);
/* Now it is ok to drvie the pins high
* so configure SPI CPIO */
// the temp cal eeprom is unused, so disable the CS from here
stm32_configgpio(GPIO_SPI_CS_TEMPCAL_EEPROM);
stm32_gpiowrite(GPIO_SPI_CS_TEMPCAL_EEPROM, 1);
stm32_spiinitialize();
px4_platform_init();
@@ -316,10 +316,10 @@ __EXPORT int board_app_initialize(uintptr_t arg)
/* Configure SPI-based devices */
spi1 = stm32_spibus_initialize(PX4_SPI_BUS_SENSORS);
spi1 = stm32_spibus_initialize(1);
if (!spi1) {
syslog(LOG_ERR, "[boot] FAILED to initialize SPI port %d\n", PX4_SPI_BUS_SENSORS);
syslog(LOG_ERR, "[boot] FAILED to initialize SPI port %d\n", 1);
led_on(LED_RED);
return -ENODEV;
}
@@ -337,10 +337,10 @@ __EXPORT int board_app_initialize(uintptr_t arg)
/* Get the SPI port for the FRAM */
spi2 = stm32_spibus_initialize(PX4_SPI_BUS_RAMTRON);
spi2 = stm32_spibus_initialize(2);
if (!spi2) {
syslog(LOG_ERR, "[boot] FAILED to initialize SPI port %d\n", PX4_SPI_BUS_RAMTRON);
syslog(LOG_ERR, "[boot] FAILED to initialize SPI port %d\n", 2);
led_on(LED_RED);
return -ENODEV;
}
@@ -356,10 +356,10 @@ __EXPORT int board_app_initialize(uintptr_t arg)
/* Configure SPI 5-based devices */
spi5 = stm32_spibus_initialize(PX4_SPI_BUS_EXT0);
spi5 = stm32_spibus_initialize(5);
if (!spi5) {
syslog(LOG_ERR, "[boot] FAILED to initialize SPI port %d\n", PX4_SPI_BUS_EXT0);
syslog(LOG_ERR, "[boot] FAILED to initialize SPI port %d\n", 5);
led_on(LED_RED);
return -ENODEV;
}
@@ -372,10 +372,10 @@ __EXPORT int board_app_initialize(uintptr_t arg)
/* Configure SPI 6-based devices */
spi6 = stm32_spibus_initialize(PX4_SPI_BUS_EXT1);
spi6 = stm32_spibus_initialize(6);
if (!spi6) {
syslog(LOG_ERR, "[boot] FAILED to initialize SPI port %d\n", PX4_SPI_BUS_EXT1);
syslog(LOG_ERR, "[boot] FAILED to initialize SPI port %d\n", 6);
led_on(LED_RED);
return -ENODEV;
}
-283
View File
@@ -1,283 +0,0 @@
/****************************************************************************
*
* Copyright (C) 2012 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name PX4 nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/**
* @file px4fmu_spi.c
*
* Board-specific SPI functions.
*/
/************************************************************************************
* Included Files
************************************************************************************/
#include <px4_platform_common/px4_config.h>
#include <stdint.h>
#include <stdbool.h>
#include <debug.h>
#include <unistd.h>
#include <nuttx/spi/spi.h>
#include <arch/board/board.h>
#include <up_arch.h>
#include <chip.h>
#include <stm32.h>
#include "board_config.h"
/************************************************************************************
* Public Functions
************************************************************************************/
/************************************************************************************
* Name: stm32_spiinitialize
*
* Description:
* Called to configure SPI chip select GPIO pins for the PX4FMU board.
*
************************************************************************************/
__EXPORT void stm32_spiinitialize(void)
{
#ifdef CONFIG_STM32_SPI1
stm32_configgpio(GPIO_SPI_CS_MPU9250);
stm32_configgpio(GPIO_SPI_CS_LIS3MDL);
stm32_configgpio(GPIO_SPI_CS_MS5611);
stm32_configgpio(GPIO_SPI_CS_ICM_2060X);
stm32_configgpio(GPIO_SPI_CS_TEMPCAL_EEPROM);
stm32_configgpio(GPIO_DRDY_MPU9250);
stm32_configgpio(GPIO_DRDY_LIS3MDL);
stm32_configgpio(GPIO_DRDY_ICM_2060X);
#endif
#ifdef CONFIG_STM32_SPI2
stm32_configgpio(GPIO_SPI_CS_FRAM);
#endif
#ifdef CONFIG_STM32_SPI5
stm32_configgpio(GPIO_SPI5_CS);
#endif
#ifdef CONFIG_STM32_SPI6
stm32_configgpio(GPIO_SPI6_CS);
#endif
}
__EXPORT void stm32_spi1select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected)
{
/* SPI select is active low, so write !selected to select the device */
switch (devid) {
case PX4_SPIDEV_ICM_20602:
// FALLTHROUGH
case PX4_SPIDEV_ICM_20608:
/* Making sure the other peripherals are not selected */
stm32_gpiowrite(GPIO_SPI_CS_MPU9250, 1);
stm32_gpiowrite(GPIO_SPI_CS_LIS3MDL, 1);
stm32_gpiowrite(GPIO_SPI_CS_MS5611, 1);
stm32_gpiowrite(GPIO_SPI_CS_ICM_2060X, !selected);
stm32_gpiowrite(GPIO_SPI_CS_TEMPCAL_EEPROM, 1);
break;
case PX4_SPIDEV_BARO:
/* Making sure the other peripherals are not selected */
stm32_gpiowrite(GPIO_SPI_CS_MPU9250, 1);
stm32_gpiowrite(GPIO_SPI_CS_LIS3MDL, 1);
stm32_gpiowrite(GPIO_SPI_CS_MS5611, !selected);
stm32_gpiowrite(GPIO_SPI_CS_ICM_2060X, 1);
stm32_gpiowrite(GPIO_SPI_CS_TEMPCAL_EEPROM, 1);
break;
case PX4_SPIDEV_LIS:
/* Making sure the other peripherals are not selected */
stm32_gpiowrite(GPIO_SPI_CS_MPU9250, 1);
stm32_gpiowrite(GPIO_SPI_CS_LIS3MDL, !selected);
stm32_gpiowrite(GPIO_SPI_CS_MS5611, 1);
stm32_gpiowrite(GPIO_SPI_CS_ICM_2060X, 1);
stm32_gpiowrite(GPIO_SPI_CS_TEMPCAL_EEPROM, 1);
break;
case PX4_SPIDEV_MPU:
/* Making sure the other peripherals are not selected */
stm32_gpiowrite(GPIO_SPI_CS_MPU9250, !selected);
stm32_gpiowrite(GPIO_SPI_CS_LIS3MDL, 1);
stm32_gpiowrite(GPIO_SPI_CS_MS5611, 1);
stm32_gpiowrite(GPIO_SPI_CS_ICM_2060X, 1);
stm32_gpiowrite(GPIO_SPI_CS_TEMPCAL_EEPROM, 1);
break;
case PX4_SPIDEV_EEPROM:
/* Making sure the other peripherals are not selected */
stm32_gpiowrite(GPIO_SPI_CS_MPU9250, 1);
stm32_gpiowrite(GPIO_SPI_CS_LIS3MDL, 1);
stm32_gpiowrite(GPIO_SPI_CS_MS5611, 1);
stm32_gpiowrite(GPIO_SPI_CS_ICM_2060X, 1);
stm32_gpiowrite(GPIO_SPI_CS_TEMPCAL_EEPROM, !selected);
break;
default:
break;
}
}
__EXPORT uint8_t stm32_spi1status(FAR struct spi_dev_s *dev, uint32_t devid)
{
return SPI_STATUS_PRESENT;
}
#ifdef CONFIG_STM32_SPI2
__EXPORT void stm32_spi2select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected)
{
stm32_gpiowrite(GPIO_SPI_CS_FRAM, !selected);
}
__EXPORT uint8_t stm32_spi2status(FAR struct spi_dev_s *dev, uint32_t devid)
{
/* FRAM is always present */
return SPI_STATUS_PRESENT;
}
#endif
/************************************************************************************
* Name: stm32_spi5select and stm32_spi5status
*
* Description:
* Called by stm32 spi driver on bus 5.
*
************************************************************************************/
#ifdef CONFIG_STM32_SPI5
__EXPORT void stm32_spi5select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected)
{
stm32_gpiowrite(GPIO_SPI5_CS, !selected);
}
__EXPORT uint8_t stm32_spi5status(FAR struct spi_dev_s *dev, uint32_t devid)
{
return SPI_STATUS_PRESENT;
}
#endif
/************************************************************************************
* Name: stm32_spi6select and stm32_spi6status
*
* Description:
* Called by stm32 spi driver on bus 6.
*
************************************************************************************/
#ifdef CONFIG_STM32_SPI6
__EXPORT void stm32_spi6select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected)
{
stm32_gpiowrite(GPIO_SPI6_CS, !selected);
}
__EXPORT uint8_t stm32_spi6status(FAR struct spi_dev_s *dev, uint32_t devid)
{
return SPI_STATUS_PRESENT;
}
#endif
__EXPORT void board_spi_reset(int ms)
{
/* disable SPI bus */
stm32_configgpio(GPIO_SPI_CS_OFF_MPU9250);
stm32_configgpio(GPIO_SPI_CS_OFF_LIS3MDL);
stm32_configgpio(GPIO_SPI_CS_OFF_MS5611);
stm32_configgpio(GPIO_SPI_CS_OFF_ICM_2060X);
stm32_configgpio(GPIO_SPI_CS_TEMPCAL_EEPROM);
stm32_gpiowrite(GPIO_SPI_CS_OFF_MPU9250, 0);
stm32_gpiowrite(GPIO_SPI_CS_OFF_LIS3MDL, 0);
stm32_gpiowrite(GPIO_SPI_CS_OFF_MS5611, 0);
stm32_gpiowrite(GPIO_SPI_CS_OFF_ICM_2060X, 0);
stm32_gpiowrite(GPIO_SPI_CS_TEMPCAL_EEPROM, 0);
stm32_configgpio(GPIO_SPI1_SCK_OFF);
stm32_configgpio(GPIO_SPI1_MISO_OFF);
stm32_configgpio(GPIO_SPI1_MOSI_OFF);
stm32_gpiowrite(GPIO_SPI1_SCK_OFF, 0);
stm32_gpiowrite(GPIO_SPI1_MISO_OFF, 0);
stm32_gpiowrite(GPIO_SPI1_MOSI_OFF, 0);
stm32_configgpio(GPIO_DRDY_OFF_MPU9250);
stm32_configgpio(GPIO_DRDY_OFF_LIS3MDL);
stm32_configgpio(GPIO_DRDY_OFF_ICM_2060X);
stm32_gpiowrite(GPIO_DRDY_OFF_MPU9250, 0);
stm32_gpiowrite(GPIO_DRDY_OFF_LIS3MDL, 0);
stm32_gpiowrite(GPIO_DRDY_OFF_ICM_2060X, 0);
/* set the sensor rail off */
stm32_configgpio(GPIO_VDD_3V3_SENSORS_EN);
stm32_gpiowrite(GPIO_VDD_3V3_SENSORS_EN, 0);
/* wait for the sensor rail to reach GND */
usleep(ms * 1000);
syslog(LOG_DEBUG, "reset done, %d ms\n", ms);
/* re-enable power */
/* switch the sensor rail back on */
stm32_gpiowrite(GPIO_VDD_3V3_SENSORS_EN, 1);
/* wait a bit before starting SPI, different times didn't influence results */
usleep(100);
/* reconfigure the SPI pins */
#ifdef CONFIG_STM32_SPI1
stm32_configgpio(GPIO_SPI_CS_MPU9250);
stm32_configgpio(GPIO_SPI_CS_LIS3MDL);
stm32_configgpio(GPIO_SPI_CS_MS5611);
stm32_configgpio(GPIO_SPI_CS_ICM_2060X);
stm32_configgpio(GPIO_SPI_CS_TEMPCAL_EEPROM);
stm32_configgpio(GPIO_SPI1_SCK);
stm32_configgpio(GPIO_SPI1_MISO);
stm32_configgpio(GPIO_SPI1_MOSI);
/* bring up the EXTI pins again */
stm32_configgpio(GPIO_DRDY_MPU9250);
stm32_configgpio(GPIO_DRDY_LIS3MDL);
stm32_configgpio(GPIO_DRDY_ICM_2060X);
#endif
}
+56
View File
@@ -0,0 +1,56 @@
/****************************************************************************
*
* Copyright (C) 2012 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name PX4 nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#include <px4_arch/spi_hw_description.h>
#include <drivers/drv_sensor.h>
#include <nuttx/spi/spi.h>
constexpr px4_spi_bus_t px4_spi_buses[SPI_BUS_MAX_BUS_ITEMS] = {
initSPIBus(1, {
initSPIDevice(DRV_IMU_DEVTYPE_MPU9250, SPI::CS{GPIO::PortC, GPIO::Pin2}, SPI::DRDY{GPIO::PortD, GPIO::Pin15}),
initSPIDevice(DRV_IMU_DEVTYPE_ICM20602, SPI::CS{GPIO::PortC, GPIO::Pin15}, SPI::DRDY{GPIO::PortC, GPIO::Pin14}),
initSPIDevice(DRV_IMU_DEVTYPE_ICM20608, SPI::CS{GPIO::PortC, GPIO::Pin15}, SPI::DRDY{GPIO::PortC, GPIO::Pin14}),
initSPIDevice(DRV_MAG_DEVTYPE_LIS3MDL, SPI::CS{GPIO::PortE, GPIO::Pin15}, SPI::DRDY{GPIO::PortE, GPIO::Pin12}),
initSPIDevice(DRV_BARO_DEVTYPE_MS5611, SPI::CS{GPIO::PortD, GPIO::Pin7}),
}, {GPIO::PortE, GPIO::Pin3}),
initSPIBus(2, {
initSPIDevice(SPIDEV_FLASH(0), SPI::CS{GPIO::PortD, GPIO::Pin10}),
}),
initSPIBusExternal(5, {
initSPIConfigExternal(SPI::CS{GPIO::PortF, GPIO::Pin6}),
}),
initSPIBusExternal(6, {
initSPIConfigExternal(SPI::CS{GPIO::PortG, GPIO::Pin11}),
}),
};
+2
View File
@@ -33,6 +33,7 @@
add_library(drivers_board
can.c
i2c.cpp
init.c
led.c
manifest.c
@@ -46,6 +47,7 @@ add_dependencies(drivers_board arch_board_hw_info)
target_link_libraries(drivers_board
PRIVATE
arch_board_hw_info
arch_spi
drivers__led # drv_led_start
nuttx_arch # sdio
nuttx_drivers # sdio
+8 -12
View File
@@ -182,18 +182,19 @@
/* v BEGIN Legacy SPI defines TODO: fix this with enumeration */
#define PX4_SPI_BUS_RAMTRON PX4_SPI_BUS_MEMORY
/* ^ END Legacy SPI defines TODO: fix this with enumeration */
#include <drivers/drv_sensor.h>
#define PX4_SPIDEV_ICM_20689 PX4_MK_SPI_SEL(PX4_SPI_BUS_SENSORS,0)
#define PX4_SPIDEV_ICM_20602 PX4_MK_SPI_SEL(PX4_SPI_BUS_SENSORS,1)
#define PX4_SPIDEV_BMI055_GYR PX4_MK_SPI_SEL(PX4_SPI_BUS_SENSORS,2)
#define PX4_SPIDEV_BMI055_ACC PX4_MK_SPI_SEL(PX4_SPI_BUS_SENSORS,3)
#define PX4_SPIDEV_AUX_MEM PX4_MK_SPI_SEL(PX4_SPI_BUS_SENSORS,4)
#define PX4_SPIDEV_ICM_20689 PX4_MK_SPI_SEL(0,DRV_IMU_DEVTYPE_ICM20689)
#define PX4_SPIDEV_ICM_20602 PX4_MK_SPI_SEL(0,DRV_IMU_DEVTYPE_ICM20602)
#define PX4_SPIDEV_BMI055_GYR PX4_MK_SPI_SEL(0,DRV_GYR_DEVTYPE_BMI055)
#define PX4_SPIDEV_BMI055_ACC PX4_MK_SPI_SEL(0,DRV_ACC_DEVTYPE_BMI055)
#define PX4_SPIDEV_AUX_MEM PX4_MK_SPI_SEL(0,4)
#define PX4_SENSOR_BUS_CS_GPIO {GPIO_SPI1_CS1_ICM20689, GPIO_SPI1_CS2_ICM20602, GPIO_SPI1_CS3_BMI055_GYRO, GPIO_SPI1_CS4_BMI055_ACC, GPIO_SPI1_CS5_AUX_MEM}
#define PX4_SPIDEV_MEMORY PX4_MK_SPI_SEL(PX4_SPI_BUS_MEMORY,0)
#define PX4_SPIDEV_MEMORY SPIDEV_FLASH(0)
#define PX4_MEMORY_BUS_CS_GPIO {GPIO_SPI2_CS_FRAM}
#define PX4_SPIDEV_BARO PX4_MK_SPI_SEL(PX4_SPI_BUS_BARO,0)
#define PX4_SPIDEV_BARO PX4_MK_SPI_SEL(0,DRV_BARO_DEVTYPE_MS5611)
#define PX4_SPIDEV_SPI4_CS2 PX4_MK_SPI_SEL(PX4_SPI_BUS_BARO,1)
#define PX4_BARO_BUS_CS_GPIO {GPIO_SPI4_CS1_MS5611, GPIO_SPI4_CS2}
@@ -384,7 +385,6 @@
#define GPIO_nVDD_5V_PERIPH_OC /* PE15 */ (GPIO_INPUT |GPIO_FLOAT|GPIO_PORTE|GPIO_PIN15)
#define GPIO_nVDD_5V_HIPOWER_EN /* PF12 */ (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_2MHz|GPIO_OUTPUT_SET|GPIO_PORTF|GPIO_PIN12)
#define GPIO_nVDD_5V_HIPOWER_OC /* PG13 */ (GPIO_INPUT |GPIO_FLOAT|GPIO_PORTF|GPIO_PIN13)
#define GPIO_VDD_3V3_SENSORS_EN /* PE3 */ (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_2MHz|GPIO_OUTPUT_CLEAR|GPIO_PORTE|GPIO_PIN3)
#define GPIO_VDD_3V3_SPEKTRUM_POWER_EN /* PE4 */ (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_2MHz|GPIO_OUTPUT_CLEAR|GPIO_PORTE|GPIO_PIN4)
#define GPIO_VDD_5V_RC_EN /* PG5 */ (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_2MHz|GPIO_OUTPUT_CLEAR|GPIO_PORTG|GPIO_PIN5)
#define GPIO_VDD_5V_WIFI_EN /* PG6 */ (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_2MHz|GPIO_OUTPUT_CLEAR|GPIO_PORTG|GPIO_PIN5)
@@ -395,7 +395,6 @@
#define VDD_5V_PERIPH_EN(on_true) px4_arch_gpiowrite(GPIO_nVDD_5V_PERIPH_EN, !(on_true))
#define VDD_5V_HIPOWER_EN(on_true) px4_arch_gpiowrite(GPIO_nVDD_5V_HIPOWER_EN, !(on_true))
#define VDD_3V3_SENSORS_EN(on_true) px4_arch_gpiowrite(GPIO_VDD_3V3_SENSORS_EN, (on_true))
#define VDD_3V3_SPEKTRUM_POWER_EN(on_true) px4_arch_gpiowrite(GPIO_VDD_3V3_SPEKTRUM_POWER_EN, (on_true))
#define READ_VDD_3V3_SPEKTRUM_POWER_EN() px4_arch_gpioread(GPIO_VDD_3V3_SPEKTRUM_POWER_EN)
#define VDD_5V_RC_EN(on_true) px4_arch_gpiowrite(GPIO_VDD_5V_RC_EN, (on_true))
@@ -575,7 +574,6 @@
GPIO_nVDD_5V_PERIPH_OC, \
GPIO_nVDD_5V_HIPOWER_EN, \
GPIO_nVDD_5V_HIPOWER_OC, \
GPIO_VDD_3V3_SENSORS_EN, \
GPIO_VDD_3V3_SPEKTRUM_POWER_EN, \
GPIO_VDD_5V_RC_EN, \
GPIO_VDD_5V_WIFI_EN, \
@@ -629,8 +627,6 @@ int stm32_sdio_initialize(void);
extern void stm32_spiinitialize(void);
void board_spi_reset(int ms);
extern void stm32_usbinitialize(void);
extern void board_peripheral_reset(int ms);
+42
View File
@@ -0,0 +1,42 @@
/****************************************************************************
*
* Copyright (C) 2020 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name PX4 nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#include <px4_arch/i2c_hw_description.h>
constexpr px4_i2c_bus_t px4_i2c_buses[I2C_BUS_MAX_BUS_ITEMS] = {
initI2CBusExternal(1),
initI2CBusExternal(2),
initI2CBusInternal(3),
initI2CBusExternal(4),
};
+8 -7
View File
@@ -105,7 +105,7 @@ __EXPORT void board_peripheral_reset(int ms)
/* set the peripheral rails off */
VDD_5V_PERIPH_EN(false);
VDD_3V3_SENSORS_EN(false);
board_control_spi_sensors_power(false, 0xffff);
bool last = READ_VDD_3V3_SPEKTRUM_POWER_EN();
/* Keep Spektum on to discharge rail*/
@@ -119,7 +119,7 @@ __EXPORT void board_peripheral_reset(int ms)
/* switch the peripheral rail back on */
VDD_3V3_SPEKTRUM_POWER_EN(last);
VDD_3V3_SENSORS_EN(true);
board_control_spi_sensors_power(true, 0xffff);
VDD_5V_PERIPH_EN(true);
}
@@ -169,10 +169,7 @@ stm32_boardinitialize(void)
const uint32_t gpio[] = PX4_GPIO_INIT_LIST;
px4_gpio_init(gpio, arraySize(gpio));
/* configure SPI interfaces */
stm32_spiinitialize();
board_control_spi_sensors_power_configgpio();
/* configure USB interfaces */
@@ -212,7 +209,7 @@ __EXPORT int board_app_initialize(uintptr_t arg)
VDD_3V3_SD_CARD_EN(true);
VDD_5V_PERIPH_EN(true);
VDD_5V_HIPOWER_EN(true);
VDD_3V3_SENSORS_EN(true);
board_control_spi_sensors_power(true, 0xffff);
VDD_3V3_SPEKTRUM_POWER_EN(true);
VDD_5V_RC_EN(true);
VDD_5V_WIFI_EN(true);
@@ -230,6 +227,10 @@ __EXPORT int board_app_initialize(uintptr_t arg)
syslog(LOG_ERR, "[boot] Failed to read HW revision and version\n");
}
/* configure SPI interfaces (after we determined the HW version) */
stm32_spiinitialize();
/* configure the DMA allocator */
if (board_dma_alloc_init() < 0) {
+27 -284
View File
@@ -31,291 +31,34 @@
*
****************************************************************************/
/**
* @file spi.cpp
*
* Board-specific SPI functions.
*/
/************************************************************************************
* Included Files
************************************************************************************/
#include <board_config.h>
#include <stdint.h>
#include <stdbool.h>
#include <debug.h>
#include <unistd.h>
#include <px4_arch/spi_hw_description.h>
#include <drivers/drv_sensor.h>
#include <nuttx/spi/spi.h>
#include <arch/board/board.h>
#include <systemlib/px4_macros.h>
#include <up_arch.h>
#include <chip.h>
#include <stm32_gpio.h>
#include "board_config.h"
constexpr px4_spi_bus_t px4_spi_buses[SPI_BUS_MAX_BUS_ITEMS] = {
initSPIBus(1, {
initSPIDevice(DRV_IMU_DEVTYPE_ICM20689, SPI::CS{GPIO::PortF, GPIO::Pin2}, SPI::DRDY{GPIO::PortB, GPIO::Pin4}),
initSPIDevice(DRV_IMU_DEVTYPE_ICM20602, SPI::CS{GPIO::PortF, GPIO::Pin3}, SPI::DRDY{GPIO::PortC, GPIO::Pin5}),
initSPIDevice(DRV_GYR_DEVTYPE_BMI055, SPI::CS{GPIO::PortF, GPIO::Pin4}, SPI::DRDY{GPIO::PortB, GPIO::Pin14}),
initSPIDevice(DRV_ACC_DEVTYPE_BMI055, SPI::CS{GPIO::PortG, GPIO::Pin10}, SPI::DRDY{GPIO::PortB, GPIO::Pin15}),
}, {GPIO::PortE, GPIO::Pin3}),
initSPIBus(2, {
initSPIDevice(SPIDEV_FLASH(0), SPI::CS{GPIO::PortF, GPIO::Pin5})
}),
initSPIBus(4, {
initSPIDevice(DRV_BARO_DEVTYPE_MS5611, SPI::CS{GPIO::PortF, GPIO::Pin10}),
}),
initSPIBusExternal(5, {
initSPIConfigExternal(SPI::CS{GPIO::PortI, GPIO::Pin4}, SPI::DRDY{GPIO::PortD, GPIO::Pin15}),
initSPIConfigExternal(SPI::CS{GPIO::PortI, GPIO::Pin10}),
initSPIConfigExternal(SPI::CS{GPIO::PortI, GPIO::Pin11})
}),
initSPIBusExternal(6, {
initSPIConfigExternal(SPI::CS{GPIO::PortI, GPIO::Pin6}),
initSPIConfigExternal(SPI::CS{GPIO::PortI, GPIO::Pin7}),
initSPIConfigExternal(SPI::CS{GPIO::PortI, GPIO::Pin8})
}),
};
/* Define CS GPIO array */
static constexpr uint32_t spi1selects_gpio[] = PX4_SENSOR_BUS_CS_GPIO;
static constexpr uint32_t spi2selects_gpio[] = PX4_MEMORY_BUS_CS_GPIO;
static constexpr uint32_t spi4selects_gpio[] = PX4_BARO_BUS_CS_GPIO;
static constexpr uint32_t spi5selects_gpio[] = PX4_EXTERNAL1_BUS_CS_GPIO;
static constexpr uint32_t spi6selects_gpio[] = PX4_EXTERNAL2_BUS_CS_GPIO;
static constexpr bool unused = validateSPIConfig(px4_spi_buses);
/************************************************************************************
* Name: stm32_spiinitialize
*
* Description:
* Called to configure SPI chip select GPIO pins for the PX4FMU board.
*
************************************************************************************/
__EXPORT void stm32_spiinitialize()
{
#ifdef CONFIG_STM32F7_SPI1
for (auto gpio : spi1selects_gpio) {
px4_arch_configgpio(gpio);
}
#endif // CONFIG_STM32F7_SPI1
#if defined(CONFIG_STM32F7_SPI2)
for (auto gpio : spi2selects_gpio) {
px4_arch_configgpio(gpio);
}
#endif // CONFIG_STM32F7_SPI2
#ifdef CONFIG_STM32F7_SPI4
for (auto gpio : spi4selects_gpio) {
px4_arch_configgpio(gpio);
}
#endif // CONFIG_STM32F7_SPI4
#ifdef CONFIG_STM32F7_SPI5
for (auto gpio : spi5selects_gpio) {
px4_arch_configgpio(gpio);
}
#endif // CONFIG_STM32F7_SPI5
#ifdef CONFIG_STM32F7_SPI6
for (auto gpio : spi6selects_gpio) {
px4_arch_configgpio(gpio);
}
#endif // CONFIG_STM32F7_SPI6
}
/************************************************************************************
* Name: stm32_spi1select and stm32_spi1status
*
* Description:
* Called by stm32 spi driver on bus 1.
*
************************************************************************************/
#ifdef CONFIG_STM32F7_SPI1
__EXPORT void stm32_spi1select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected)
{
ASSERT(PX4_SPI_BUS_ID(devid) == PX4_SPI_BUS_SENSORS);
// Making sure the other peripherals are not selected
for (auto cs : spi1selects_gpio) {
stm32_gpiowrite(cs, 1);
}
// SPI select is active low, so write !selected to select the device
stm32_gpiowrite(spi1selects_gpio[PX4_SPI_DEV_ID(devid)], !selected);
}
__EXPORT uint8_t stm32_spi1status(FAR struct spi_dev_s *dev, uint32_t devid)
{
return SPI_STATUS_PRESENT;
}
#endif // CONFIG_STM32F7_SPI1
/************************************************************************************
* Name: stm32_spi2select and stm32_spi2status
*
* Description:
* Called by stm32 spi driver on bus 2.
*
************************************************************************************/
#if defined(CONFIG_STM32F7_SPI2)
__EXPORT void stm32_spi2select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected)
{
if (devid == SPIDEV_FLASH(0)) {
devid = PX4_SPIDEV_MEMORY;
}
ASSERT(PX4_SPI_BUS_ID(devid) == PX4_SPI_BUS_MEMORY);
// Making sure the other peripherals are not selected
for (auto cs : spi2selects_gpio) {
stm32_gpiowrite(cs, 1);
}
// SPI select is active low, so write !selected to select the device
stm32_gpiowrite(spi2selects_gpio[PX4_SPI_DEV_ID(devid)], !selected);
}
__EXPORT uint8_t stm32_spi2status(FAR struct spi_dev_s *dev, uint32_t devid)
{
return SPI_STATUS_PRESENT;
}
#endif // CONFIG_STM32F7_SPI2 && GPIO_SPI2_CS_FRAM
/************************************************************************************
* Name: stm32_spi4select and stm32_spi4status
*
* Description:
* Called by stm32 spi driver on bus 4.
*
************************************************************************************/
#ifdef CONFIG_STM32F7_SPI4
__EXPORT void stm32_spi4select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected)
{
ASSERT(PX4_SPI_BUS_ID(devid) == PX4_SPI_BUS_BARO);
// Making sure the other peripherals are not selected
for (auto cs : spi4selects_gpio) {
stm32_gpiowrite(cs, 1);
}
// SPI select is active low, so write !selected to select the device
stm32_gpiowrite(spi4selects_gpio[PX4_SPI_DEV_ID(devid)], !selected);
}
__EXPORT uint8_t stm32_spi4status(FAR struct spi_dev_s *dev, uint32_t devid)
{
return SPI_STATUS_PRESENT;
}
#endif // CONFIG_STM32F7_SPI4
/************************************************************************************
* Name: stm32_spi5select and stm32_spi5status
*
* Description:
* Called by stm32 spi driver on bus 5.
*
************************************************************************************/
#ifdef CONFIG_STM32F7_SPI5
__EXPORT void stm32_spi5select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected)
{
ASSERT(PX4_SPI_BUS_ID(devid) == PX4_SPI_BUS_EXTERNAL1);
// Making sure the other peripherals are not selected
for (auto cs : spi5selects_gpio) {
stm32_gpiowrite(cs, 1);
}
// SPI select is active low, so write !selected to select the device
stm32_gpiowrite(spi5selects_gpio[PX4_SPI_DEV_ID(devid)], !selected);
}
__EXPORT uint8_t stm32_spi5status(FAR struct spi_dev_s *dev, uint32_t devid)
{
return SPI_STATUS_PRESENT;
}
#endif // CONFIG_STM32F7_SPI5
/************************************************************************************
* Name: stm32_spi6select and stm32_spi6status
*
* Description:
* Called by stm32 spi driver on bus 6.
*
************************************************************************************/
#ifdef CONFIG_STM32F7_SPI6
__EXPORT void stm32_spi6select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected)
{
ASSERT(PX4_SPI_BUS_ID(devid) == PX4_SPI_BUS_EXTERNAL2);
// Making sure the other peripherals are not selected
for (auto cs : spi6selects_gpio) {
stm32_gpiowrite(cs, 1);
}
// SPI select is active low, so write !selected to select the device
stm32_gpiowrite(spi6selects_gpio[PX4_SPI_DEV_ID(devid)], !selected);
}
__EXPORT uint8_t stm32_spi6status(FAR struct spi_dev_s *dev, uint32_t devid)
{
return SPI_STATUS_PRESENT;
}
#endif // CONFIG_STM32F7_SPI6
/************************************************************************************
* Name: board_spi_reset
*
* Description:
*
*
************************************************************************************/
__EXPORT void board_spi_reset(int ms)
{
// disable SPI bus
for (auto cs : spi1selects_gpio) {
stm32_configgpio(_PIN_OFF(cs));
}
stm32_configgpio(GPIO_SPI1_SCK_OFF);
stm32_configgpio(GPIO_SPI1_MISO_OFF);
stm32_configgpio(GPIO_SPI1_MOSI_OFF);
#if BOARD_USE_DRDY
stm32_configgpio(GPIO_DRDY_OFF_SPI1_DRDY1_ICM20689);
stm32_configgpio(GPIO_DRDY_OFF_SPI1_DRDY2_BMI055_GYRO);
stm32_configgpio(GPIO_DRDY_OFF_SPI1_DRDY3_BMI055_ACC);
stm32_configgpio(GPIO_DRDY_OFF_SPI1_DRDY4_ICM20602);
stm32_configgpio(GPIO_DRDY_OFF_SPI1_DRDY5_BMI055_GYRO);
stm32_configgpio(GPIO_DRDY_OFF_SPI1_DRDY6_BMI055_ACC);
#endif
/* set the sensor rail off */
stm32_gpiowrite(GPIO_VDD_3V3_SENSORS_EN, 0);
/* wait for the sensor rail to reach GND */
usleep(ms * 1000);
syslog(LOG_DEBUG, "reset done, %d ms\n", ms);
/* re-enable power */
/* switch the sensor rail back on */
stm32_gpiowrite(GPIO_VDD_3V3_SENSORS_EN, 1);
/* wait a bit before starting SPI, different times didn't influence results */
usleep(100);
/* reconfigure the SPI pins */
for (auto cs : spi1selects_gpio) {
stm32_configgpio(cs);
}
stm32_configgpio(GPIO_SPI1_SCK);
stm32_configgpio(GPIO_SPI1_MISO);
stm32_configgpio(GPIO_SPI1_MOSI);
#if BOARD_USE_DRDY
stm32_configgpio(GPIO_SPI1_DRDY1_ICM20689);
stm32_configgpio(GPIO_SPI1_DRDY2_BMI055_GYRO);
stm32_configgpio(GPIO_SPI1_DRDY3_BMI055_ACC);
stm32_configgpio(GPIO_SPI1_DRDY4_ICM20602);
stm32_configgpio(GPIO_SPI1_DRDY5_BMI055_GYRO);
stm32_configgpio(GPIO_SPI1_DRDY6_BMI055_ACC);
#endif
}
+1 -1
View File
@@ -30,7 +30,7 @@ qmc5883 -X start
# Possible internal compass
bmm150 start
# Possible internal Barro
# Possible internal Baro
bmp388 -I start
bmp388 -J start
+2
View File
@@ -33,6 +33,7 @@
add_library(drivers_board
can.c
i2c.cpp
init.c
led.c
manifest.c
@@ -45,6 +46,7 @@ add_dependencies(drivers_board arch_board_hw_info)
target_link_libraries(drivers_board
PRIVATE
arch_spi
arch_board_hw_info
drivers__led # drv_led_start
nuttx_arch # sdio
+8 -18
View File
@@ -227,21 +227,22 @@
#define _PIN_OFF(def) (((def) & (GPIO_PORT_MASK | GPIO_PIN_MASK)) | (GPIO_INPUT|GPIO_PULLDOWN|GPIO_SPEED_2MHz))
#define PX4_SPI_BUS_RAMTRON PX4_SPI_BUS_MEMORY
#define PX4_SPIDEV_ICM_20602 PX4_MK_SPI_SEL(PX4_SPI_BUS_SENSORS1,0)
#include <drivers/drv_sensor.h>
#define PX4_SPIDEV_ICM_20602 PX4_MK_SPI_SEL(0,DRV_IMU_DEVTYPE_ICM20602)
#define PX4_SENSORS1_BUS_CS_GPIO {GPIO_SPI1_nCS1_ICM20602}
#define PX4_SPIDEV_ISM330 PX4_MK_SPI_SEL(PX4_SPI_BUS_SENSORS2,0)
#define PX4_SPIDEV_ISM330 PX4_MK_SPI_SEL(0,DRV_DEVTYPE_ST_ISM330DLC)
#define PX4_SENSORS2_BUS_CS_GPIO {GPIO_SPI2_nCS1_ISM330}
#define PX4_SPIDEV_BMI088_GYR PX4_MK_SPI_SEL(PX4_SPI_BUS_SENSORS3,0)
#define PX4_SPIDEV_BMI088_ACC PX4_MK_SPI_SEL(PX4_SPI_BUS_SENSORS3,1)
#define PX4_SPIDEV_BMI088_GYR PX4_MK_SPI_SEL(0,DRV_GYR_DEVTYPE_BMI088)
#define PX4_SPIDEV_BMI088_ACC PX4_MK_SPI_SEL(0,DRV_ACC_DEVTYPE_BMI088)
#define PX4_SENSORS3_BUS_CS_GPIO {GPIO_SPI3_nCS2_BMI088_GYRO, GPIO_SPI3_nCS1_BMI088_ACCEL}
#define PX4_SPIDEV_MEMORY PX4_MK_SPI_SEL(PX4_SPI_BUS_MEMORY,0)
#define PX4_SPIDEV_MEMORY SPIDEV_FLASH(0)
#define PX4_MEMORY_BUS_CS_GPIO {GPIO_SPI5_nCS1_FRAM}
#define PX4_SPIDEV_EXTERNAL1_1 PX4_MK_SPI_SEL(PX4_SPI_BUS_EXTERNAL1,0)
#define PX4_SPIDEV_EXTERNAL1_2 PX4_MK_SPI_SEL(PX4_SPI_BUS_EXTERNAL1,1)
#define PX4_SPIDEV_EXTERNAL1_1 PX4_MK_SPI_SEL(0,0)
#define PX4_SPIDEV_EXTERNAL1_2 PX4_MK_SPI_SEL(0,1)
#define PX4_EXTERNAL1_BUS_CS_GPIO {GPIO_SPI6_nCS1_EXTERNAL1, GPIO_SPI6_nCS2_EXTERNAL1}
@@ -389,9 +390,6 @@
#define GPIO_VDD_5V_PERIPH_nOC /* PE15 */ (GPIO_INPUT |GPIO_FLOAT|GPIO_PORTE|GPIO_PIN15)
#define GPIO_VDD_5V_HIPOWER_nEN /* PF12 */ (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_2MHz|GPIO_OUTPUT_SET|GPIO_PORTF|GPIO_PIN12)
#define GPIO_VDD_5V_HIPOWER_nOC /* PF13 */ (GPIO_INPUT |GPIO_FLOAT|GPIO_PORTF|GPIO_PIN13)
#define GPIO_VDD_3V3_SENSORS1_EN /* PI11 */ (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_2MHz|GPIO_OUTPUT_CLEAR|GPIO_PORTI|GPIO_PIN11)
#define GPIO_VDD_3V3_SENSORS2_EN /* PD15 */ (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_2MHz|GPIO_OUTPUT_CLEAR|GPIO_PORTD|GPIO_PIN15)
#define GPIO_VDD_3V3_SENSORS3_EN /* PE7 */ (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_2MHz|GPIO_OUTPUT_CLEAR|GPIO_PORTE|GPIO_PIN7)
#define GPIO_VDD_3V3_SENSORS4_EN /* PG8 */ (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_2MHz|GPIO_OUTPUT_CLEAR|GPIO_PORTG|GPIO_PIN8)
#define GPIO_VDD_3V3_SPEKTRUM_POWER_EN /* PH2 */ (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_2MHz|GPIO_OUTPUT_CLEAR|GPIO_PORTH|GPIO_PIN2)
#define GPIO_VDD_3V3_SD_CARD_EN /* PC13 */ (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_2MHz|GPIO_OUTPUT_CLEAR|GPIO_PORTC|GPIO_PIN13)
@@ -413,9 +411,6 @@
#define VDD_5V_PERIPH_EN(on_true) px4_arch_gpiowrite(GPIO_VDD_5V_PERIPH_nEN, !(on_true))
#define VDD_5V_HIPOWER_EN(on_true) px4_arch_gpiowrite(GPIO_VDD_5V_HIPOWER_nEN, !(on_true))
#define VDD_3V3_SENSORS1_EN(on_true) px4_arch_gpiowrite(GPIO_VDD_3V3_SENSORS1_EN, (on_true))
#define VDD_3V3_SENSORS2_EN(on_true) px4_arch_gpiowrite(GPIO_VDD_3V3_SENSORS2_EN, (on_true))
#define VDD_3V3_SENSORS3_EN(on_true) px4_arch_gpiowrite(GPIO_VDD_3V3_SENSORS3_EN, (on_true))
#define VDD_3V3_SENSORS4_EN(on_true) px4_arch_gpiowrite(GPIO_VDD_3V3_SENSORS4_EN, (on_true))
#define VDD_3V3_SPEKTRUM_POWER_EN(on_true) px4_arch_gpiowrite(GPIO_VDD_3V3_SPEKTRUM_POWER_EN, (on_true))
#define READ_VDD_3V3_SPEKTRUM_POWER_EN() px4_arch_gpioread(GPIO_VDD_3V3_SPEKTRUM_POWER_EN)
@@ -569,9 +564,6 @@
GPIO_VDD_5V_PERIPH_nOC, \
GPIO_VDD_5V_HIPOWER_nEN, \
GPIO_VDD_5V_HIPOWER_nOC, \
GPIO_VDD_3V3_SENSORS1_EN, \
GPIO_VDD_3V3_SENSORS2_EN, \
GPIO_VDD_3V3_SENSORS3_EN, \
GPIO_VDD_3V3_SENSORS4_EN, \
GPIO_VDD_3V3_SPEKTRUM_POWER_EN, \
GPIO_VDD_3V3_SD_CARD_EN, \
@@ -627,8 +619,6 @@ int stm32_sdio_initialize(void);
extern void stm32_spiinitialize(void);
void board_spi_reset(int ms);
extern void stm32_usbinitialize(void);
extern void board_peripheral_reset(int ms);
+41
View File
@@ -0,0 +1,41 @@
/****************************************************************************
*
* Copyright (C) 2020 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name PX4 nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#include <px4_arch/i2c_hw_description.h>
constexpr px4_i2c_bus_t px4_i2c_buses[I2C_BUS_MAX_BUS_ITEMS] = {
initI2CBusExternal(1),
initI2CBusExternal(2),
initI2CBusExternal(3),
initI2CBusInternal(4),
};
+7 -8
View File
@@ -105,9 +105,7 @@ __EXPORT void board_peripheral_reset(int ms)
/* set the peripheral rails off */
VDD_5V_PERIPH_EN(false);
VDD_3V3_SENSORS1_EN(false);
VDD_3V3_SENSORS2_EN(false);
VDD_3V3_SENSORS3_EN(false);
board_control_spi_sensors_power(false, 0xffff);
VDD_3V3_SENSORS4_EN(false);
bool last = READ_VDD_3V3_SPEKTRUM_POWER_EN();
@@ -122,9 +120,7 @@ __EXPORT void board_peripheral_reset(int ms)
/* switch the peripheral rail back on */
VDD_3V3_SPEKTRUM_POWER_EN(last);
VDD_3V3_SENSORS1_EN(true);
VDD_3V3_SENSORS2_EN(true);
VDD_3V3_SENSORS3_EN(true);
board_control_spi_sensors_power(true, 0xffff);
VDD_3V3_SENSORS4_EN(true);
VDD_5V_PERIPH_EN(true);
@@ -176,7 +172,9 @@ stm32_boardinitialize(void)
const uint32_t gpio[] = PX4_GPIO_INIT_LIST;
px4_gpio_init(gpio, arraySize(gpio));
/* configure SPI interfaces */
/* configure SPI interfaces (we can do this here as long as we only have a single SPI hw config version -
* otherwise we need to move this after board_determine_hw_info()) */
_Static_assert(BOARD_NUM_SPI_CFG_HW_VERSIONS == 1, "Need to move the SPI initialization for multi-version support");
stm32_spiinitialize();
@@ -220,7 +218,8 @@ __EXPORT int board_app_initialize(uintptr_t arg)
VDD_3V3_SD_CARD_EN(true);
VDD_5V_PERIPH_EN(true);
VDD_5V_HIPOWER_EN(true);
board_spi_reset(0xff00000A);
board_spi_reset(10, 0xffff);
VDD_3V3_SENSORS4_EN(true);
VDD_3V3_SPEKTRUM_POWER_EN(true);
SE050_RESET(false);
+27 -386
View File
@@ -31,392 +31,33 @@
*
****************************************************************************/
/**
* @file spi.c
*
* Board-specific SPI functions.
*/
/************************************************************************************
* Included Files
************************************************************************************/
#include <board_config.h>
#include <stdint.h>
#include <stdbool.h>
#include <debug.h>
#include <unistd.h>
#include <px4_arch/spi_hw_description.h>
#include <drivers/drv_sensor.h>
#include <nuttx/spi/spi.h>
#include <arch/board/board.h>
#include <systemlib/px4_macros.h>
#include <up_arch.h>
#include <chip.h>
#include <stm32_gpio.h>
#include "board_config.h"
constexpr px4_spi_bus_t px4_spi_buses[SPI_BUS_MAX_BUS_ITEMS] = {
initSPIBus(1, {
initSPIDevice(DRV_IMU_DEVTYPE_ICM20602, SPI::CS{GPIO::PortI, GPIO::Pin9}, SPI::DRDY{GPIO::PortF, GPIO::Pin2}),
}, {GPIO::PortI, GPIO::Pin11}),
initSPIBus(2, {
initSPIDevice(DRV_DEVTYPE_ST_ISM330DLC, SPI::CS{GPIO::PortH, GPIO::Pin5}, SPI::DRDY{GPIO::PortH, GPIO::Pin12}),
}, {GPIO::PortD, GPIO::Pin15}),
initSPIBus(3, {
initSPIDevice(DRV_GYR_DEVTYPE_BMI088, SPI::CS{GPIO::PortI, GPIO::Pin8}, SPI::DRDY{GPIO::PortI, GPIO::Pin7}),
initSPIDevice(DRV_ACC_DEVTYPE_BMI088, SPI::CS{GPIO::PortI, GPIO::Pin4}, SPI::DRDY{GPIO::PortI, GPIO::Pin6}),
}, {GPIO::PortE, GPIO::Pin7}),
// initSPIBus(4, {
// // no devices
// TODO: if enabled, remove GPIO_VDD_3V3_SENSORS4_EN from board_config.h
// }, {GPIO::PortG, GPIO::Pin8}),
initSPIBus(5, {
initSPIDevice(SPIDEV_FLASH(0), SPI::CS{GPIO::PortG, GPIO::Pin7})
}),
initSPIBusExternal(6, {
initSPIConfigExternal(SPI::CS{GPIO::PortI, GPIO::Pin10}, SPI::DRDY{GPIO::PortD, GPIO::Pin11}),
initSPIConfigExternal(SPI::CS{GPIO::PortA, GPIO::Pin15}, SPI::DRDY{GPIO::PortD, GPIO::Pin12}),
}),
};
static constexpr bool unused = validateSPIConfig(px4_spi_buses);
/* Define CS GPIO array */
static constexpr uint32_t spi1selects_gpio[] = PX4_SENSORS1_BUS_CS_GPIO;
static constexpr uint32_t spi2selects_gpio[] = PX4_SENSORS2_BUS_CS_GPIO;
static constexpr uint32_t spi3selects_gpio[] = PX4_SENSORS3_BUS_CS_GPIO;
#ifdef CONFIG_STM32F7_SPI4
static constexpr uint32_t spi4selects_gpio[] = PX4_SENSORS4_BUS_CS_GPIO;
#endif
static constexpr uint32_t spi5selects_gpio[] = PX4_MEMORY_BUS_CS_GPIO;
static constexpr uint32_t spi6selects_gpio[] = PX4_EXTERNAL1_BUS_CS_GPIO;
/************************************************************************************
* Name: stm32_spiinitialize
*
* Description:
* Called to configure SPI chip select GPIO pins for the PX4FMU board.
*
************************************************************************************/
__EXPORT void stm32_spiinitialize()
{
#ifdef CONFIG_STM32F7_SPI1
for (auto gpio : spi1selects_gpio) {
px4_arch_configgpio(gpio);
}
#endif // CONFIG_STM32F7_SPI1
#if defined(CONFIG_STM32F7_SPI2)
for (auto gpio : spi2selects_gpio) {
px4_arch_configgpio(gpio);
}
#endif // CONFIG_STM32F7_SPI2
#if defined(CONFIG_STM32F7_SPI3)
for (auto gpio : spi3selects_gpio) {
px4_arch_configgpio(gpio);
}
#endif // CONFIG_STM32F7_SPI3
#ifdef CONFIG_STM32F7_SPI4
for (auto gpio : spi4selects_gpio) {
px4_arch_configgpio(gpio);
}
#endif // CONFIG_STM32F7_SPI4
#ifdef CONFIG_STM32F7_SPI5
for (auto gpio : spi5selects_gpio) {
px4_arch_configgpio(gpio);
}
#endif // CONFIG_STM32F7_SPI5
#ifdef CONFIG_STM32F7_SPI6
for (auto gpio : spi6selects_gpio) {
px4_arch_configgpio(gpio);
}
#endif // CONFIG_STM32F7_SPI6
}
/************************************************************************************
* Name: stm32_spi1select and stm32_spi1status
*
* Description:
* Called by stm32 spi driver on bus 1.
*
************************************************************************************/
#ifdef CONFIG_STM32F7_SPI1
__EXPORT void stm32_spi1select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected)
{
ASSERT(PX4_SPI_BUS_ID(devid) == PX4_SPI_BUS_SENSORS1);
// Making sure the other peripherals are not selected
for (auto cs : spi1selects_gpio) {
stm32_gpiowrite(cs, 1);
}
// SPI select is active low, so write !selected to select the device
stm32_gpiowrite(spi1selects_gpio[PX4_SPI_DEV_ID(devid)], !selected);
}
__EXPORT uint8_t stm32_spi1status(FAR struct spi_dev_s *dev, uint32_t devid)
{
return SPI_STATUS_PRESENT;
}
#endif // CONFIG_STM32F7_SPI1
/************************************************************************************
* Name: stm32_spi2select and stm32_spi2status
*
* Description:
* Called by stm32 spi driver on bus 2.
*
************************************************************************************/
#if defined(CONFIG_STM32F7_SPI2)
__EXPORT void stm32_spi2select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected)
{
ASSERT(PX4_SPI_BUS_ID(devid) == PX4_SPI_BUS_SENSORS2);
// Making sure the other peripherals are not selected
for (auto cs : spi2selects_gpio) {
stm32_gpiowrite(cs, 1);
}
// SPI select is active low, so write !selected to select the device
stm32_gpiowrite(spi2selects_gpio[PX4_SPI_DEV_ID(devid)], !selected);
}
__EXPORT uint8_t stm32_spi2status(FAR struct spi_dev_s *dev, uint32_t devid)
{
return SPI_STATUS_PRESENT;
}
#endif // CONFIG_STM32F7_SPI2
/************************************************************************************
* Name: stm32_spi3select and stm32_spi3status
*
* Description:
* Called by stm32 spi driver on bus 3.
*
************************************************************************************/
#if defined(CONFIG_STM32F7_SPI3)
__EXPORT void stm32_spi3select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected)
{
ASSERT(PX4_SPI_BUS_ID(devid) == PX4_SPI_BUS_SENSORS3);
// Making sure the other peripherals are not selected
for (auto cs : spi3selects_gpio) {
stm32_gpiowrite(cs, 1);
}
// SPI select is active low, so write !selected to select the device
stm32_gpiowrite(spi3selects_gpio[PX4_SPI_DEV_ID(devid)], !selected);
}
__EXPORT uint8_t stm32_spi3status(FAR struct spi_dev_s *dev, uint32_t devid)
{
return SPI_STATUS_PRESENT;
}
#endif // CONFIG_STM32F7_SPI3
/************************************************************************************
* Name: stm32_spi4select and stm32_spi4status
*
* Description:
* Called by stm32 spi driver on bus 4.
*
************************************************************************************/
#ifdef CONFIG_STM32F7_SPI4
__EXPORT void stm32_spi4select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected)
{
ASSERT(PX4_SPI_BUS_ID(devid) == PX4_SPI_BUS_SENSORS4);
// Making sure the other peripherals are not selected
for (auto cs : spi4selects_gpio) {
stm32_gpiowrite(cs, 1);
}
// SPI select is active low, so write !selected to select the device
stm32_gpiowrite(spi4selects_gpio[PX4_SPI_DEV_ID(devid)], !selected);
}
__EXPORT uint8_t stm32_spi4status(FAR struct spi_dev_s *dev, uint32_t devid)
{
return SPI_STATUS_PRESENT;
}
#endif // CONFIG_STM32F7_SPI4
/************************************************************************************
* Name: stm32_spi5select and stm32_spi5status
*
* Description:
* Called by stm32 spi driver on bus 5.
*
************************************************************************************/
#ifdef CONFIG_STM32F7_SPI5
__EXPORT void stm32_spi5select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected)
{
if (devid == SPIDEV_FLASH(0)) {
devid = PX4_SPIDEV_MEMORY;
}
ASSERT(PX4_SPI_BUS_ID(devid) == PX4_SPI_BUS_MEMORY);
// Making sure the other peripherals are not selected
for (auto cs : spi5selects_gpio) {
stm32_gpiowrite(cs, 1);
}
// SPI select is active low, so write !selected to select the device
stm32_gpiowrite(spi5selects_gpio[PX4_SPI_DEV_ID(devid)], !selected);
}
__EXPORT uint8_t stm32_spi5status(FAR struct spi_dev_s *dev, uint32_t devid)
{
return SPI_STATUS_PRESENT;
}
#endif // CONFIG_STM32F7_SPI5
/************************************************************************************
* Name: stm32_spi6select and stm32_spi6status
*
* Description:
* Called by stm32 spi driver on bus 6.
*
************************************************************************************/
#ifdef CONFIG_STM32F7_SPI6
__EXPORT void stm32_spi6select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected)
{
ASSERT(PX4_SPI_BUS_ID(devid) == PX4_SPI_BUS_EXTERNAL1);
// Making sure the other peripherals are not selected
for (auto cs : spi6selects_gpio) {
stm32_gpiowrite(cs, 1);
}
// SPI select is active low, so write !selected to select the device
stm32_gpiowrite(spi6selects_gpio[PX4_SPI_DEV_ID(devid)], !selected);
}
__EXPORT uint8_t stm32_spi6status(FAR struct spi_dev_s *dev, uint32_t devid)
{
return SPI_STATUS_PRESENT;
}
#endif // CONFIG_STM32F7_SPI6
/************************************************************************************
* Name: board_spi_reset
*
* Description:
* TODO:Add 4 bit MASK active LOW for Bus 1-4
*
************************************************************************************/
__EXPORT void board_spi_reset(int mask_ms)
{
int ms = mask_ms & 0x00ffffff;
int mask = ((mask_ms & 0xff000000) >> 24) & 0xff;
// disable SPI bus
if (mask & 1) {
for (auto cs : spi1selects_gpio) {
stm32_configgpio(_PIN_OFF(cs));
}
stm32_configgpio(GPIO_SPI1_SCK_OFF);
stm32_configgpio(GPIO_SPI1_MISO_OFF);
stm32_configgpio(GPIO_SPI1_MOSI_OFF);
#if BOARD_USE_DRDY
stm32_configgpio(GPIO_DRDY_OFF_SPI1_DRDY1_ICM20602);
#endif
/* set the sensor rail off */
stm32_gpiowrite(GPIO_VDD_3V3_SENSORS1_EN, 0);
}
if (mask & 2) {
for (auto cs : spi2selects_gpio) {
stm32_configgpio(_PIN_OFF(cs));
}
stm32_configgpio(GPIO_SPI2_SCK_OFF);
stm32_configgpio(GPIO_SPI2_MISO_OFF);
stm32_configgpio(GPIO_SPI2_MOSI_OFF);
stm32_configgpio(GPIO_DRDY_OFF_SPI2_DRDY1_ISM330);
/* set the sensor rail off */
stm32_gpiowrite(GPIO_VDD_3V3_SENSORS2_EN, 0);
}
if (mask & 4) {
for (auto cs : spi3selects_gpio) {
stm32_configgpio(_PIN_OFF(cs));
}
stm32_configgpio(GPIO_SPI3_SCK_OFF);
stm32_configgpio(GPIO_SPI3_MISO_OFF);
stm32_configgpio(GPIO_SPI3_MOSI_OFF);
#if BOARD_USE_DRDY
stm32_configgpio(GPIO_DRDY_OFF_SPI3_DRDY1_BMI088);
stm32_configgpio(GPIO_DRDY_OFF_SPI3_DRDY2_BMI088);
#endif
/* set the sensor rail off */
stm32_gpiowrite(GPIO_VDD_3V3_SENSORS3_EN, 0);
}
if (mask & 8) {
/* set the sensor rail off */
stm32_gpiowrite(GPIO_VDD_3V3_SENSORS4_EN, 0);
}
/* wait for the sensor rail to reach GND */
usleep(ms * 1000);
syslog(LOG_DEBUG, "reset done, %d ms\n", ms);
/* re-enable power */
/* switch the sensor rail back on */
stm32_gpiowrite(GPIO_VDD_3V3_SENSORS1_EN, 1);
stm32_gpiowrite(GPIO_VDD_3V3_SENSORS2_EN, 1);
stm32_gpiowrite(GPIO_VDD_3V3_SENSORS3_EN, 1);
stm32_gpiowrite(GPIO_VDD_3V3_SENSORS4_EN, 1);
/* wait a bit before starting SPI, different times didn't influence results */
usleep(100);
if (mask & 1) {
/* reconfigure the SPI pins */
for (auto cs : spi1selects_gpio) {
stm32_configgpio(cs);
}
stm32_configgpio(GPIO_SPI1_SCK);
stm32_configgpio(GPIO_SPI1_MISO);
stm32_configgpio(GPIO_SPI1_MOSI);
#if BOARD_USE_DRDY
stm32_configgpio(GPIO_SPI1_DRDY1_ICM20602);
#endif
}
if (mask & 2) {
/* reconfigure the SPI pins */
for (auto cs : spi2selects_gpio) {
stm32_configgpio(cs);
}
stm32_configgpio(GPIO_SPI2_SCK);
stm32_configgpio(GPIO_SPI2_MISO);
stm32_configgpio(GPIO_SPI2_MOSI);
stm32_configgpio(GPIO_SPI2_DRDY1_ISM330);
}
if (mask & 4) {
/* reconfigure the SPI pins */
for (auto cs : spi3selects_gpio) {
stm32_configgpio(cs);
}
stm32_configgpio(GPIO_SPI3_SCK);
stm32_configgpio(GPIO_SPI3_MISO);
stm32_configgpio(GPIO_SPI3_MOSI);
#if BOARD_USE_DRDY
stm32_configgpio(GPIO_SPI3_DRDY1_BMI088);
stm32_configgpio(GPIO_SPI3_DRDY2_BMI088);
#endif
}
}
+2
View File
@@ -166,3 +166,5 @@
#define LED_PANIC 7 /* N/C + N/C + N/C + LED? */
#define BOARD_NUM_IO_TIMERS 3
#define BOARD_DISABLE_I2C_SPI
+2 -1
View File
@@ -32,5 +32,6 @@
############################################################################
add_library(drivers_board
empty.c
i2c.cpp
spi.cpp
)
+1 -1
View File
@@ -55,7 +55,7 @@
// SPI
#define PX4_SPI_BUS_SENSORS 0
#define PX4_SPIDEV_MPU PX4_MK_SPI_SEL(PX4_SPI_BUS_SENSORS, 0) // spidev0.0
#define PX4_SPIDEV_MPU PX4_MK_SPI_SEL(0, 0) // spidev0.0
#include <system_config.h>
#include <px4_platform_common/board_common.h>
View File
+40
View File
@@ -0,0 +1,40 @@
/****************************************************************************
*
* Copyright (C) 2020 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name PX4 nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#include <px4_arch/i2c_hw_description.h>
constexpr px4_i2c_bus_t px4_i2c_buses[I2C_BUS_MAX_BUS_ITEMS] = {
initI2CBusExternal(0),
initI2CBusInternal(1),
};
+42
View File
@@ -0,0 +1,42 @@
/****************************************************************************
*
* Copyright (C) 2020 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name PX4 nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#include <px4_arch/spi_hw_description.h>
#include <drivers/drv_sensor.h>
constexpr px4_spi_bus_t px4_spi_buses[SPI_BUS_MAX_BUS_ITEMS] = {
initSPIBus(0, {
initSPIDevice(DRV_IMU_DEVTYPE_MPU9250, 0),
}),
};