2018-01-05 03:00:09 -04:00
|
|
|
/*
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
/*
|
2022-02-21 00:28:14 -04:00
|
|
|
* AP_BoardConfig - driver loading and setup
|
2018-01-05 03:00:09 -04:00
|
|
|
*/
|
|
|
|
|
2022-02-21 00:28:14 -04:00
|
|
|
|
2018-01-05 03:00:09 -04:00
|
|
|
#include <AP_HAL/AP_HAL.h>
|
2022-02-21 00:28:14 -04:00
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS
|
|
|
|
#include <hal.h>
|
|
|
|
#endif
|
2018-01-05 03:00:09 -04:00
|
|
|
#include "AP_BoardConfig.h"
|
2019-04-19 21:29:04 -03:00
|
|
|
#include <GCS_MAVLink/GCS.h>
|
2019-04-25 17:40:01 -03:00
|
|
|
#include <AP_Math/crc.h>
|
2018-01-05 03:00:09 -04:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
extern const AP_HAL::HAL& hal;
|
|
|
|
|
|
|
|
/*
|
|
|
|
init safety state
|
|
|
|
*/
|
|
|
|
void AP_BoardConfig::board_init_safety()
|
|
|
|
{
|
2019-04-19 21:29:04 -03:00
|
|
|
bool force_safety_off = (state.safety_enable.get() == 0);
|
|
|
|
if (!force_safety_off && hal.util->was_watchdog_safety_off()) {
|
2022-05-21 05:49:24 -03:00
|
|
|
GCS_SEND_TEXT(MAV_SEVERITY_INFO, "Forcing safety off for watchdog\n");
|
2019-04-19 21:29:04 -03:00
|
|
|
force_safety_off = true;
|
|
|
|
}
|
|
|
|
if (force_safety_off) {
|
2018-01-05 03:00:09 -04:00
|
|
|
hal.rcout->force_safety_off();
|
|
|
|
// wait until safety has been turned off
|
|
|
|
uint8_t count = 20;
|
|
|
|
while (hal.util->safety_switch_state() != AP_HAL::Util::SAFETY_ARMED && count--) {
|
|
|
|
hal.scheduler->delay(20);
|
|
|
|
}
|
|
|
|
}
|
2018-08-01 20:46:59 -03:00
|
|
|
}
|
2018-04-20 18:31:20 -03:00
|
|
|
|
2021-12-17 20:08:06 -04:00
|
|
|
/*
|
|
|
|
init debug pins. We set debug pins as input if BRD_OPTIONS bit for debug enable is not set
|
|
|
|
this prevents possible ESD issues on the debug pins
|
|
|
|
*/
|
|
|
|
void AP_BoardConfig::board_init_debug()
|
|
|
|
{
|
2022-11-27 11:56:15 -04:00
|
|
|
#if !defined(HAL_BUILD_AP_PERIPH) && !defined(HAL_DEBUG_BUILD)
|
2021-12-17 20:08:06 -04:00
|
|
|
if ((_options & BOARD_OPTION_DEBUG_ENABLE) == 0) {
|
|
|
|
#ifdef HAL_GPIO_PIN_JTCK_SWCLK
|
|
|
|
palSetLineMode(HAL_GPIO_PIN_JTCK_SWCLK, PAL_MODE_INPUT);
|
|
|
|
#endif
|
|
|
|
#ifdef HAL_GPIO_PIN_JTMS_SWDIO
|
|
|
|
palSetLineMode(HAL_GPIO_PIN_JTMS_SWDIO, PAL_MODE_INPUT);
|
|
|
|
#endif
|
|
|
|
}
|
2022-11-27 11:56:15 -04:00
|
|
|
#endif // HAL_BUILD_AP_PERIPH && HAL_DEBUG_BUILD
|
2021-12-17 20:08:06 -04:00
|
|
|
}
|
|
|
|
|
2018-04-20 18:31:20 -03:00
|
|
|
|
|
|
|
#if AP_FEATURE_BOARD_DETECT
|
|
|
|
|
|
|
|
AP_BoardConfig::px4_board_type AP_BoardConfig::px4_configured_board;
|
2018-01-05 03:00:09 -04:00
|
|
|
|
|
|
|
void AP_BoardConfig::board_setup_drivers(void)
|
|
|
|
{
|
|
|
|
if (state.board_type == PX4_BOARD_OLDDRIVERS) {
|
|
|
|
printf("Old drivers no longer supported\n");
|
2022-07-05 00:08:56 -03:00
|
|
|
state.board_type.set(PX4_BOARD_AUTO);
|
2018-01-05 03:00:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// run board auto-detection
|
|
|
|
board_autodetect();
|
|
|
|
|
|
|
|
px4_configured_board = (enum px4_board_type)state.board_type.get();
|
|
|
|
|
|
|
|
switch (px4_configured_board) {
|
|
|
|
case PX4_BOARD_PX4V1:
|
|
|
|
case PX4_BOARD_PIXHAWK:
|
|
|
|
case PX4_BOARD_PIXHAWK2:
|
2018-05-29 08:43:01 -03:00
|
|
|
case PX4_BOARD_FMUV5:
|
2019-02-06 17:09:34 -04:00
|
|
|
case PX4_BOARD_FMUV6:
|
2018-02-14 01:35:40 -04:00
|
|
|
case PX4_BOARD_SP01:
|
2018-01-05 03:00:09 -04:00
|
|
|
case PX4_BOARD_PIXRACER:
|
|
|
|
case PX4_BOARD_PHMINI:
|
|
|
|
case PX4_BOARD_AUAV21:
|
|
|
|
case PX4_BOARD_PH2SLIM:
|
2018-02-03 09:51:34 -04:00
|
|
|
case VRX_BOARD_BRAIN51:
|
|
|
|
case VRX_BOARD_BRAIN52:
|
2018-02-03 10:19:25 -04:00
|
|
|
case VRX_BOARD_BRAIN52E:
|
2018-02-03 09:51:34 -04:00
|
|
|
case VRX_BOARD_UBRAIN51:
|
|
|
|
case VRX_BOARD_UBRAIN52:
|
|
|
|
case VRX_BOARD_CORE10:
|
|
|
|
case VRX_BOARD_BRAIN54:
|
2018-01-05 03:00:09 -04:00
|
|
|
case PX4_BOARD_AEROFC:
|
|
|
|
case PX4_BOARD_PIXHAWK_PRO:
|
|
|
|
case PX4_BOARD_PCNC1:
|
2018-01-11 17:26:14 -04:00
|
|
|
case PX4_BOARD_MINDPXV2:
|
2022-07-18 19:30:56 -03:00
|
|
|
case FMUV6_BOARD_HOLYBRO_6X:
|
2023-10-24 00:52:39 -03:00
|
|
|
case FMUV6_BOARD_HOLYBRO_6X_REV6:
|
2024-01-21 00:36:29 -04:00
|
|
|
case FMUV6_BOARD_HOLYBRO_6X_45686:
|
2022-07-18 19:30:56 -03:00
|
|
|
case FMUV6_BOARD_CUAV_6X:
|
2018-01-05 03:00:09 -04:00
|
|
|
break;
|
|
|
|
default:
|
2019-11-04 18:55:39 -04:00
|
|
|
config_error("Unknown board type");
|
2018-01-05 03:00:09 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-13 07:31:35 -03:00
|
|
|
#define SPI_PROBE_DEBUG 0
|
|
|
|
|
2018-01-05 03:00:09 -04:00
|
|
|
/*
|
|
|
|
check a SPI device for a register value
|
|
|
|
*/
|
|
|
|
bool AP_BoardConfig::spi_check_register(const char *devname, uint8_t regnum, uint8_t value, uint8_t read_flag)
|
|
|
|
{
|
|
|
|
auto dev = hal.spi->get_device(devname);
|
|
|
|
if (!dev) {
|
2018-07-13 07:31:35 -03:00
|
|
|
#if SPI_PROBE_DEBUG
|
2018-01-05 03:00:09 -04:00
|
|
|
hal.console->printf("%s: no device\n", devname);
|
2018-07-13 07:31:35 -03:00
|
|
|
#endif
|
2018-01-05 03:00:09 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
dev->set_read_flag(read_flag);
|
2023-10-24 00:52:39 -03:00
|
|
|
WITH_SEMAPHORE(dev->get_semaphore());
|
2020-09-13 12:23:14 -03:00
|
|
|
dev->set_speed(AP_HAL::Device::SPEED_LOW);
|
2018-01-05 03:00:09 -04:00
|
|
|
uint8_t v;
|
|
|
|
if (!dev->read_registers(regnum, &v, 1)) {
|
2018-07-13 07:31:35 -03:00
|
|
|
#if SPI_PROBE_DEBUG
|
2018-01-05 03:00:09 -04:00
|
|
|
hal.console->printf("%s: reg %02x read fail\n", devname, (unsigned)regnum);
|
2018-07-13 07:31:35 -03:00
|
|
|
#endif
|
2018-01-05 03:00:09 -04:00
|
|
|
return false;
|
|
|
|
}
|
2018-07-13 07:31:35 -03:00
|
|
|
#if SPI_PROBE_DEBUG
|
2018-01-05 03:00:09 -04:00
|
|
|
hal.console->printf("%s: reg %02x expected:%02x got:%02x\n", devname, (unsigned)regnum, (unsigned)value, (unsigned)v);
|
2018-07-13 07:31:35 -03:00
|
|
|
#endif
|
2018-01-05 03:00:09 -04:00
|
|
|
return v == value;
|
|
|
|
}
|
|
|
|
|
2020-09-13 12:23:14 -03:00
|
|
|
|
|
|
|
#define INV2REG_BANK_SEL 0x7F
|
|
|
|
/*
|
|
|
|
check a SPI device for a register value
|
|
|
|
*/
|
|
|
|
bool AP_BoardConfig::spi_check_register_inv2(const char *devname, uint8_t regnum, uint8_t value, uint8_t read_flag)
|
|
|
|
{
|
|
|
|
auto dev = hal.spi->get_device(devname);
|
|
|
|
if (!dev) {
|
|
|
|
#if SPI_PROBE_DEBUG
|
|
|
|
hal.console->printf("%s: no device\n", devname);
|
|
|
|
#endif
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
dev->set_read_flag(read_flag);
|
2023-10-24 00:52:39 -03:00
|
|
|
WITH_SEMAPHORE(dev->get_semaphore());
|
2020-09-13 12:23:14 -03:00
|
|
|
dev->set_speed(AP_HAL::Device::SPEED_LOW);
|
|
|
|
uint8_t v;
|
|
|
|
// select bank 0 for who am i
|
|
|
|
dev->write_register(INV2REG_BANK_SEL, 0, false);
|
|
|
|
if (!dev->read_registers(regnum, &v, 1)) {
|
|
|
|
#if SPI_PROBE_DEBUG
|
|
|
|
hal.console->printf("%s: reg %02x read fail\n", devname, (unsigned)regnum);
|
|
|
|
#endif
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#if SPI_PROBE_DEBUG
|
|
|
|
hal.console->printf("%s: reg %02x expected:%02x got:%02x\n", devname, (unsigned)regnum, (unsigned)value, (unsigned)v);
|
|
|
|
#endif
|
|
|
|
return v == value;
|
|
|
|
}
|
|
|
|
|
2020-04-23 23:06:21 -03:00
|
|
|
#if defined(HAL_VALIDATE_BOARD)
|
2020-04-27 20:02:33 -03:00
|
|
|
bool AP_BoardConfig::check_ms5611(const char* devname) {
|
2019-04-23 17:20:37 -03:00
|
|
|
auto dev = hal.spi->get_device(devname);
|
2019-04-23 19:39:47 -03:00
|
|
|
if (!dev) {
|
2019-04-23 17:20:37 -03:00
|
|
|
#if SPI_PROBE_DEBUG
|
|
|
|
hal.console->printf("%s: no device\n", devname);
|
|
|
|
#endif
|
|
|
|
return false;
|
|
|
|
}
|
2019-04-23 19:39:47 -03:00
|
|
|
|
|
|
|
AP_HAL::Semaphore *dev_sem = dev->get_semaphore();
|
|
|
|
|
2020-01-18 17:42:32 -04:00
|
|
|
if (!dev_sem) {
|
2019-04-23 17:20:37 -03:00
|
|
|
return false;
|
|
|
|
}
|
2023-10-24 00:52:39 -03:00
|
|
|
WITH_SEMAPHORE(dev_sem);
|
2019-04-23 17:20:37 -03:00
|
|
|
|
|
|
|
static const uint8_t CMD_MS56XX_RESET = 0x1E;
|
|
|
|
static const uint8_t CMD_MS56XX_PROM = 0xA0;
|
|
|
|
|
|
|
|
dev->transfer(&CMD_MS56XX_RESET, 1, nullptr, 0);
|
|
|
|
hal.scheduler->delay(4);
|
|
|
|
|
|
|
|
uint16_t prom[8];
|
|
|
|
bool all_zero = true;
|
|
|
|
for (uint8_t i = 0; i < 8; i++) {
|
|
|
|
const uint8_t reg = CMD_MS56XX_PROM + (i << 1);
|
|
|
|
uint8_t val[2];
|
|
|
|
if (!dev->transfer(®, 1, val, sizeof(val))) {
|
|
|
|
#if SPI_PROBE_DEBUG
|
|
|
|
hal.console->printf("%s: transfer fail\n", devname);
|
|
|
|
#endif
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
prom[i] = (val[0] << 8) | val[1];
|
|
|
|
|
|
|
|
if (prom[i] != 0) {
|
|
|
|
all_zero = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t crc_read = prom[7]&0xf;
|
|
|
|
prom[7] &= 0xff00;
|
|
|
|
|
2019-04-25 17:40:01 -03:00
|
|
|
if (crc_read != crc_crc4(prom) || all_zero) {
|
2019-04-23 17:20:37 -03:00
|
|
|
#if SPI_PROBE_DEBUG
|
|
|
|
hal.console->printf("%s: crc fail\n", devname);
|
|
|
|
#endif
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if SPI_PROBE_DEBUG
|
|
|
|
hal.console->printf("%s: found successfully\n", devname);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2020-04-23 23:06:21 -03:00
|
|
|
#endif // HAL_VALIDATE_BOARD
|
2019-04-23 17:20:37 -03:00
|
|
|
|
2018-01-05 03:00:09 -04:00
|
|
|
#define MPUREG_WHOAMI 0x75
|
|
|
|
#define MPU_WHOAMI_MPU60X0 0x68
|
|
|
|
#define MPU_WHOAMI_MPU9250 0x71
|
|
|
|
#define MPU_WHOAMI_ICM20608 0xaf
|
|
|
|
#define MPU_WHOAMI_ICM20602 0x12
|
|
|
|
|
|
|
|
#define LSMREG_WHOAMI 0x0f
|
|
|
|
#define LSM_WHOAMI_LSM303D 0x49
|
2019-04-23 17:20:37 -03:00
|
|
|
#define LSM_WHOAMI_L3GD20 0xd4
|
2018-01-05 03:00:09 -04:00
|
|
|
|
2019-01-22 22:27:43 -04:00
|
|
|
#define INV2REG_WHOAMI 0x00
|
2020-09-13 12:23:14 -03:00
|
|
|
|
2019-01-22 22:27:43 -04:00
|
|
|
#define INV2_WHOAMI_ICM20948 0xEA
|
2020-03-17 10:48:50 -03:00
|
|
|
#define INV2_WHOAMI_ICM20649 0xE1
|
2019-04-23 17:20:37 -03:00
|
|
|
|
2022-03-20 05:18:40 -03:00
|
|
|
#define INV3REG_WHOAMI 0x75
|
2023-10-24 00:52:39 -03:00
|
|
|
#define INV3REG_456_WHOAMI 0x72
|
2022-03-20 05:18:40 -03:00
|
|
|
|
|
|
|
#define INV3_WHOAMI_ICM42688 0x47
|
2022-07-19 02:21:18 -03:00
|
|
|
#define INV3_WHOAMI_ICM42670 0x67
|
2022-10-21 04:01:02 -03:00
|
|
|
#define INV3_WHOAMI_ICM45686 0xE9
|
2023-10-24 00:52:39 -03:00
|
|
|
#define INV3_WHOAMI_IIM42652 0x6f
|
|
|
|
|
2018-01-05 03:00:09 -04:00
|
|
|
/*
|
|
|
|
validation of the board type
|
|
|
|
*/
|
|
|
|
void AP_BoardConfig::validate_board_type(void)
|
|
|
|
{
|
|
|
|
/* some boards can be damaged by the user setting the wrong board
|
|
|
|
type. The key one is the cube which has a heater which can
|
|
|
|
cook the IMUs if the user uses an old paramater file. We
|
|
|
|
override the board type for that specific case
|
|
|
|
*/
|
2022-06-27 08:47:37 -03:00
|
|
|
#if defined(HAL_CHIBIOS_ARCH_FMUV3)
|
2018-01-05 03:00:09 -04:00
|
|
|
if (state.board_type == PX4_BOARD_PIXHAWK &&
|
|
|
|
(spi_check_register("mpu6000_ext", MPUREG_WHOAMI, MPU_WHOAMI_MPU60X0) ||
|
|
|
|
spi_check_register("mpu9250_ext", MPUREG_WHOAMI, MPU_WHOAMI_MPU9250) ||
|
|
|
|
spi_check_register("icm20608", MPUREG_WHOAMI, MPU_WHOAMI_ICM20608) ||
|
2019-01-22 22:27:43 -04:00
|
|
|
spi_check_register("icm20608_ext", MPUREG_WHOAMI, MPU_WHOAMI_ICM20602) ||
|
|
|
|
spi_check_register("icm20602_ext", MPUREG_WHOAMI, MPU_WHOAMI_ICM20602)) &&
|
|
|
|
(spi_check_register("lsm9ds0_ext_am", LSMREG_WHOAMI, LSM_WHOAMI_LSM303D) ||
|
2020-09-13 12:23:14 -03:00
|
|
|
spi_check_register_inv2("icm20948_ext", INV2REG_WHOAMI, INV2_WHOAMI_ICM20948))) {
|
2018-01-05 03:00:09 -04:00
|
|
|
// Pixhawk2 has LSM303D and MPUxxxx on external bus. If we
|
|
|
|
// detect those, then force PIXHAWK2, even if the user has
|
|
|
|
// configured for PIXHAWK1
|
2022-06-27 08:47:37 -03:00
|
|
|
#if !defined(HAL_CHIBIOS_ARCH_FMUV3)
|
2018-01-05 03:00:09 -04:00
|
|
|
// force user to load the right firmware
|
2019-11-04 18:55:39 -04:00
|
|
|
config_error("Pixhawk2 requires FMUv3 firmware");
|
2018-01-05 03:00:09 -04:00
|
|
|
#endif
|
|
|
|
state.board_type.set(PX4_BOARD_PIXHAWK2);
|
2022-03-21 06:34:32 -03:00
|
|
|
DEV_PRINTF("Forced PIXHAWK2\n");
|
2018-01-05 03:00:09 -04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
auto-detect board type
|
|
|
|
*/
|
|
|
|
void AP_BoardConfig::board_autodetect(void)
|
|
|
|
{
|
2020-03-17 10:48:50 -03:00
|
|
|
#if defined(HAL_VALIDATE_BOARD)
|
2023-04-26 01:09:24 -03:00
|
|
|
if((_options & SKIP_BOARD_VALIDATION) == 0) {
|
|
|
|
const char* errored_check = HAL_VALIDATE_BOARD;
|
|
|
|
if (errored_check == nullptr) {
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
config_error("Board Validation %s Failed", errored_check);
|
|
|
|
return;
|
|
|
|
}
|
2020-03-17 10:48:50 -03:00
|
|
|
}
|
2019-04-23 17:20:37 -03:00
|
|
|
#endif
|
|
|
|
|
2018-01-05 03:00:09 -04:00
|
|
|
if (state.board_type != PX4_BOARD_AUTO) {
|
|
|
|
validate_board_type();
|
|
|
|
// user has chosen a board type
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-06-27 08:47:37 -03:00
|
|
|
#if defined(HAL_CHIBIOS_ARCH_FMUV3)
|
2018-01-05 03:00:09 -04:00
|
|
|
if ((spi_check_register("mpu6000_ext", MPUREG_WHOAMI, MPU_WHOAMI_MPU60X0) ||
|
|
|
|
spi_check_register("mpu6000_ext", MPUREG_WHOAMI, MPU_WHOAMI_MPU60X0) ||
|
|
|
|
spi_check_register("mpu9250_ext", MPUREG_WHOAMI, MPU_WHOAMI_MPU60X0) ||
|
|
|
|
spi_check_register("mpu9250_ext", MPUREG_WHOAMI, MPU_WHOAMI_MPU9250) ||
|
|
|
|
spi_check_register("icm20608_ext", MPUREG_WHOAMI, MPU_WHOAMI_ICM20608) ||
|
2019-01-22 22:27:43 -04:00
|
|
|
spi_check_register("icm20608_ext", MPUREG_WHOAMI, MPU_WHOAMI_ICM20602) ||
|
|
|
|
spi_check_register("icm20602_ext", MPUREG_WHOAMI, MPU_WHOAMI_ICM20602)) &&
|
|
|
|
(spi_check_register("lsm9ds0_ext_am", LSMREG_WHOAMI, LSM_WHOAMI_LSM303D) ||
|
2020-09-13 12:23:14 -03:00
|
|
|
spi_check_register_inv2("icm20948_ext", INV2REG_WHOAMI, INV2_WHOAMI_ICM20948))) {
|
2018-01-05 03:00:09 -04:00
|
|
|
// Pixhawk2 has LSM303D and MPUxxxx on external bus
|
|
|
|
state.board_type.set(PX4_BOARD_PIXHAWK2);
|
2022-03-21 06:34:32 -03:00
|
|
|
DEV_PRINTF("Detected PIXHAWK2\n");
|
2018-01-05 03:00:09 -04:00
|
|
|
} else if ((spi_check_register("icm20608-am", MPUREG_WHOAMI, MPU_WHOAMI_ICM20608) ||
|
|
|
|
spi_check_register("icm20608-am", MPUREG_WHOAMI, MPU_WHOAMI_ICM20602)) &&
|
|
|
|
spi_check_register("mpu9250", MPUREG_WHOAMI, MPU_WHOAMI_MPU9250)) {
|
|
|
|
// PHMINI has an ICM20608 and MPU9250 on sensor bus
|
|
|
|
state.board_type.set(PX4_BOARD_PHMINI);
|
2022-03-21 06:34:32 -03:00
|
|
|
DEV_PRINTF("Detected PixhawkMini\n");
|
2018-01-05 03:00:09 -04:00
|
|
|
} else if (spi_check_register("lsm9ds0_am", LSMREG_WHOAMI, LSM_WHOAMI_LSM303D) &&
|
|
|
|
(spi_check_register("mpu6000", MPUREG_WHOAMI, MPU_WHOAMI_MPU60X0) ||
|
|
|
|
spi_check_register("icm20608", MPUREG_WHOAMI, MPU_WHOAMI_ICM20608) ||
|
|
|
|
spi_check_register("icm20608", MPUREG_WHOAMI, MPU_WHOAMI_ICM20602) ||
|
|
|
|
spi_check_register("mpu9250", MPUREG_WHOAMI, MPU_WHOAMI_MPU9250))) {
|
|
|
|
|
|
|
|
// classic or upgraded Pixhawk1
|
|
|
|
state.board_type.set(PX4_BOARD_PIXHAWK);
|
2022-03-21 06:34:32 -03:00
|
|
|
DEV_PRINTF("Detected Pixhawk\n");
|
2018-01-05 03:00:09 -04:00
|
|
|
} else {
|
2019-11-04 18:55:39 -04:00
|
|
|
config_error("Unable to detect board type");
|
2018-01-05 03:00:09 -04:00
|
|
|
}
|
2022-06-27 08:47:37 -03:00
|
|
|
#elif defined(HAL_CHIBIOS_ARCH_FMUV4)
|
2018-01-05 03:00:09 -04:00
|
|
|
// only one choice
|
|
|
|
state.board_type.set_and_notify(PX4_BOARD_PIXRACER);
|
2022-03-21 06:34:32 -03:00
|
|
|
DEV_PRINTF("Detected Pixracer\n");
|
2018-01-11 17:26:14 -04:00
|
|
|
#elif defined(HAL_CHIBIOS_ARCH_MINDPXV2)
|
|
|
|
// only one choice
|
|
|
|
state.board_type.set_and_notify(PX4_BOARD_MINDPXV2);
|
2022-03-21 06:34:32 -03:00
|
|
|
DEV_PRINTF("Detected MindPX-V2\n");
|
2022-06-27 08:47:37 -03:00
|
|
|
#elif defined(HAL_CHIBIOS_ARCH_FMUV4PRO)
|
2018-01-05 03:00:09 -04:00
|
|
|
// only one choice
|
|
|
|
state.board_type.set_and_notify(PX4_BOARD_PIXHAWK_PRO);
|
2022-03-21 06:34:32 -03:00
|
|
|
DEV_PRINTF("Detected Pixhawk Pro\n");
|
2018-05-29 08:43:01 -03:00
|
|
|
#elif defined(HAL_CHIBIOS_ARCH_FMUV5)
|
|
|
|
state.board_type.set_and_notify(PX4_BOARD_FMUV5);
|
2022-03-21 06:34:32 -03:00
|
|
|
DEV_PRINTF("Detected FMUv5\n");
|
2019-02-06 17:09:34 -04:00
|
|
|
#elif defined(HAL_CHIBIOS_ARCH_FMUV6)
|
2022-07-18 19:30:56 -03:00
|
|
|
detect_fmuv6_variant();
|
2022-06-27 08:47:37 -03:00
|
|
|
#elif defined(HAL_CHIBIOS_ARCH_BRAINV51)
|
2018-02-03 09:51:34 -04:00
|
|
|
state.board_type.set_and_notify(VRX_BOARD_BRAIN51);
|
2022-03-21 06:34:32 -03:00
|
|
|
DEV_PRINTF("Detected VR Brain 5.1\n");
|
2022-06-27 08:47:37 -03:00
|
|
|
#elif defined(HAL_CHIBIOS_ARCH_BRAINV52)
|
2018-02-03 09:51:34 -04:00
|
|
|
state.board_type.set_and_notify(VRX_BOARD_BRAIN52);
|
2022-03-21 06:34:32 -03:00
|
|
|
DEV_PRINTF("Detected VR Brain 5.2\n");
|
2022-06-27 08:47:37 -03:00
|
|
|
#elif defined(HAL_CHIBIOS_ARCH_UBRAINV51)
|
2018-02-03 09:51:34 -04:00
|
|
|
state.board_type.set_and_notify(VRX_BOARD_UBRAIN51);
|
2022-03-21 06:34:32 -03:00
|
|
|
DEV_PRINTF("Detected VR Micro Brain 5.1\n");
|
2022-06-27 08:47:37 -03:00
|
|
|
#elif defined(HAL_CHIBIOS_ARCH_COREV10)
|
2018-02-03 09:51:34 -04:00
|
|
|
state.board_type.set_and_notify(VRX_BOARD_CORE10);
|
2022-03-21 06:34:32 -03:00
|
|
|
DEV_PRINTF("Detected VR Core 1.0\n");
|
2022-06-27 08:47:37 -03:00
|
|
|
#elif defined(HAL_CHIBIOS_ARCH_BRAINV54)
|
2018-02-03 09:51:34 -04:00
|
|
|
state.board_type.set_and_notify(VRX_BOARD_BRAIN54);
|
2022-03-21 06:34:32 -03:00
|
|
|
DEV_PRINTF("Detected VR Brain 5.4\n");
|
2018-01-05 03:00:09 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-01-07 19:29:53 -04:00
|
|
|
#endif // AP_FEATURE_BOARD_DETECT
|
|
|
|
|
|
|
|
/*
|
|
|
|
setup flow control on UARTs
|
|
|
|
*/
|
|
|
|
void AP_BoardConfig::board_setup_uart()
|
|
|
|
{
|
|
|
|
#if AP_FEATURE_RTSCTS
|
2020-10-02 07:11:03 -03:00
|
|
|
#ifdef HAL_HAVE_RTSCTS_SERIAL1
|
2020-12-10 20:18:37 -04:00
|
|
|
if (hal.serial(1) != nullptr) {
|
|
|
|
hal.serial(1)->set_flow_control((AP_HAL::UARTDriver::flow_control)state.ser_rtscts[1].get());
|
2020-10-02 07:11:03 -03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef HAL_HAVE_RTSCTS_SERIAL2
|
2020-12-10 20:18:37 -04:00
|
|
|
if (hal.serial(2) != nullptr) {
|
|
|
|
hal.serial(2)->set_flow_control((AP_HAL::UARTDriver::flow_control)state.ser_rtscts[2].get());
|
2018-01-07 19:29:53 -04:00
|
|
|
}
|
|
|
|
#endif
|
2020-10-02 07:11:03 -03:00
|
|
|
#ifdef HAL_HAVE_RTSCTS_SERIAL3
|
2020-12-10 20:18:37 -04:00
|
|
|
if (hal.serial(3) != nullptr) {
|
|
|
|
hal.serial(3)->set_flow_control((AP_HAL::UARTDriver::flow_control)state.ser_rtscts[3].get());
|
2020-10-02 07:11:03 -03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef HAL_HAVE_RTSCTS_SERIAL4
|
2020-12-10 20:18:37 -04:00
|
|
|
if (hal.serial(4) != nullptr) {
|
|
|
|
hal.serial(4)->set_flow_control((AP_HAL::UARTDriver::flow_control)state.ser_rtscts[4].get());
|
2020-10-02 07:11:03 -03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef HAL_HAVE_RTSCTS_SERIAL5
|
2020-12-10 20:18:37 -04:00
|
|
|
if (hal.serial(5) != nullptr) {
|
|
|
|
hal.serial(5)->set_flow_control((AP_HAL::UARTDriver::flow_control)state.ser_rtscts[5].get());
|
2020-10-02 07:11:03 -03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
2018-01-07 19:29:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
setup SBUS
|
|
|
|
*/
|
|
|
|
void AP_BoardConfig::board_setup_sbus(void)
|
|
|
|
{
|
|
|
|
#if AP_FEATURE_SBUS_OUT
|
|
|
|
if (state.sbus_out_rate.get() >= 1) {
|
|
|
|
static const struct {
|
|
|
|
uint8_t value;
|
|
|
|
uint16_t rate;
|
|
|
|
} rates[] = {
|
|
|
|
{ 1, 50 },
|
|
|
|
{ 2, 75 },
|
|
|
|
{ 3, 100 },
|
|
|
|
{ 4, 150 },
|
|
|
|
{ 5, 200 },
|
|
|
|
{ 6, 250 },
|
|
|
|
{ 7, 300 }
|
|
|
|
};
|
|
|
|
uint16_t rate = 300;
|
|
|
|
for (uint8_t i=0; i<ARRAY_SIZE(rates); i++) {
|
|
|
|
if (rates[i].value == state.sbus_out_rate) {
|
|
|
|
rate = rates[i].rate;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!hal.rcout->enable_px4io_sbus_out(rate)) {
|
|
|
|
hal.console->printf("Failed to enable SBUS out\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-05 03:00:09 -04:00
|
|
|
/*
|
|
|
|
setup peripherals and drivers
|
|
|
|
*/
|
|
|
|
void AP_BoardConfig::board_setup()
|
|
|
|
{
|
2019-02-25 01:13:46 -04:00
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS
|
2018-01-06 05:42:30 -04:00
|
|
|
// init needs to be done after boardconfig is read so parameters are set
|
|
|
|
hal.gpio->init();
|
|
|
|
hal.rcin->init();
|
|
|
|
hal.rcout->init();
|
2018-01-05 03:00:09 -04:00
|
|
|
#endif
|
2019-03-29 09:08:35 -03:00
|
|
|
|
2019-04-01 23:44:38 -03:00
|
|
|
#ifdef HAL_GPIO_PWM_VOLT_PIN
|
2019-03-29 09:08:35 -03:00
|
|
|
if (_pwm_volt_sel == 0) {
|
2020-07-17 19:10:09 -03:00
|
|
|
hal.gpio->write(HAL_GPIO_PWM_VOLT_PIN, HAL_GPIO_PWM_VOLT_3v3); //set pin for 3.3V PWM Output
|
2019-03-29 09:08:35 -03:00
|
|
|
} else if (_pwm_volt_sel == 1) {
|
2020-07-17 19:10:09 -03:00
|
|
|
hal.gpio->write(HAL_GPIO_PWM_VOLT_PIN, !HAL_GPIO_PWM_VOLT_3v3); //set pin for 5V PWM Output
|
2019-03-29 09:08:35 -03:00
|
|
|
}
|
|
|
|
#endif
|
2018-01-05 03:00:09 -04:00
|
|
|
board_setup_uart();
|
|
|
|
board_setup_sbus();
|
2018-01-07 19:29:53 -04:00
|
|
|
#if AP_FEATURE_BOARD_DETECT
|
2018-01-05 03:00:09 -04:00
|
|
|
board_setup_drivers();
|
2018-01-07 19:29:53 -04:00
|
|
|
#endif
|
2018-01-05 03:00:09 -04:00
|
|
|
}
|
|
|
|
|
2022-07-18 19:30:56 -03:00
|
|
|
|
|
|
|
#ifdef HAL_CHIBIOS_ARCH_FMUV6
|
2022-07-19 02:21:18 -03:00
|
|
|
|
|
|
|
#define BMI088REG_CHIPID 0x00
|
|
|
|
#define CHIPID_BMI088_G 0x0F
|
|
|
|
|
2022-07-18 19:30:56 -03:00
|
|
|
/*
|
|
|
|
detect which FMUV6 variant we are running on
|
|
|
|
*/
|
|
|
|
void AP_BoardConfig::detect_fmuv6_variant()
|
|
|
|
{
|
2022-07-19 02:21:18 -03:00
|
|
|
if (((spi_check_register_inv2("icm20649", INV2REG_WHOAMI, INV2_WHOAMI_ICM20649) ||
|
|
|
|
spi_check_register("bmi088_g", BMI088REG_CHIPID, CHIPID_BMI088_G)) && // alternative config
|
|
|
|
spi_check_register("icm42688", INV3REG_WHOAMI, INV3_WHOAMI_ICM42688) &&
|
|
|
|
spi_check_register("icm42670", INV3REG_WHOAMI, INV3_WHOAMI_ICM42670))) {
|
2022-07-18 19:30:56 -03:00
|
|
|
state.board_type.set_and_notify(FMUV6_BOARD_HOLYBRO_6X);
|
|
|
|
DEV_PRINTF("Detected Holybro 6X\n");
|
|
|
|
} else if ((spi_check_register_inv2("icm20649_2", INV2REG_WHOAMI, INV2_WHOAMI_ICM20649) &&
|
2022-07-19 02:21:18 -03:00
|
|
|
spi_check_register("icm42688", INV3REG_WHOAMI, INV3_WHOAMI_ICM42688) &&
|
|
|
|
spi_check_register("bmi088_g", BMI088REG_CHIPID, CHIPID_BMI088_G))) {
|
2022-07-18 19:30:56 -03:00
|
|
|
state.board_type.set_and_notify(FMUV6_BOARD_CUAV_6X);
|
|
|
|
DEV_PRINTF("Detected CUAV 6X\n");
|
2022-09-13 06:27:06 -03:00
|
|
|
AP_Param::load_defaults_file("@ROMFS/param/CUAV_V6X_defaults.parm", false);
|
2024-01-21 00:36:29 -04:00
|
|
|
} else if (spi_check_register("icm45686-1", INV3REG_456_WHOAMI, INV3_WHOAMI_ICM45686) &&
|
|
|
|
spi_check_register("icm45686-2", INV3REG_456_WHOAMI, INV3_WHOAMI_ICM45686) &&
|
|
|
|
spi_check_register("icm45686-3", INV3REG_456_WHOAMI, INV3_WHOAMI_ICM45686)) {
|
|
|
|
state.board_type.set_and_notify(FMUV6_BOARD_HOLYBRO_6X_45686);
|
|
|
|
DEV_PRINTF("Detected Holybro 6X_45686\n");
|
2023-10-24 00:52:39 -03:00
|
|
|
} else if (spi_check_register("iim42652", INV3REG_WHOAMI, INV3_WHOAMI_IIM42652) &&
|
|
|
|
spi_check_register("icm45686", INV3REG_456_WHOAMI, INV3_WHOAMI_ICM45686)) {
|
|
|
|
state.board_type.set_and_notify(FMUV6_BOARD_HOLYBRO_6X_REV6);
|
|
|
|
DEV_PRINTF("Detected Holybro 6X_Rev6\n");
|
2022-07-18 19:30:56 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|