From 52fc56a61f09bcba39d45a34c5e0e55f0a6fa8da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Wed, 31 Oct 2018 01:36:25 +0100 Subject: [PATCH] gps: explicitly set SPI bus speed to 1MHz Required on RPi, the default seems to be too high. --- src/drivers/gps/gps.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/drivers/gps/gps.cpp b/src/drivers/gps/gps.cpp index 6f6ff81a7c..4dae509bd3 100644 --- a/src/drivers/gps/gps.cpp +++ b/src/drivers/gps/gps.cpp @@ -87,6 +87,9 @@ #include "devices/src/mtk.h" #include "devices/src/ashtech.h" +#ifdef __PX4_LINUX +#include +#endif /* __PX4_LINUX */ #define TIMEOUT_5HZ 500 #define RATE_MEASUREMENT_PERIOD 5000000 @@ -608,6 +611,27 @@ GPS::run() PX4_ERR("GPS: failed to open serial port: %s err: %d", _port, errno); return; } + +#ifdef __PX4_LINUX + + if (_interface == GPSHelper::Interface::SPI) { + int spi_speed = 1000000; // make sure the bus speed is not too high (required on RPi) + int status_value = ioctl(_serial_fd, SPI_IOC_WR_MAX_SPEED_HZ, &spi_speed); + + if (status_value < 0) { + PX4_ERR("SPI_IOC_WR_MAX_SPEED_HZ failed for %s (%d)", _port, errno); + return; + } + + status_value = ioctl(_serial_fd, SPI_IOC_RD_MAX_SPEED_HZ, &spi_speed); + + if (status_value < 0) { + PX4_ERR("SPI_IOC_RD_MAX_SPEED_HZ failed for %s (%d)", _port, errno); + return; + } + } + +#endif /* __PX4_LINUX */ } param_t handle = param_find("GPS_YAW_OFFSET");