diff --git a/.gitignore b/.gitignore index 86b85dc44..67e2f3cbe 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ obj/ patches/ startup_stm32f10x_md_gcc.s +.idea # script-generated files docs/Manual.pdf diff --git a/Makefile b/Makefile index d53e7dc24..5df29e470 100644 --- a/Makefile +++ b/Makefile @@ -123,7 +123,7 @@ endif -include $(ROOT)/src/main/target/$(BASE_TARGET)/target.mk F4_TARGETS = $(F405_TARGETS) $(F411_TARGETS) -F7_TARGETS = $(F7X5XE_TARGETS) $(F7X5XG_TARGETS) $(F7X5XI_TARGETS) +F7_TARGETS = $(F7X5XE_TARGETS) $(F7X5XG_TARGETS) $(F7X5XI_TARGETS) $(F7X6XG_TARGETS) ifeq ($(filter $(TARGET),$(VALID_TARGETS)),) $(error Target '$(TARGET)' is not valid, must be one of $(VALID_TARGETS). Have you prepared a valid target.mk?) @@ -136,7 +136,7 @@ endif 128K_TARGETS = $(F1_TARGETS) 256K_TARGETS = $(F3_TARGETS) 512K_TARGETS = $(F411_TARGETS) $(F7X5XE_TARGETS) -1024K_TARGETS = $(F405_TARGETS) $(F7X5XG_TARGETS) +1024K_TARGETS = $(F405_TARGETS) $(F7X5XG_TARGETS) $(F7X6XG_TARGETS) 2048K_TARGETS = $(F7X5XI_TARGETS) # Configure default flash sizes for the targets (largest size specified gets hit first) if flash not specified already. @@ -376,6 +376,9 @@ ARCH_FLAGS = -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-sp-d16 -fs ifeq ($(TARGET),$(filter $(TARGET),$(F7X5XG_TARGETS))) DEVICE_FLAGS = -DSTM32F745xx -DUSE_HAL_DRIVER -D__FPU_PRESENT LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f745.ld +else ifeq ($(TARGET),$(filter $(TARGET),$(F7X6XG_TARGETS))) +DEVICE_FLAGS = -DSTM32F746xx -DUSE_HAL_DRIVER -D__FPU_PRESENT +LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f746.ld else $(error Unknown MCU for F7 target) endif @@ -593,7 +596,7 @@ HIGHEND_SRC = \ telemetry/smartport.c \ telemetry/ltm.c \ telemetry/mavlink.c \ - telemetry/esc_telemetry.c \ + sensors/esc_sensor.c \ SPEED_OPTIMISED_SRC = \ common/encoding.c \ diff --git a/src/main/build/debug.h b/src/main/build/debug.h index 6b2e7ca9f..cd6fc1d78 100644 --- a/src/main/build/debug.h +++ b/src/main/build/debug.h @@ -59,7 +59,7 @@ typedef enum { DEBUG_VELOCITY, DEBUG_DTERM_FILTER, DEBUG_ANGLERATE, - DEBUG_ESC_TELEMETRY, + DEBUG_ESC_SENSOR, DEBUG_SCHEDULER, DEBUG_STACK, DEBUG_COUNT diff --git a/src/main/config/config_eeprom.c b/src/main/config/config_eeprom.c index 0cc02f1f3..18c25d68b 100644 --- a/src/main/config/config_eeprom.c +++ b/src/main/config/config_eeprom.c @@ -51,6 +51,10 @@ #define FLASH_PAGE_SIZE ((uint32_t)0x40000) #endif + #if defined(STM32F746xx) + #define FLASH_PAGE_SIZE ((uint32_t)0x40000) + #endif + #if defined(STM32F40_41xxx) #define FLASH_PAGE_SIZE ((uint32_t)0x20000) #endif @@ -78,6 +82,8 @@ #define FLASH_PAGE_COUNT 3 // just to make calculations work #elif defined (STM32F745xx) #define FLASH_PAGE_COUNT 4 // just to make calculations work +#elif defined (STM32F746xx) +#define FLASH_PAGE_COUNT 4 // just to make calculations work #else #define FLASH_PAGE_COUNT ((FLASH_SIZE * 0x400) / FLASH_PAGE_SIZE) #endif diff --git a/src/main/config/config_master.h b/src/main/config/config_master.h index addefdef1..45af459a7 100644 --- a/src/main/config/config_master.h +++ b/src/main/config/config_master.h @@ -31,6 +31,8 @@ #include "drivers/sonar_hcsr04.h" #include "drivers/sdcard.h" #include "drivers/vcd.h" +#include "drivers/light_led.h" +#include "drivers/flash.h" #include "fc/rc_controls.h" @@ -90,10 +92,12 @@ #define beeperConfig(x) (&masterConfig.beeperConfig) #define sonarConfig(x) (&masterConfig.sonarConfig) #define ledStripConfig(x) (&masterConfig.ledStripConfig) +#define statusLedConfig(x) (&masterConfig.statusLedConfig) #define osdProfile(x) (&masterConfig.osdProfile) #define vcdProfile(x) (&masterConfig.vcdProfile) #define sdcardConfig(x) (&masterConfig.sdcardConfig) #define blackboxConfig(x) (&masterConfig.blackboxConfig) +#define flashConfig(x) (&masterConfig.flashConfig) // System-wide @@ -162,6 +166,8 @@ typedef struct master_s { serialConfig_t serialConfig; telemetryConfig_t telemetryConfig; + statusLedConfig_t statusLedConfig; + #ifdef USE_PPM ppmConfig_t ppmConfig; #endif @@ -226,6 +232,10 @@ typedef struct master_s { blackboxConfig_t blackboxConfig; #endif +#ifdef USE_FLASHFS + flashConfig_t flashConfig; +#endif + uint32_t beeper_off_flags; uint32_t preferred_beeper_off_flags; diff --git a/src/main/drivers/accgyro_adxl345.c b/src/main/drivers/accgyro_adxl345.c index 86ee11f4f..122062318 100644 --- a/src/main/drivers/accgyro_adxl345.c +++ b/src/main/drivers/accgyro_adxl345.c @@ -56,27 +56,8 @@ #define ADXL345_RANGE_16G 0x03 #define ADXL345_FIFO_STREAM 0x80 -static void adxl345Init(accDev_t *acc); -static bool adxl345Read(int16_t *accelData); - static bool useFifo = false; -bool adxl345Detect(drv_adxl345_config_t *init, accDev_t *acc) -{ - uint8_t sig = 0; - bool ack = i2cRead(MPU_I2C_INSTANCE, ADXL345_ADDRESS, 0x00, 1, &sig); - - if (!ack || sig != 0xE5) - return false; - - // use ADXL345's fifo to filter data or not - useFifo = init->useFifo; - - acc->init = adxl345Init; - acc->read = adxl345Read; - return true; -} - static void adxl345Init(accDev_t *acc) { if (useFifo) { @@ -135,3 +116,19 @@ static bool adxl345Read(int16_t *accelData) return true; } + +bool adxl345Detect(drv_adxl345_config_t *init, accDev_t *acc) +{ + uint8_t sig = 0; + bool ack = i2cRead(MPU_I2C_INSTANCE, ADXL345_ADDRESS, 0x00, 1, &sig); + + if (!ack || sig != 0xE5) + return false; + + // use ADXL345's fifo to filter data or not + useFifo = init->useFifo; + + acc->init = adxl345Init; + acc->read = adxl345Read; + return true; +} diff --git a/src/main/drivers/accgyro_bma280.c b/src/main/drivers/accgyro_bma280.c index 3b0ec6e85..3c285a942 100644 --- a/src/main/drivers/accgyro_bma280.c +++ b/src/main/drivers/accgyro_bma280.c @@ -32,22 +32,6 @@ #define BMA280_PMU_BW 0x10 #define BMA280_PMU_RANGE 0x0F -static void bma280Init(accDev_t *acc); -static bool bma280Read(int16_t *accelData); - -bool bma280Detect(accDev_t *acc) -{ - uint8_t sig = 0; - bool ack = i2cRead(MPU_I2C_INSTANCE, BMA280_ADDRESS, 0x00, 1, &sig); - - if (!ack || sig != 0xFB) - return false; - - acc->init = bma280Init; - acc->read = bma280Read; - return true; -} - static void bma280Init(accDev_t *acc) { i2cWrite(MPU_I2C_INSTANCE, BMA280_ADDRESS, BMA280_PMU_RANGE, 0x08); // +-8g range @@ -71,3 +55,16 @@ static bool bma280Read(int16_t *accelData) return true; } + +bool bma280Detect(accDev_t *acc) +{ + uint8_t sig = 0; + bool ack = i2cRead(MPU_I2C_INSTANCE, BMA280_ADDRESS, 0x00, 1, &sig); + + if (!ack || sig != 0xFB) + return false; + + acc->init = bma280Init; + acc->read = bma280Read; + return true; +} diff --git a/src/main/drivers/accgyro_l3g4200d.c b/src/main/drivers/accgyro_l3g4200d.c index 2183bebdf..170bb0fe7 100644 --- a/src/main/drivers/accgyro_l3g4200d.c +++ b/src/main/drivers/accgyro_l3g4200d.c @@ -54,28 +54,6 @@ #define L3G4200D_DLPF_78HZ 0x80 #define L3G4200D_DLPF_93HZ 0xC0 -static void l3g4200dInit(gyroDev_t *gyro); -static bool l3g4200dRead(gyroDev_t *gyro); - -bool l3g4200dDetect(gyroDev_t *gyro) -{ - uint8_t deviceid; - - delay(25); - - i2cRead(MPU_I2C_INSTANCE, L3G4200D_ADDRESS, L3G4200D_WHO_AM_I, 1, &deviceid); - if (deviceid != L3G4200D_ID) - return false; - - gyro->init = l3g4200dInit; - gyro->read = l3g4200dRead; - - // 14.2857dps/lsb scalefactor - gyro->scale = 1.0f / 14.2857f; - - return true; -} - static void l3g4200dInit(gyroDev_t *gyro) { bool ack; @@ -123,3 +101,22 @@ static bool l3g4200dRead(gyroDev_t *gyro) return true; } + +bool l3g4200dDetect(gyroDev_t *gyro) +{ + uint8_t deviceid; + + delay(25); + + i2cRead(MPU_I2C_INSTANCE, L3G4200D_ADDRESS, L3G4200D_WHO_AM_I, 1, &deviceid); + if (deviceid != L3G4200D_ID) + return false; + + gyro->init = l3g4200dInit; + gyro->read = l3g4200dRead; + + // 14.2857dps/lsb scalefactor + gyro->scale = 1.0f / 14.2857f; + + return true; +} diff --git a/src/main/drivers/accgyro_mma845x.c b/src/main/drivers/accgyro_mma845x.c index c4b65fdcc..7dcb4ed19 100644 --- a/src/main/drivers/accgyro_mma845x.c +++ b/src/main/drivers/accgyro_mma845x.c @@ -81,23 +81,6 @@ static uint8_t device_id; -static void mma8452Init(accDev_t *acc); -static bool mma8452Read(int16_t *accelData); - -bool mma8452Detect(accDev_t *acc) -{ - uint8_t sig = 0; - bool ack = i2cRead(MPU_I2C_INSTANCE, MMA8452_ADDRESS, MMA8452_WHO_AM_I, 1, &sig); - - if (!ack || (sig != MMA8452_DEVICE_SIGNATURE && sig != MMA8451_DEVICE_SIGNATURE)) - return false; - - acc->init = mma8452Init; - acc->read = mma8452Read; - device_id = sig; - return true; -} - static inline void mma8451ConfigureInterrupt(void) { #ifdef NAZE @@ -142,3 +125,17 @@ static bool mma8452Read(int16_t *accelData) return true; } + +bool mma8452Detect(accDev_t *acc) +{ + uint8_t sig = 0; + bool ack = i2cRead(MPU_I2C_INSTANCE, MMA8452_ADDRESS, MMA8452_WHO_AM_I, 1, &sig); + + if (!ack || (sig != MMA8452_DEVICE_SIGNATURE && sig != MMA8451_DEVICE_SIGNATURE)) + return false; + + acc->init = mma8452Init; + acc->read = mma8452Read; + device_id = sig; + return true; +} diff --git a/src/main/drivers/accgyro_mpu.c b/src/main/drivers/accgyro_mpu.c index 3f59e2fb9..7c87b8fdd 100644 --- a/src/main/drivers/accgyro_mpu.c +++ b/src/main/drivers/accgyro_mpu.c @@ -75,7 +75,7 @@ static const extiConfig_t *mpuIntExtiConfig = NULL; #define MPU_INQUIRY_MASK 0x7E -mpuDetectionResult_t *detectMpu(const extiConfig_t *configToUse) +mpuDetectionResult_t *mpuDetect(const extiConfig_t *configToUse) { memset(&mpuDetectionResult, 0, sizeof(mpuDetectionResult)); memset(&mpuConfiguration, 0, sizeof(mpuConfiguration)); @@ -334,7 +334,7 @@ void mpuGyroInit(gyroDev_t *gyro) mpuIntExtiInit(gyro); } -bool checkMPUDataReady(gyroDev_t* gyro) +bool mpuCheckDataReady(gyroDev_t* gyro) { bool ret; if (gyro->dataReady) { diff --git a/src/main/drivers/accgyro_mpu.h b/src/main/drivers/accgyro_mpu.h index 2eafe89f0..cb97af5ce 100644 --- a/src/main/drivers/accgyro_mpu.h +++ b/src/main/drivers/accgyro_mpu.h @@ -183,10 +183,10 @@ typedef struct mpuDetectionResult_s { extern mpuDetectionResult_t mpuDetectionResult; -void configureMPUDataReadyInterruptHandling(void); +void mpuConfigureDataReadyInterruptHandling(void); struct gyroDev_s; void mpuGyroInit(struct gyroDev_s *gyro); bool mpuAccRead(int16_t *accData); bool mpuGyroRead(struct gyroDev_s *gyro); -mpuDetectionResult_t *detectMpu(const extiConfig_t *configToUse); -bool checkMPUDataReady(struct gyroDev_s *gyro); +mpuDetectionResult_t *mpuDetect(const extiConfig_t *configToUse); +bool mpuCheckDataReady(struct gyroDev_s *gyro); diff --git a/src/main/drivers/accgyro_mpu3050.c b/src/main/drivers/accgyro_mpu3050.c index 4d8d84fba..fe4692c20 100644 --- a/src/main/drivers/accgyro_mpu3050.c +++ b/src/main/drivers/accgyro_mpu3050.c @@ -46,25 +46,6 @@ #define MPU3050_USER_RESET 0x01 #define MPU3050_CLK_SEL_PLL_GX 0x01 -static void mpu3050Init(gyroDev_t *gyro); -static bool mpu3050ReadTemp(int16_t *tempData); - -bool mpu3050Detect(gyroDev_t *gyro) -{ - if (mpuDetectionResult.sensor != MPU_3050) { - return false; - } - gyro->init = mpu3050Init; - gyro->read = mpuGyroRead; - gyro->temperature = mpu3050ReadTemp; - gyro->intStatus = checkMPUDataReady; - - // 16.4 dps/lsb scalefactor - gyro->scale = 1.0f / 16.4f; - - return true; -} - static void mpu3050Init(gyroDev_t *gyro) { bool ack; @@ -81,7 +62,7 @@ static void mpu3050Init(gyroDev_t *gyro) mpuConfiguration.write(MPU3050_PWR_MGM, MPU3050_CLK_SEL_PLL_GX); } -static bool mpu3050ReadTemp(int16_t *tempData) +static bool mpu3050ReadTemperature(int16_t *tempData) { uint8_t buf[2]; if (!mpuConfiguration.read(MPU3050_TEMP_OUT, 2, buf)) { @@ -92,3 +73,19 @@ static bool mpu3050ReadTemp(int16_t *tempData) return true; } + +bool mpu3050Detect(gyroDev_t *gyro) +{ + if (mpuDetectionResult.sensor != MPU_3050) { + return false; + } + gyro->init = mpu3050Init; + gyro->read = mpuGyroRead; + gyro->temperature = mpu3050ReadTemperature; + gyro->intStatus = mpuCheckDataReady; + + // 16.4 dps/lsb scalefactor + gyro->scale = 1.0f / 16.4f; + + return true; +} diff --git a/src/main/drivers/accgyro_mpu6050.c b/src/main/drivers/accgyro_mpu6050.c index af91df4e8..35d475a3a 100644 --- a/src/main/drivers/accgyro_mpu6050.c +++ b/src/main/drivers/accgyro_mpu6050.c @@ -50,8 +50,17 @@ #define MPU6050_SMPLRT_DIV 0 // 8000Hz -static void mpu6050AccInit(accDev_t *acc); -static void mpu6050GyroInit(gyroDev_t *gyro); +static void mpu6050AccInit(accDev_t *acc) +{ + switch (mpuDetectionResult.resolution) { + case MPU_HALF_RESOLUTION: + acc->acc_1G = 256 * 4; + break; + case MPU_FULL_RESOLUTION: + acc->acc_1G = 512 * 4; + break; + } +} bool mpu6050AccDetect(accDev_t *acc) { @@ -66,33 +75,6 @@ bool mpu6050AccDetect(accDev_t *acc) return true; } -bool mpu6050GyroDetect(gyroDev_t *gyro) -{ - if (mpuDetectionResult.sensor != MPU_60x0) { - return false; - } - gyro->init = mpu6050GyroInit; - gyro->read = mpuGyroRead; - gyro->intStatus = checkMPUDataReady; - - // 16.4 dps/lsb scalefactor - gyro->scale = 1.0f / 16.4f; - - return true; -} - -static void mpu6050AccInit(accDev_t *acc) -{ - switch (mpuDetectionResult.resolution) { - case MPU_HALF_RESOLUTION: - acc->acc_1G = 256 * 4; - break; - case MPU_FULL_RESOLUTION: - acc->acc_1G = 512 * 4; - break; - } -} - static void mpu6050GyroInit(gyroDev_t *gyro) { mpuGyroInit(gyro); @@ -116,3 +98,18 @@ static void mpu6050GyroInit(gyroDev_t *gyro) mpuConfiguration.write(MPU_RA_INT_ENABLE, MPU_RF_DATA_RDY_EN); #endif } + +bool mpu6050GyroDetect(gyroDev_t *gyro) +{ + if (mpuDetectionResult.sensor != MPU_60x0) { + return false; + } + gyro->init = mpu6050GyroInit; + gyro->read = mpuGyroRead; + gyro->intStatus = mpuCheckDataReady; + + // 16.4 dps/lsb scalefactor + gyro->scale = 1.0f / 16.4f; + + return true; +} diff --git a/src/main/drivers/accgyro_mpu6500.c b/src/main/drivers/accgyro_mpu6500.c index d4257c15f..a5254ba59 100644 --- a/src/main/drivers/accgyro_mpu6500.c +++ b/src/main/drivers/accgyro_mpu6500.c @@ -34,6 +34,11 @@ #include "accgyro_mpu.h" #include "accgyro_mpu6500.h" +void mpu6500AccInit(accDev_t *acc) +{ + acc->acc_1G = 512 * 4; +} + bool mpu6500AccDetect(accDev_t *acc) { if (mpuDetectionResult.sensor != MPU_65xx_I2C) { @@ -46,27 +51,6 @@ bool mpu6500AccDetect(accDev_t *acc) return true; } -bool mpu6500GyroDetect(gyroDev_t *gyro) -{ - if (mpuDetectionResult.sensor != MPU_65xx_I2C) { - return false; - } - - gyro->init = mpu6500GyroInit; - gyro->read = mpuGyroRead; - gyro->intStatus = checkMPUDataReady; - - // 16.4 dps/lsb scalefactor - gyro->scale = 1.0f / 16.4f; - - return true; -} - -void mpu6500AccInit(accDev_t *acc) -{ - acc->acc_1G = 512 * 4; -} - void mpu6500GyroInit(gyroDev_t *gyro) { mpuGyroInit(gyro); @@ -101,3 +85,19 @@ void mpu6500GyroInit(gyroDev_t *gyro) #endif delay(15); } + +bool mpu6500GyroDetect(gyroDev_t *gyro) +{ + if (mpuDetectionResult.sensor != MPU_65xx_I2C) { + return false; + } + + gyro->init = mpu6500GyroInit; + gyro->read = mpuGyroRead; + gyro->intStatus = mpuCheckDataReady; + + // 16.4 dps/lsb scalefactor + gyro->scale = 1.0f / 16.4f; + + return true; +} diff --git a/src/main/drivers/accgyro_spi_icm20689.c b/src/main/drivers/accgyro_spi_icm20689.c index 95d94fccc..286e2171e 100644 --- a/src/main/drivers/accgyro_spi_icm20689.c +++ b/src/main/drivers/accgyro_spi_icm20689.c @@ -107,6 +107,11 @@ bool icm20689SpiDetect(void) } +void icm20689AccInit(accDev_t *acc) +{ + acc->acc_1G = 512 * 4; +} + bool icm20689SpiAccDetect(accDev_t *acc) { if (mpuDetectionResult.sensor != ICM_20689_SPI) { @@ -119,27 +124,6 @@ bool icm20689SpiAccDetect(accDev_t *acc) return true; } -bool icm20689SpiGyroDetect(gyroDev_t *gyro) -{ - if (mpuDetectionResult.sensor != ICM_20689_SPI) { - return false; - } - - gyro->init = icm20689GyroInit; - gyro->read = mpuGyroRead; - gyro->intStatus = checkMPUDataReady; - - // 16.4 dps/lsb scalefactor - gyro->scale = 1.0f / 16.4f; - - return true; -} - -void icm20689AccInit(accDev_t *acc) -{ - acc->acc_1G = 512 * 4; -} - void icm20689GyroInit(gyroDev_t *gyro) { mpuGyroInit(gyro); @@ -174,5 +158,20 @@ void icm20689GyroInit(gyroDev_t *gyro) #endif spiSetDivisor(ICM20689_SPI_INSTANCE, SPI_CLOCK_STANDARD); - +} + +bool icm20689SpiGyroDetect(gyroDev_t *gyro) +{ + if (mpuDetectionResult.sensor != ICM_20689_SPI) { + return false; + } + + gyro->init = icm20689GyroInit; + gyro->read = mpuGyroRead; + gyro->intStatus = mpuCheckDataReady; + + // 16.4 dps/lsb scalefactor + gyro->scale = 1.0f / 16.4f; + + return true; } diff --git a/src/main/drivers/accgyro_spi_mpu6000.c b/src/main/drivers/accgyro_spi_mpu6000.c index 2f0fe9443..67192ecef 100644 --- a/src/main/drivers/accgyro_spi_mpu6000.c +++ b/src/main/drivers/accgyro_spi_mpu6000.c @@ -274,7 +274,7 @@ bool mpu6000SpiGyroDetect(gyroDev_t *gyro) gyro->init = mpu6000SpiGyroInit; gyro->read = mpuGyroRead; - gyro->intStatus = checkMPUDataReady; + gyro->intStatus = mpuCheckDataReady; // 16.4 dps/lsb scalefactor gyro->scale = 1.0f / 16.4f; diff --git a/src/main/drivers/accgyro_spi_mpu6500.c b/src/main/drivers/accgyro_spi_mpu6500.c index b14a9ca93..a6a19f7ad 100755 --- a/src/main/drivers/accgyro_spi_mpu6500.c +++ b/src/main/drivers/accgyro_spi_mpu6500.c @@ -134,7 +134,7 @@ bool mpu6500SpiGyroDetect(gyroDev_t *gyro) gyro->init = mpu6500SpiGyroInit; gyro->read = mpuGyroRead; - gyro->intStatus = checkMPUDataReady; + gyro->intStatus = mpuCheckDataReady; // 16.4 dps/lsb scalefactor gyro->scale = 1.0f / 16.4f; diff --git a/src/main/drivers/accgyro_spi_mpu9250.c b/src/main/drivers/accgyro_spi_mpu9250.c index 81415fac1..8e9253a71 100644 --- a/src/main/drivers/accgyro_spi_mpu9250.c +++ b/src/main/drivers/accgyro_spi_mpu9250.c @@ -229,7 +229,7 @@ bool mpu9250SpiGyroDetect(gyroDev_t *gyro) gyro->init = mpu9250SpiGyroInit; gyro->read = mpuGyroRead; - gyro->intStatus = checkMPUDataReady; + gyro->intStatus = mpuCheckDataReady; // 16.4 dps/lsb scalefactor gyro->scale = 1.0f / 16.4f; diff --git a/src/main/drivers/flash.h b/src/main/drivers/flash.h index 21216825c..6a6f160b0 100644 --- a/src/main/drivers/flash.h +++ b/src/main/drivers/flash.h @@ -18,6 +18,7 @@ #pragma once #include +#include "drivers/io_types.h" typedef struct flashGeometry_s { uint16_t sectors; // Count of the number of erasable blocks on the device @@ -29,3 +30,7 @@ typedef struct flashGeometry_s { uint32_t totalSize; // This is just sectorSize * sectors } flashGeometry_t; + +typedef struct flashConfig_s { + ioTag_t csTag; +} flashConfig_t; diff --git a/src/main/drivers/flash_m25p16.c b/src/main/drivers/flash_m25p16.c index 67219ce30..c6429fe43 100644 --- a/src/main/drivers/flash_m25p16.c +++ b/src/main/drivers/flash_m25p16.c @@ -208,27 +208,21 @@ static bool m25p16_readIdentification() * Attempts to detect a connected m25p16. If found, true is returned and device capacity can be fetched with * m25p16_getGeometry(). */ -bool m25p16_init(ioTag_t csTag) +bool m25p16_init(flashConfig_t *flashConfig) { /* if we have already detected a flash device we can simply exit - - TODO: change the init param in favour of flash CFG when ParamGroups work is done - then cs pin can be specified in hardware_revision.c or config.c (dependent on revision). */ if (geometry.sectors) { return true; } - if (csTag) { - m25p16CsPin = IOGetByTag(csTag); + if (flashConfig->csTag) { + m25p16CsPin = IOGetByTag(flashConfig->csTag); } else { -#ifdef M25P16_CS_PIN - m25p16CsPin = IOGetByTag(IO_TAG(M25P16_CS_PIN)); -#else return false; -#endif } + IOInit(m25p16CsPin, OWNER_FLASH_CS, 0); IOConfigGPIO(m25p16CsPin, SPI_IO_CS_CFG); diff --git a/src/main/drivers/flash_m25p16.h b/src/main/drivers/flash_m25p16.h index ace78fc8b..f3cec0d9f 100644 --- a/src/main/drivers/flash_m25p16.h +++ b/src/main/drivers/flash_m25p16.h @@ -18,11 +18,11 @@ #pragma once #include -#include "io_types.h" +#include "flash.h" #define M25P16_PAGESIZE 256 -bool m25p16_init(ioTag_t csTag); +bool m25p16_init(flashConfig_t *flashConfig); void m25p16_eraseSector(uint32_t address); void m25p16_eraseCompletely(); diff --git a/src/main/drivers/light_led.c b/src/main/drivers/light_led.c index 1c9271883..8011f04cf 100644 --- a/src/main/drivers/light_led.c +++ b/src/main/drivers/light_led.c @@ -22,82 +22,23 @@ #include "light_led.h" -static const IO_t leds[] = { -#ifdef LED0 - DEFIO_IO(LED0), -#else - DEFIO_IO(NONE), -#endif -#ifdef LED1 - DEFIO_IO(LED1), -#else - DEFIO_IO(NONE), -#endif -#ifdef LED2 - DEFIO_IO(LED2), -#else - DEFIO_IO(NONE), -#endif -#if defined(LED0_A) || defined(LED1_A) || defined(LED2_A) -#ifdef LED0_A - DEFIO_IO(LED0_A), -#else - DEFIO_IO(NONE), -#endif -#ifdef LED1_A - DEFIO_IO(LED1_A), -#else - DEFIO_IO(NONE), -#endif -#ifdef LED2_A - DEFIO_IO(LED2_A), -#else - DEFIO_IO(NONE), -#endif -#endif -}; +static IO_t leds[LED_NUMBER]; +static uint8_t ledPolarity = 0; -uint8_t ledPolarity = 0 -#ifdef LED0_INVERTED - | BIT(0) -#endif -#ifdef LED1_INVERTED - | BIT(1) -#endif -#ifdef LED2_INVERTED - | BIT(2) -#endif -#ifdef LED0_A_INVERTED - | BIT(3) -#endif -#ifdef LED1_A_INVERTED - | BIT(4) -#endif -#ifdef LED2_A_INVERTED - | BIT(5) -#endif - ; - -static uint8_t ledOffset = 0; - -void ledInit(bool alternative_led) +void ledInit(statusLedConfig_t *statusLedConfig) { -#if defined(LED0_A) || defined(LED1_A) || defined(LED2_A) - if (alternative_led) { - ledOffset = LED_NUMBER; - } -#else - UNUSED(alternative_led); -#endif - LED0_OFF; LED1_OFF; LED2_OFF; + ledPolarity = statusLedConfig->polarity; for (int i = 0; i < LED_NUMBER; i++) { - if (leds[i + ledOffset]) { - IOInit(leds[i + ledOffset], OWNER_LED, RESOURCE_INDEX(i)); - IOConfigGPIO(leds[i + ledOffset], IOCFG_OUT_PP); + if (statusLedConfig->ledTags[i]) { + leds[i] = IOGetByTag(statusLedConfig->ledTags[i]); + IOInit(leds[i], OWNER_LED, RESOURCE_INDEX(i)); + IOConfigGPIO(leds[i], IOCFG_OUT_PP); + } else { + leds[i] = IO_NONE; } } @@ -108,11 +49,11 @@ void ledInit(bool alternative_led) void ledToggle(int led) { - IOToggle(leds[led + ledOffset]); + IOToggle(leds[led]); } void ledSet(int led, bool on) { - const bool inverted = (1 << (led + ledOffset)) & ledPolarity; - IOWrite(leds[led + ledOffset], on ? inverted : !inverted); + const bool inverted = (1 << (led)) & ledPolarity; + IOWrite(leds[led], on ? inverted : !inverted); } diff --git a/src/main/drivers/light_led.h b/src/main/drivers/light_led.h index 55814e1a1..d1ae47294 100644 --- a/src/main/drivers/light_led.h +++ b/src/main/drivers/light_led.h @@ -17,8 +17,15 @@ #pragma once +#include "drivers/io_types.h" + #define LED_NUMBER 3 +typedef struct statusLedConfig_s { + ioTag_t ledTags[LED_NUMBER]; + uint8_t polarity; +} statusLedConfig_t; + // Helpful macros #ifdef LED0 # define LED0_TOGGLE ledToggle(0) @@ -50,6 +57,6 @@ # define LED2_ON do {} while(0) #endif -void ledInit(bool alternative_led); +void ledInit(statusLedConfig_t *statusLedConfig); void ledToggle(int led); void ledSet(int led, bool state); diff --git a/src/main/drivers/pwm_output.c b/src/main/drivers/pwm_output.c index ed58b2529..90ad21c90 100644 --- a/src/main/drivers/pwm_output.c +++ b/src/main/drivers/pwm_output.c @@ -24,6 +24,7 @@ #include "io.h" #include "timer.h" #include "pwm_output.h" +#include "system.h" #define MULTISHOT_5US_PW (MULTISHOT_TIMER_MHZ * 5) #define MULTISHOT_20US_MULT (MULTISHOT_TIMER_MHZ * 20 / 1000.0f) @@ -280,3 +281,28 @@ void servoInit(const servoConfig_t *servoConfig) } #endif + +#ifdef BRUSHED_ESC_AUTODETECT +uint8_t hardwareMotorType = MOTOR_UNKNOWN; + +void detectBrushedESC(void) +{ + int i = 0; + while (!(timerHardware[i].usageFlags & TIM_USE_MOTOR) && (i < USABLE_TIMER_CHANNEL_COUNT)) { + i++; + } + + IO_t MotorDetectPin = IOGetByTag(timerHardware[i].tag); + IOInit(MotorDetectPin, OWNER_SYSTEM, 0); + IOConfigGPIO(MotorDetectPin, IOCFG_IPU); + + delayMicroseconds(10); // allow configuration to settle + + // Check presence of brushed ESC's + if (IORead(MotorDetectPin)) { + hardwareMotorType = MOTOR_BRUSHLESS; + } else { + hardwareMotorType = MOTOR_BRUSHED; + } +} +#endif diff --git a/src/main/drivers/pwm_output.h b/src/main/drivers/pwm_output.h index 9d94a1d07..8c6488298 100644 --- a/src/main/drivers/pwm_output.h +++ b/src/main/drivers/pwm_output.h @@ -114,3 +114,15 @@ pwmOutputPort_t *pwmGetMotors(void); bool pwmIsSynced(void); void pwmDisableMotors(void); void pwmEnableMotors(void); + +#ifdef BRUSHED_ESC_AUTODETECT +typedef enum { + MOTOR_UNKNOWN = 0, + MOTOR_BRUSHED, + MOTOR_BRUSHLESS +} HardwareMotorTypes_e; + +extern uint8_t hardwareMotorType; + +void detectBrushedESC(void); +#endif diff --git a/src/main/drivers/serial_uart_hal.c b/src/main/drivers/serial_uart_hal.c index 0a00d2aac..ecbd54a5e 100644 --- a/src/main/drivers/serial_uart_hal.c +++ b/src/main/drivers/serial_uart_hal.c @@ -179,8 +179,11 @@ serialPort_t *uartOpen(USART_TypeDef *USARTx, serialReceiveCallbackPtr callback, { uartPort_t *s = NULL; - if (USARTx == USART1) { + if (false) { +#ifdef USE_UART1 + } else if (USARTx == USART1) { s = serialUART1(baudRate, mode, options); +#endif #ifdef USE_UART2 } else if (USARTx == USART2) { s = serialUART2(baudRate, mode, options); diff --git a/src/main/drivers/timer_hal.c b/src/main/drivers/timer_hal.c index 263b49f00..127e2a1d5 100644 --- a/src/main/drivers/timer_hal.c +++ b/src/main/drivers/timer_hal.c @@ -872,7 +872,7 @@ const timerHardware_t *timerGetByTag(ioTag_t tag, timerUsageFlag_e flag) { for (int i = 0; i < USABLE_TIMER_CHANNEL_COUNT; i++) { if (timerHardware[i].tag == tag) { - if (timerHardware[i].output & flag) { + if (timerHardware[i].usageFlags & flag || flag == 0) { return &timerHardware[i]; } } diff --git a/src/main/fc/config.c b/src/main/fc/config.c index fa1cc67cd..4359fcd2b 100755 --- a/src/main/fc/config.c +++ b/src/main/fc/config.c @@ -274,9 +274,19 @@ void resetMotorConfig(motorConfig_t *motorConfig) motorConfig->motorPwmProtocol = PWM_TYPE_BRUSHED; motorConfig->useUnsyncedPwm = true; #else - motorConfig->minthrottle = 1070; - motorConfig->motorPwmRate = BRUSHLESS_MOTORS_PWM_RATE; - motorConfig->motorPwmProtocol = PWM_TYPE_ONESHOT125; +#ifdef BRUSHED_ESC_AUTODETECT + if (hardwareMotorType == MOTOR_BRUSHED) { + motorConfig->minthrottle = 1000; + motorConfig->motorPwmRate = BRUSHED_MOTORS_PWM_RATE; + motorConfig->motorPwmProtocol = PWM_TYPE_BRUSHED; + motorConfig->useUnsyncedPwm = true; + } else +#endif + { + motorConfig->minthrottle = 1070; + motorConfig->motorPwmRate = BRUSHLESS_MOTORS_PWM_RATE; + motorConfig->motorPwmProtocol = PWM_TYPE_ONESHOT125; + } #endif motorConfig->maxthrottle = 2000; motorConfig->mincommand = 1000; @@ -490,6 +500,46 @@ void resetMax7456Config(vcdProfile_t *pVcdProfile) } #endif +void resetStatusLedConfig(statusLedConfig_t *statusLedConfig) +{ + for (int i = 0; i < LED_NUMBER; i++) { + statusLedConfig->ledTags[i] = IO_TAG_NONE; + } + +#ifdef LED0 + statusLedConfig->ledTags[0] = IO_TAG(LED0); +#endif +#ifdef LED1 + statusLedConfig->ledTags[1] = IO_TAG(LED1); +#endif +#ifdef LED2 + statusLedConfig->ledTags[2] = IO_TAG(LED2); +#endif + + statusLedConfig->polarity = 0 +#ifdef LED0_INVERTED + | BIT(0) +#endif +#ifdef LED1_INVERTED + | BIT(1) +#endif +#ifdef LED2_INVERTED + | BIT(2) +#endif + ; +} + +#ifdef USE_FLASHFS +void resetFlashConfig(flashConfig_t *flashConfig) +{ +#ifdef M25P16_CS_PIN + flashConfig->csTag = IO_TAG(M25P16_CS_PIN); +#else + flashConfig->csTag = IO_TAG_NONE; +#endif +} +#endif + uint8_t getCurrentProfile(void) { return masterConfig.current_profile_index; @@ -789,6 +839,12 @@ void createDefaultConfig(master_t *config) } #endif +#ifdef USE_FLASHFS + resetFlashConfig(&config->flashConfig); +#endif + + resetStatusLedConfig(&config->statusLedConfig); + #if defined(TARGET_CONFIG) targetConfiguration(config); #endif diff --git a/src/main/fc/config.h b/src/main/fc/config.h index c5fe4ecf6..0fe4f9e61 100644 --- a/src/main/fc/config.h +++ b/src/main/fc/config.h @@ -55,7 +55,7 @@ typedef enum { FEATURE_VTX = 1 << 24, FEATURE_RX_SPI = 1 << 25, FEATURE_SOFTSPI = 1 << 26, - FEATURE_ESC_TELEMETRY = 1 << 27 + FEATURE_ESC_SENSOR = 1 << 27, } features_e; void beeperOffSet(uint32_t mask); diff --git a/src/main/fc/fc_msp.c b/src/main/fc/fc_msp.c index 62d75cddb..bbc065145 100755 --- a/src/main/fc/fc_msp.c +++ b/src/main/fc/fc_msp.c @@ -882,6 +882,7 @@ static bool mspFcProcessOutCommand(uint8_t cmdMSP, sbuf_t *dst, mspPostProcessFn sbufWriteU8(dst, batteryConfig()->vbatmincellvoltage); sbufWriteU8(dst, batteryConfig()->vbatmaxcellvoltage); sbufWriteU8(dst, batteryConfig()->vbatwarningcellvoltage); + sbufWriteU8(dst, batteryConfig()->batteryMeterType); break; case MSP_CURRENT_METER_CONFIG: @@ -1662,6 +1663,9 @@ static mspResult_e mspFcProcessInCommand(uint8_t cmdMSP, sbuf_t *src) batteryConfig()->vbatmincellvoltage = sbufReadU8(src); // vbatlevel_warn1 in MWC2.3 GUI batteryConfig()->vbatmaxcellvoltage = sbufReadU8(src); // vbatlevel_warn2 in MWC2.3 GUI batteryConfig()->vbatwarningcellvoltage = sbufReadU8(src); // vbatlevel when buzzer starts to alert + if (dataSize > 4) { + batteryConfig()->batteryMeterType = sbufReadU8(src); + } break; case MSP_SET_CURRENT_METER_CONFIG: diff --git a/src/main/fc/fc_tasks.c b/src/main/fc/fc_tasks.c index 0ecdd239d..f76d134b2 100644 --- a/src/main/fc/fc_tasks.c +++ b/src/main/fc/fc_tasks.c @@ -22,7 +22,6 @@ #include #include "cms/cms.h" -#include "cms/cms_types.h" #include "common/axis.h" #include "common/color.h" @@ -65,11 +64,11 @@ #include "sensors/compass.h" #include "sensors/gyro.h" #include "sensors/sonar.h" +#include "sensors/esc_sensor.h" #include "scheduler/scheduler.h" #include "telemetry/telemetry.h" -#include "telemetry/esc_telemetry.h" #include "config/feature.h" #include "config/config_profile.h" @@ -111,9 +110,9 @@ static void taskHandleSerial(timeUs_t currentTimeUs) static void taskUpdateBattery(timeUs_t currentTimeUs) { -#ifdef USE_ADC +#if defined(USE_ADC) || defined(USE_ESC_SENSOR) static uint32_t vbatLastServiced = 0; - if (feature(FEATURE_VBAT) || feature(FEATURE_ESC_TELEMETRY)) { + if (feature(FEATURE_VBAT) || feature(FEATURE_ESC_SENSOR)) { if (cmp32(currentTimeUs, vbatLastServiced) >= VBATINTERVAL) { vbatLastServiced = currentTimeUs; updateBattery(); @@ -122,7 +121,7 @@ static void taskUpdateBattery(timeUs_t currentTimeUs) #endif static uint32_t ibatLastServiced = 0; - if (feature(FEATURE_CURRENT_METER) || feature(FEATURE_ESC_TELEMETRY)) { + if (feature(FEATURE_CURRENT_METER) || feature(FEATURE_ESC_SENSOR)) { const int32_t ibatTimeSinceLastServiced = cmp32(currentTimeUs, ibatLastServiced); if (ibatTimeSinceLastServiced >= IBATINTERVAL) { @@ -205,15 +204,6 @@ static void taskTelemetry(timeUs_t currentTimeUs) } #endif -#ifdef USE_ESC_TELEMETRY -static void taskEscTelemetry(timeUs_t currentTimeUs) -{ - if (feature(FEATURE_ESC_TELEMETRY)) { - escTelemetryProcess(currentTimeUs); - } - } -#endif - #ifdef VTX_CONTROL // Everything that listens to VTX devices void taskVtxControl(uint32_t currentTime) @@ -292,8 +282,8 @@ void fcTasksInit(void) #ifdef USE_BST setTaskEnabled(TASK_BST_MASTER_PROCESS, true); #endif -#ifdef USE_ESC_TELEMETRY - setTaskEnabled(TASK_ESC_TELEMETRY, feature(FEATURE_ESC_TELEMETRY)); +#ifdef USE_ESC_SENSOR + setTaskEnabled(TASK_ESC_SENSOR, feature(FEATURE_ESC_SENSOR)); #endif #ifdef CMS #ifdef USE_MSP_DISPLAYPORT @@ -470,11 +460,11 @@ cfTask_t cfTasks[TASK_COUNT] = { }, #endif -#ifdef USE_ESC_TELEMETRY - [TASK_ESC_TELEMETRY] = { - .taskName = "ESC_TELEMETRY", - .taskFunc = taskEscTelemetry, - .desiredPeriod = 1000000 / 100, // 100 Hz +#ifdef USE_ESC_SENSOR + [TASK_ESC_SENSOR] = { + .taskName = "ESC_SENSOR", + .taskFunc = escSensorProcess, + .desiredPeriod = TASK_PERIOD_HZ(100), // 100 Hz every 10ms .staticPriority = TASK_PRIORITY_LOW, }, #endif diff --git a/src/main/io/serial.h b/src/main/io/serial.h index 6c702f488..c8c9a6667 100644 --- a/src/main/io/serial.h +++ b/src/main/io/serial.h @@ -37,7 +37,7 @@ typedef enum { FUNCTION_BLACKBOX = (1 << 7), // 128 FUNCTION_TELEMETRY_MAVLINK = (1 << 9), // 512 - FUNCTION_TELEMETRY_ESC = (1 << 10), // 1024 + FUNCTION_ESC_SENSOR = (1 << 10),// 1024 FUNCTION_VTX_CONTROL = (1 << 11),// 2048 } serialPortFunction_e; diff --git a/src/main/io/serial_cli.c b/src/main/io/serial_cli.c index d0636ea62..0845abb09 100755 --- a/src/main/io/serial_cli.c +++ b/src/main/io/serial_cli.c @@ -234,7 +234,7 @@ static const char * const featureNames[] = { "SONAR", "TELEMETRY", "CURRENT_METER", "3D", "RX_PARALLEL_PWM", "RX_MSP", "RSSI_ADC", "LED_STRIP", "DISPLAY", "OSD", "BLACKBOX", "CHANNEL_FORWARDING", "TRANSPONDER", "AIRMODE", - "SDCARD", "VTX", "RX_SPI", "SOFTSPI", "ESC_TELEMETRY", NULL + "SDCARD", "VTX", "RX_SPI", "SOFTSPI", "ESC_SENSOR", NULL }; // sync this with rxFailsafeChannelMode_e @@ -415,7 +415,11 @@ static const char * const lookupTableGPSSBASMode[] = { #endif static const char * const lookupTableCurrentSensor[] = { - "NONE", "ADC", "VIRTUAL" + "NONE", "ADC", "VIRTUAL", "ESC" +}; + +static const char * const lookupTableBatterySensor[] = { + "ADC", "ESC" }; #ifdef USE_SERVOS @@ -519,7 +523,7 @@ static const char * const lookupTableDebug[DEBUG_COUNT] = { "VELOCITY", "DFILTER", "ANGLERATE", - "ESC_TELEMETRY", + "ESC_SENSOR", "SCHEDULER", }; @@ -571,6 +575,7 @@ typedef enum { TABLE_BLACKBOX_DEVICE, #endif TABLE_CURRENT_SENSOR, + TABLE_BATTERY_SENSOR, #ifdef USE_SERVOS TABLE_GIMBAL_MODE, #endif @@ -611,6 +616,7 @@ static const lookupTableEntry_t lookupTables[] = { { lookupTableBlackboxDevice, sizeof(lookupTableBlackboxDevice) / sizeof(char *) }, #endif { lookupTableCurrentSensor, sizeof(lookupTableCurrentSensor) / sizeof(char *) }, + { lookupTableBatterySensor, sizeof(lookupTableBatterySensor) / sizeof(char *) }, #ifdef USE_SERVOS { lookupTableGimbalMode, sizeof(lookupTableGimbalMode) / sizeof(char *) }, #endif @@ -799,6 +805,7 @@ const clivalue_t valueTable[] = { { "current_meter_offset", VAR_INT16 | MASTER_VALUE, &batteryConfig()->currentMeterOffset, .config.minmax = { -16000, 16000 } }, { "multiwii_current_meter_output", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &batteryConfig()->multiwiiCurrentMeterOutput, .config.lookup = { TABLE_OFF_ON } }, { "current_meter_type", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &batteryConfig()->currentMeterType, .config.lookup = { TABLE_CURRENT_SENSOR } }, + { "battery_meter_type", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &batteryConfig()->batteryMeterType, .config.lookup = { TABLE_BATTERY_SENSOR } }, { "battery_notpresent_level", VAR_UINT8 | MASTER_VALUE, &batteryConfig()->batterynotpresentlevel, .config.minmax = { 0, 200 } }, { "use_vbat_alerts", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &batteryConfig()->useVBatAlerts, .config.lookup = { TABLE_OFF_ON } }, { "use_consumption_alerts", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &batteryConfig()->useConsumptionAlerts, .config.lookup = { TABLE_OFF_ON } }, diff --git a/src/main/main.c b/src/main/main.c index 70f32d258..591acc3b7 100644 --- a/src/main/main.c +++ b/src/main/main.c @@ -36,7 +36,6 @@ #include "drivers/sensor.h" #include "drivers/system.h" #include "drivers/dma.h" -#include "drivers/gpio.h" #include "drivers/io.h" #include "drivers/light_led.h" #include "drivers/sound_beeper.h" @@ -106,7 +105,7 @@ #include "sensors/initialisation.h" #include "telemetry/telemetry.h" -#include "telemetry/esc_telemetry.h" +#include "sensors/esc_sensor.h" #include "flight/pid.h" #include "flight/imu.h" @@ -126,6 +125,10 @@ #include "build/build_config.h" #include "build/debug.h" +#ifdef TARGET_BUS_INIT +void targetBusInit(void); +#endif + extern uint8_t motorControlEnable; #ifdef SOFTSERIAL_LOOPBACK @@ -160,6 +163,10 @@ void init(void) detectHardwareRevision(); #endif +#ifdef BRUSHED_ESC_AUTODETECT + detectBrushedESC(); +#endif + initEEPROM(); ensureEEPROMContainsValidData(); @@ -174,11 +181,7 @@ void init(void) // Latch active features to be used for feature() in the remainder of init(). latchActiveFeatures(); -#ifdef ALIENFLIGHTF3 - ledInit(hardwareRevision == AFF3_REV_1 ? false : true); -#else - ledInit(false); -#endif + ledInit(&masterConfig.statusLedConfig); LED2_ON; #ifdef USE_EXTI @@ -186,28 +189,22 @@ void init(void) #endif #if defined(BUTTONS) - gpio_config_t buttonAGpioConfig = { - BUTTON_A_PIN, - Mode_IPU, - Speed_2MHz - }; - gpioInit(BUTTON_A_PORT, &buttonAGpioConfig); + IO_t buttonAPin = IOGetByTag(IO_TAG(BUTTON_A_PIN)); + IOInit(buttonAPin, OWNER_SYSTEM, 0); + IOConfigGPIO(buttonAPin, IOCFG_IPU); - gpio_config_t buttonBGpioConfig = { - BUTTON_B_PIN, - Mode_IPU, - Speed_2MHz - }; - gpioInit(BUTTON_B_PORT, &buttonBGpioConfig); + IO_t buttonBPin = IOGetByTag(IO_TAG(BUTTON_B_PIN)); + IOInit(buttonBPin, OWNER_SYSTEM, 0); + IOConfigGPIO(buttonBPin, IOCFG_IPU); // Check status of bind plug and exit if not active - delayMicroseconds(10); // allow GPIO configuration to settle + delayMicroseconds(10); // allow configuration to settle if (!isMPUSoftReset()) { uint8_t secondsRemaining = 5; bool bothButtonsHeld; do { - bothButtonsHeld = !digitalIn(BUTTON_A_PORT, BUTTON_A_PIN) && !digitalIn(BUTTON_B_PORT, BUTTON_B_PIN); + bothButtonsHeld = !IORead(buttonAPin) && !IORead(buttonBPin); if (bothButtonsHeld) { if (--secondsRemaining == 0) { resetEEPROM(); @@ -293,7 +290,6 @@ void init(void) pwmRxSetInputFilteringMode(masterConfig.inputFilteringMode); #endif - systemState |= SYSTEM_STATE_MOTORS_READY; #ifdef BEEPER @@ -308,74 +304,48 @@ void init(void) bstInit(BST_DEVICE); #endif -#ifdef USE_SPI -#ifdef USE_SPI_DEVICE_1 - spiInit(SPIDEV_1); -#endif -#ifdef USE_SPI_DEVICE_2 - spiInit(SPIDEV_2); -#endif -#ifdef USE_SPI_DEVICE_3 -#ifdef ALIENFLIGHTF3 - if (hardwareRevision == AFF3_REV_2) { - spiInit(SPIDEV_3); - } +#ifdef TARGET_BUS_INIT + targetBusInit(); #else - spiInit(SPIDEV_3); -#endif -#endif -#ifdef USE_SPI_DEVICE_4 - spiInit(SPIDEV_4); -#endif -#endif + #ifdef USE_SPI + #ifdef USE_SPI_DEVICE_1 + spiInit(SPIDEV_1); + #endif + #ifdef USE_SPI_DEVICE_2 + spiInit(SPIDEV_2); + #endif + #ifdef USE_SPI_DEVICE_3 + spiInit(SPIDEV_3); + #endif + #ifdef USE_SPI_DEVICE_4 + spiInit(SPIDEV_4); + #endif + #endif -#ifdef VTX - vtxInit(); + #ifdef USE_I2C + i2cInit(I2C_DEVICE); + #endif #endif #ifdef USE_HARDWARE_REVISION_DETECTION updateHardwareRevision(); #endif -#if defined(NAZE) - if (hardwareRevision == NAZE32_SP) { - serialRemovePort(SERIAL_PORT_SOFTSERIAL2); - } else { - serialRemovePort(SERIAL_PORT_USART3); - } +#ifdef VTX + vtxInit(); #endif -#if defined(SPRACINGF3) && defined(SONAR) && defined(USE_SOFTSERIAL2) +#if defined(SONAR_SOFTSERIAL2_EXCLUSIVE) && defined(SONAR) && defined(USE_SOFTSERIAL2) if (feature(FEATURE_SONAR) && feature(FEATURE_SOFTSERIAL)) { serialRemovePort(SERIAL_PORT_SOFTSERIAL2); } #endif -#if defined(SPRACINGF3MINI) || defined(OMNIBUS) || defined(X_RACERSPI) -#if defined(SONAR) && defined(USE_SOFTSERIAL1) +#if defined(SONAR_SOFTSERIAL1_EXCLUSIVE) && defined(SONAR) && defined(USE_SOFTSERIAL1) if (feature(FEATURE_SONAR) && feature(FEATURE_SOFTSERIAL)) { serialRemovePort(SERIAL_PORT_SOFTSERIAL1); } #endif -#endif - -#ifdef USE_I2C -#if defined(NAZE) - if (hardwareRevision != NAZE32_SP) { - i2cInit(I2C_DEVICE); - } else { - if (!doesConfigurationUsePort(SERIAL_PORT_USART3)) { - i2cInit(I2C_DEVICE); - } - } -#elif defined(CC3D) - if (!doesConfigurationUsePort(SERIAL_PORT_USART3)) { - i2cInit(I2C_DEVICE); - } -#else - i2cInit(I2C_DEVICE); -#endif -#endif #ifdef USE_ADC /* these can be removed from features! */ @@ -385,7 +355,6 @@ void init(void) adcInit(&masterConfig.adcConfig); #endif - initBoardAlignment(&masterConfig.boardAlignment); #ifdef CMS @@ -495,9 +464,9 @@ void init(void) } #endif -#ifdef USE_ESC_TELEMETRY - if (feature(FEATURE_ESC_TELEMETRY)) { - escTelemetryInit(); +#ifdef USE_ESC_SENSOR + if (feature(FEATURE_ESC_SENSOR)) { + escSensorInit(); } #endif @@ -515,12 +484,8 @@ void init(void) #endif #ifdef USE_FLASHFS -#ifdef NAZE - if (hardwareRevision == NAZE32_REV5) { - m25p16_init(IO_TAG_NONE); - } -#elif defined(USE_FLASH_M25P16) - m25p16_init(IO_TAG_NONE); +#if defined(USE_FLASH_M25P16) + m25p16_init(&masterConfig.flashConfig); #endif flashfsInit(); diff --git a/src/main/msp/msp_protocol.h b/src/main/msp/msp_protocol.h index 84f0a60a1..925d38c14 100644 --- a/src/main/msp/msp_protocol.h +++ b/src/main/msp/msp_protocol.h @@ -59,7 +59,7 @@ #define MSP_PROTOCOL_VERSION 0 #define API_VERSION_MAJOR 1 // increment when major changes are made -#define API_VERSION_MINOR 22 // increment when any change is made, reset to zero when major changes are released after changing API_VERSION_MAJOR +#define API_VERSION_MINOR 23 // increment when any change is made, reset to zero when major changes are released after changing API_VERSION_MAJOR #define API_VERSION_LENGTH 2 diff --git a/src/main/platform.h b/src/main/platform.h index 221222263..0f6439cbc 100644 --- a/src/main/platform.h +++ b/src/main/platform.h @@ -17,7 +17,7 @@ #pragma once -#if defined(STM32F745xx) +#if defined(STM32F745xx) || defined(STM32F746xx) #include "stm32f7xx.h" #include "stm32f7xx_hal.h" diff --git a/src/main/scheduler/scheduler.h b/src/main/scheduler/scheduler.h index 306afb65e..06014f01b 100644 --- a/src/main/scheduler/scheduler.h +++ b/src/main/scheduler/scheduler.h @@ -94,8 +94,8 @@ typedef enum { #ifdef USE_BST TASK_BST_MASTER_PROCESS, #endif -#ifdef USE_ESC_TELEMETRY - TASK_ESC_TELEMETRY, +#ifdef USE_ESC_SENSOR + TASK_ESC_SENSOR, #endif #ifdef CMS TASK_CMS, diff --git a/src/main/sensors/battery.c b/src/main/sensors/battery.c index 3a8a59a8a..f090ae756 100644 --- a/src/main/sensors/battery.c +++ b/src/main/sensors/battery.c @@ -34,8 +34,7 @@ #include "config/feature.h" #include "sensors/battery.h" - -#include "telemetry/esc_telemetry.h" +#include "sensors/esc_sensor.h" #include "fc/rc_controls.h" #include "io/beeper.h" @@ -84,9 +83,9 @@ static void updateBatteryVoltage(void) vBatFilterIsInitialised = true; } - #ifdef USE_ESC_TELEMETRY - if (batteryConfig->batteryMeterType == BATTERY_SENSOR_ESC && isEscTelemetryActive()) { - vbatLatest = getEscTelemetryVbat(); + #ifdef USE_ESC_SENSOR + if (feature(FEATURE_ESC_SENSOR) && batteryConfig->batteryMeterType == BATTERY_SENSOR_ESC) { + vbatLatest = getEscSensorVbat(); if (debugMode == DEBUG_BATTERY) { debug[0] = -1; } @@ -292,11 +291,11 @@ void updateCurrentMeter(int32_t lastUpdateAt, rxConfig_t *rxConfig, uint16_t dea break; case CURRENT_SENSOR_ESC: - #ifdef USE_ESC_TELEMETRY - if (isEscTelemetryActive()) { - amperageLatest = getEscTelemetryCurrent(); + #ifdef USE_ESC_SENSOR + if (feature(FEATURE_ESC_SENSOR)) { + amperageLatest = getEscSensorCurrent(); amperage = amperageLatest; - mAhDrawn = getEscTelemetryConsumption(); + mAhDrawn = getEscSensorConsumption(); updateConsumptionWarning(); } diff --git a/src/main/sensors/battery.h b/src/main/sensors/battery.h index 01309a8c8..cb4de3911 100644 --- a/src/main/sensors/battery.h +++ b/src/main/sensors/battery.h @@ -31,12 +31,12 @@ typedef enum { CURRENT_SENSOR_NONE = 0, CURRENT_SENSOR_ADC, CURRENT_SENSOR_VIRTUAL, - CURRENT_SENSOR_ESC + CURRENT_SENSOR_ESC, + CURRENT_SENSOR_MAX = CURRENT_SENSOR_ESC } currentSensor_e; typedef enum { - BATTERY_SENSOR_NONE = 0, - BATTERY_SENSOR_ADC, + BATTERY_SENSOR_ADC = 0, BATTERY_SENSOR_ESC } batterySensor_e; diff --git a/src/main/sensors/esc_sensor.c b/src/main/sensors/esc_sensor.c new file mode 100644 index 000000000..af2c0aa11 --- /dev/null +++ b/src/main/sensors/esc_sensor.c @@ -0,0 +1,313 @@ +#include +#include +#include + +#include + +#include "fc/config.h" +#include "config/feature.h" +#include "config/config_master.h" + +#include "common/utils.h" + +#include "drivers/system.h" +#include "drivers/serial.h" +#include "drivers/serial_uart.h" +#include "drivers/pwm_output.h" + +#include "io/serial.h" + +#include "flight/mixer.h" + +#include "sensors/battery.h" + +#include "esc_sensor.h" + +#include "build/debug.h" + +/* +KISS ESC TELEMETRY PROTOCOL +--------------------------- + +One transmission will have 10 times 8-bit bytes sent with 115200 baud and 3.6V. + +Byte 0: Temperature +Byte 1: Voltage high byte +Byte 2: Voltage low byte +Byte 3: Current high byte +Byte 4: Current low byte +Byte 5: Consumption high byte +Byte 6: Consumption low byte +Byte 7: Rpm high byte +Byte 8: Rpm low byte +Byte 9: 8-bit CRC + +*/ + +/* +DEBUG INFORMATION +----------------- + +set debug_mode = DEBUG_ESC_TELEMETRY in cli + +0: current motor index requested +1: number of timeouts +2: voltage +3: current +*/ + +#ifdef USE_DSHOT + +typedef struct { + bool skipped; + int16_t temperature; + int16_t voltage; + int16_t current; + int16_t consumption; + int16_t rpm; +} esc_telemetry_t; + +typedef enum { + ESC_SENSOR_FRAME_PENDING = 1 << 0, // 1 + ESC_SENSOR_FRAME_COMPLETE = 1 << 1 // 2 +} escTlmFrameState_t; + +typedef enum { + ESC_SENSOR_TRIGGER_WAIT = 0, + ESC_SENSOR_TRIGGER_READY = 1 << 0, // 1 + ESC_SENSOR_TRIGGER_PENDING = 1 << 1, // 2 +} escSensorTriggerState_t; + +#define ESC_SENSOR_BAUDRATE 115200 +#define ESC_SENSOR_BUFFSIZE 10 +#define ESC_BOOTTIME 5000 // 5 seconds +#define ESC_REQUEST_TIMEOUT 100 // 100 ms (data transfer takes only 900us) + +static bool tlmFrameDone = false; +static uint8_t tlm[ESC_SENSOR_BUFFSIZE] = { 0, }; +static uint8_t tlmFramePosition = 0; +static serialPort_t *escSensorPort = NULL; +static esc_telemetry_t escSensorData[MAX_SUPPORTED_MOTORS]; +static uint32_t escTriggerTimestamp = -1; +static uint32_t escLastResponseTimestamp; +static uint8_t timeoutRetryCount = 0; +static uint8_t totalRetryCount = 0; + +static uint8_t escSensorMotor = 0; // motor index +static bool escSensorEnabled = false; +static escSensorTriggerState_t escSensorTriggerState = ESC_SENSOR_TRIGGER_WAIT; + +static int16_t escVbat = 0; +static int16_t escCurrent = 0; +static int16_t escConsumption = 0; + +static void escSensorDataReceive(uint16_t c); +static uint8_t update_crc8(uint8_t crc, uint8_t crc_seed); +static uint8_t get_crc8(uint8_t *Buf, uint8_t BufLen); +static void selectNextMotor(void); + +bool isEscSensorActive(void) +{ + return escSensorEnabled; +} + +int16_t getEscSensorVbat(void) +{ + return escVbat / 10; +} + +int16_t getEscSensorCurrent(void) +{ + return escCurrent; +} + +int16_t getEscSensorConsumption(void) +{ + return escConsumption; +} + +bool escSensorInit(void) +{ + serialPortConfig_t *portConfig = findSerialPortConfig(FUNCTION_ESC_SENSOR); + if (!portConfig) { + return false; + } + + portOptions_t options = (SERIAL_NOT_INVERTED); + + // Initialize serial port + escSensorPort = openSerialPort(portConfig->identifier, FUNCTION_ESC_SENSOR, escSensorDataReceive, ESC_SENSOR_BAUDRATE, MODE_RX, options); + + if (escSensorPort) { + escSensorEnabled = true; + } + + return escSensorPort != NULL; +} + +void freeEscSensorPort(void) +{ + closeSerialPort(escSensorPort); + escSensorPort = NULL; + escSensorEnabled = false; +} + +// Receive ISR callback +static void escSensorDataReceive(uint16_t c) +{ + // KISS ESC sends some data during startup, ignore this for now (maybe future use) + // startup data could be firmware version and serialnumber + + if (escSensorTriggerState == ESC_SENSOR_TRIGGER_WAIT) return; + + tlm[tlmFramePosition] = (uint8_t)c; + + if (tlmFramePosition == ESC_SENSOR_BUFFSIZE - 1) { + tlmFrameDone = true; + tlmFramePosition = 0; + } else { + tlmFramePosition++; + } +} + +uint8_t escSensorFrameStatus(void) +{ + uint8_t frameStatus = ESC_SENSOR_FRAME_PENDING; + uint16_t chksum, tlmsum; + + if (!tlmFrameDone) { + return frameStatus; + } + + tlmFrameDone = false; + + // Get CRC8 checksum + chksum = get_crc8(tlm, ESC_SENSOR_BUFFSIZE - 1); + tlmsum = tlm[ESC_SENSOR_BUFFSIZE - 1]; // last byte contains CRC value + + if (chksum == tlmsum) { + escSensorData[escSensorMotor].skipped = false; + escSensorData[escSensorMotor].temperature = tlm[0]; + escSensorData[escSensorMotor].voltage = tlm[1] << 8 | tlm[2]; + escSensorData[escSensorMotor].current = tlm[3] << 8 | tlm[4]; + escSensorData[escSensorMotor].consumption = tlm[5] << 8 | tlm[6]; + escSensorData[escSensorMotor].rpm = tlm[7] << 8 | tlm[8]; + + frameStatus = ESC_SENSOR_FRAME_COMPLETE; + } + + return frameStatus; +} + +void escSensorProcess(timeUs_t currentTimeUs) +{ + const timeMs_t currentTimeMs = currentTimeUs / 1000; + + if (!escSensorEnabled) { + return; + } + + // Wait period of time before requesting telemetry (let the system boot first) + if (currentTimeMs < ESC_BOOTTIME) { + return; + } + else if (escSensorTriggerState == ESC_SENSOR_TRIGGER_WAIT) { + // Ready for starting requesting telemetry + escSensorTriggerState = ESC_SENSOR_TRIGGER_READY; + escSensorMotor = 0; + escTriggerTimestamp = currentTimeMs; + escLastResponseTimestamp = escTriggerTimestamp; + } + else if (escSensorTriggerState == ESC_SENSOR_TRIGGER_READY) { + DEBUG_SET(DEBUG_ESC_SENSOR, 0, escSensorMotor+1); + + motorDmaOutput_t * const motor = getMotorDmaOutput(escSensorMotor); + motor->requestTelemetry = true; + escSensorTriggerState = ESC_SENSOR_TRIGGER_PENDING; + } + else if (escSensorTriggerState == ESC_SENSOR_TRIGGER_PENDING) { + + if (escTriggerTimestamp + ESC_REQUEST_TIMEOUT < currentTimeMs) { + // ESC did not repond in time, retry + timeoutRetryCount++; + escTriggerTimestamp = currentTimeMs; + escSensorTriggerState = ESC_SENSOR_TRIGGER_READY; + + if (timeoutRetryCount == 4) { + // Not responding after 3 times, skip motor + escSensorData[escSensorMotor].skipped = true; + selectNextMotor(); + } + + DEBUG_SET(DEBUG_ESC_SENSOR, 1, ++totalRetryCount); + } + + // Get received frame status + uint8_t state = escSensorFrameStatus(); + + if (state == ESC_SENSOR_FRAME_COMPLETE) { + // Wait until all ESCs are processed + if (escSensorMotor == getMotorCount()-1) { + escCurrent = 0; + escConsumption = 0; + escVbat = 0; + + for (int i = 0; i < getMotorCount(); i++) { + if (!escSensorData[i].skipped) { + escVbat = i > 0 ? ((escVbat + escSensorData[i].voltage) / 2) : escSensorData[i].voltage; + escCurrent = escCurrent + escSensorData[i].current; + escConsumption = escConsumption + escSensorData[i].consumption; + } + } + } + + DEBUG_SET(DEBUG_ESC_SENSOR, 2, escVbat); + DEBUG_SET(DEBUG_ESC_SENSOR, 3, escCurrent); + + selectNextMotor(); + escSensorTriggerState = ESC_SENSOR_TRIGGER_READY; + escLastResponseTimestamp = currentTimeMs; + } + } + + if (escLastResponseTimestamp + 10000 < currentTimeMs) { + // ESCs did not respond for 10 seconds + // Disable ESC telemetry and reset voltage and current to let the use know something is wrong + freeEscSensorPort(); + escVbat = 0; + escCurrent = 0; + } +} + +static void selectNextMotor(void) +{ + escSensorMotor++; + if (escSensorMotor == getMotorCount()) { + escSensorMotor = 0; + } + timeoutRetryCount = 0; + escTriggerTimestamp = millis(); +} + +//-- CRC + +static uint8_t update_crc8(uint8_t crc, uint8_t crc_seed) +{ + uint8_t crc_u = crc; + crc_u ^= crc_seed; + + for (int i=0; i<8; i++) { + crc_u = ( crc_u & 0x80 ) ? 0x7 ^ ( crc_u << 1 ) : ( crc_u << 1 ); + } + + return (crc_u); +} + +static uint8_t get_crc8(uint8_t *Buf, uint8_t BufLen) +{ + uint8_t crc = 0; + for(int i=0; irxConfig.spektrum_sat_bind_autoreset = 1; if (hardwareMotorType == MOTOR_BRUSHED) { - config->motorConfig.minthrottle = 1000; - config->motorConfig.motorPwmRate = 32000; - config->motorConfig.motorPwmProtocol = PWM_TYPE_BRUSHED; - config->motorConfig.useUnsyncedPwm = true; + config->motorConfig.motorPwmRate = BRUSHED_MOTORS_PWM_RATE; } config->profile[0].pidProfile.P8[ROLL] = 90; diff --git a/src/main/target/ALIENFLIGHTF1/target.h b/src/main/target/ALIENFLIGHTF1/target.h index 5bafc911c..02a730444 100644 --- a/src/main/target/ALIENFLIGHTF1/target.h +++ b/src/main/target/ALIENFLIGHTF1/target.h @@ -20,8 +20,7 @@ #define TARGET_BOARD_IDENTIFIER "AFF1" // AlienFlight F1. #define TARGET_CONFIG -#define USE_HARDWARE_REVISION_DETECTION -#define MOTOR_PIN PA8 +#define BRUSHED_ESC_AUTODETECT #define LED0 PB3 #define LED1 PB4 diff --git a/src/main/target/ALIENFLIGHTF3/AlienFlight.md b/src/main/target/ALIENFLIGHTF3/AlienFlight.md index 3510b52c1..4c33df568 100644 --- a/src/main/target/ALIENFLIGHTF3/AlienFlight.md +++ b/src/main/target/ALIENFLIGHTF3/AlienFlight.md @@ -2,9 +2,10 @@ AlienWii is now AlienFlight. This targets supports various variants of brushed and brushless flight controllers. The designs for them are released partially for public use at: +http://www.alienflight.com http://www.alienflightng.com -The legacy designs are available at: +AlienFlight Classic and F3 Eagle files are available at: https://github.com/MJ666/Flight-Controllers diff --git a/src/main/target/ALIENFLIGHTF3/config.c b/src/main/target/ALIENFLIGHTF3/config.c index 516b64a78..c14ed47be 100644 --- a/src/main/target/ALIENFLIGHTF3/config.c +++ b/src/main/target/ALIENFLIGHTF3/config.c @@ -42,19 +42,46 @@ #include "hardware_revision.h" +#define BRUSHED_MOTORS_PWM_RATE 32000 // 32kHz + // alternative defaults settings for AlienFlight targets void targetConfiguration(master_t *config) { + /* depending on revision ... depends on the LEDs to be utilised. */ + if (hardwareRevision == AFF3_REV_2) { + config->statusLedConfig.polarity = 0 +#ifdef LED0_A_INVERTED + | BIT(0) +#endif +#ifdef LED1_A_INVERTED + | BIT(1) +#endif +#ifdef LED2_A_INVERTED + | BIT(2) +#endif + ; + + for (int i = 0; i < LED_NUMBER; i++) { + config->statusLedConfig.ledTags[i] = IO_TAG_NONE; + } +#ifdef LED0_A + config->statusLedConfig.ledTags[0] = IO_TAG(LED0_A); +#endif +#ifdef LED1_A + config->statusLedConfig.ledTags[1] = IO_TAG(LED1_A); +#endif +#ifdef LED2_A + config->statusLedConfig.ledTags[2] = IO_TAG(LED2_A); +#endif + } + config->rxConfig.spektrum_sat_bind = 5; config->rxConfig.spektrum_sat_bind_autoreset = 1; config->compassConfig.mag_hardware = MAG_NONE; // disabled by default if (hardwareMotorType == MOTOR_BRUSHED) { - config->motorConfig.minthrottle = 1000; - config->motorConfig.motorPwmRate = 32000; - config->motorConfig.motorPwmProtocol = PWM_TYPE_BRUSHED; + config->motorConfig.motorPwmRate = BRUSHED_MOTORS_PWM_RATE; config->pid_process_denom = 2; - config->motorConfig.useUnsyncedPwm = true; } config->profile[0].pidProfile.P8[ROLL] = 90; diff --git a/src/main/target/ALIENFLIGHTF3/hardware_revision.c b/src/main/target/ALIENFLIGHTF3/hardware_revision.c index 0dd8ba2e4..e3942a0c1 100644 --- a/src/main/target/ALIENFLIGHTF3/hardware_revision.c +++ b/src/main/target/ALIENFLIGHTF3/hardware_revision.c @@ -29,10 +29,8 @@ #include "hardware_revision.h" uint8_t hardwareRevision = AFF3_UNKNOWN; -uint8_t hardwareMotorType = MOTOR_UNKNOWN; static IO_t HWDetectPin = IO_NONE; -static IO_t MotorDetectPin = IO_NONE; void detectHardwareRevision(void) { @@ -40,10 +38,6 @@ void detectHardwareRevision(void) IOInit(HWDetectPin, OWNER_SYSTEM, 0); IOConfigGPIO(HWDetectPin, IOCFG_IPU); - MotorDetectPin = IOGetByTag(IO_TAG(MOTOR_PIN)); - IOInit(MotorDetectPin, OWNER_SYSTEM, 0); - IOConfigGPIO(MotorDetectPin, IOCFG_IPU); - delayMicroseconds(10); // allow configuration to settle // Check hardware revision @@ -52,13 +46,6 @@ void detectHardwareRevision(void) } else { hardwareRevision = AFF3_REV_2; } - - // Check presence of brushed ESC's - if (IORead(MotorDetectPin)) { - hardwareMotorType = MOTOR_BRUSHLESS; - } else { - hardwareMotorType = MOTOR_BRUSHED; - } } void updateHardwareRevision(void) diff --git a/src/main/target/ALIENFLIGHTF3/hardware_revision.h b/src/main/target/ALIENFLIGHTF3/hardware_revision.h index 9b0618561..67cdbc931 100644 --- a/src/main/target/ALIENFLIGHTF3/hardware_revision.h +++ b/src/main/target/ALIENFLIGHTF3/hardware_revision.h @@ -22,14 +22,7 @@ typedef enum awf3HardwareRevision_t { AFF3_REV_2 // MPU6500 / MPU9250 (SPI) } awf3HardwareRevision_e; -typedef enum awf4HardwareMotorType_t { - MOTOR_UNKNOWN = 0, - MOTOR_BRUSHED, - MOTOR_BRUSHLESS -} awf4HardwareMotorType_e; - extern uint8_t hardwareRevision; -extern uint8_t hardwareMotorType; void updateHardwareRevision(void); void detectHardwareRevision(void); diff --git a/src/main/target/ALIENFLIGHTF3/initialisation.c b/src/main/target/ALIENFLIGHTF3/initialisation.c new file mode 100644 index 000000000..53fbb1f91 --- /dev/null +++ b/src/main/target/ALIENFLIGHTF3/initialisation.c @@ -0,0 +1,48 @@ +/* + * This file is part of Cleanflight. + * + * Cleanflight 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. + * + * Cleanflight 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 Cleanflight. If not, see . + */ + +#include +#include + +#include "platform.h" +#include "drivers/bus_i2c.h" +#include "drivers/bus_spi.h" +#include "hardware_revision.h" + +void targetBusInit(void) +{ + #ifdef USE_SPI + #ifdef USE_SPI_DEVICE_1 + spiInit(SPIDEV_1); + #endif + #ifdef USE_SPI_DEVICE_2 + spiInit(SPIDEV_2); + #endif + #ifdef USE_SPI_DEVICE_3 + if (hardwareRevision == AFF3_REV_2) { + spiInit(SPIDEV_3); + } + #endif + #ifdef USE_SPI_DEVICE_4 + spiInit(SPIDEV_4); + #endif + #endif + + #ifdef USE_I2C + i2cInit(I2C_DEVICE); + #endif +} \ No newline at end of file diff --git a/src/main/target/ALIENFLIGHTF3/target.h b/src/main/target/ALIENFLIGHTF3/target.h index 63a3a9bb0..0f091017d 100644 --- a/src/main/target/ALIENFLIGHTF3/target.h +++ b/src/main/target/ALIENFLIGHTF3/target.h @@ -19,12 +19,13 @@ #define TARGET_BOARD_IDENTIFIER "AFF3" // AlienFlight F3. #define TARGET_CONFIG +#define TARGET_BUS_INIT #define CONFIG_FASTLOOP_PREFERRED_ACC ACC_DEFAULT #define USE_HARDWARE_REVISION_DETECTION #define HW_PIN PB2 -#define MOTOR_PIN PB15 +#define BRUSHED_ESC_AUTODETECT // LED's V1 #define LED0 PB4 diff --git a/src/main/target/ALIENFLIGHTF4/AlienFlight.md b/src/main/target/ALIENFLIGHTF4/AlienFlight.md index 3510b52c1..4c33df568 100644 --- a/src/main/target/ALIENFLIGHTF4/AlienFlight.md +++ b/src/main/target/ALIENFLIGHTF4/AlienFlight.md @@ -2,9 +2,10 @@ AlienWii is now AlienFlight. This targets supports various variants of brushed and brushless flight controllers. The designs for them are released partially for public use at: +http://www.alienflight.com http://www.alienflightng.com -The legacy designs are available at: +AlienFlight Classic and F3 Eagle files are available at: https://github.com/MJ666/Flight-Controllers diff --git a/src/main/target/ALIENFLIGHTF4/config.c b/src/main/target/ALIENFLIGHTF4/config.c index 363a9704d..7a9b8bc54 100644 --- a/src/main/target/ALIENFLIGHTF4/config.c +++ b/src/main/target/ALIENFLIGHTF4/config.c @@ -61,11 +61,8 @@ void targetConfiguration(master_t *config) config->compassConfig.mag_hardware = MAG_NONE; // disabled by default if (hardwareMotorType == MOTOR_BRUSHED) { - config->motorConfig.minthrottle = 1000; config->motorConfig.motorPwmRate = BRUSHED_MOTORS_PWM_RATE; - config->motorConfig.motorPwmProtocol = PWM_TYPE_BRUSHED; config->pid_process_denom = 1; - config->motorConfig.useUnsyncedPwm = true; } if (hardwareRevision == AFF4_REV_1) { diff --git a/src/main/target/ALIENFLIGHTF4/hardware_revision.c b/src/main/target/ALIENFLIGHTF4/hardware_revision.c index 918e897c8..37f591828 100644 --- a/src/main/target/ALIENFLIGHTF4/hardware_revision.c +++ b/src/main/target/ALIENFLIGHTF4/hardware_revision.c @@ -28,10 +28,8 @@ #include "hardware_revision.h" uint8_t hardwareRevision = AFF4_UNKNOWN; -uint8_t hardwareMotorType = MOTOR_UNKNOWN; static IO_t HWDetectPin = IO_NONE; -static IO_t MotorDetectPin = IO_NONE; void detectHardwareRevision(void) { @@ -39,10 +37,6 @@ void detectHardwareRevision(void) IOInit(HWDetectPin, OWNER_SYSTEM, 0); IOConfigGPIO(HWDetectPin, IOCFG_IPU); - MotorDetectPin = IOGetByTag(IO_TAG(MOTOR_PIN)); - IOInit(MotorDetectPin, OWNER_SYSTEM, 0); - IOConfigGPIO(MotorDetectPin, IOCFG_IPU); - delayMicroseconds(10); // allow configuration to settle // Check hardware revision @@ -51,13 +45,6 @@ void detectHardwareRevision(void) } else { hardwareRevision = AFF4_REV_2; } - - // Check presence of brushed ESC's - if (IORead(MotorDetectPin)) { - hardwareMotorType = MOTOR_BRUSHLESS; - } else { - hardwareMotorType = MOTOR_BRUSHED; - } } void updateHardwareRevision(void) diff --git a/src/main/target/ALIENFLIGHTF4/hardware_revision.h b/src/main/target/ALIENFLIGHTF4/hardware_revision.h index e421b8896..410c8adca 100644 --- a/src/main/target/ALIENFLIGHTF4/hardware_revision.h +++ b/src/main/target/ALIENFLIGHTF4/hardware_revision.h @@ -22,14 +22,7 @@ typedef enum awf4HardwareRevision_t { AFF4_REV_2 // ICM-20602 (SPI), OpenSky RX (CC2510), Current Sensor (ACS712), SDCard Reader } awf4HardwareRevision_e; -typedef enum awf4HardwareMotorType_t { - MOTOR_UNKNOWN = 0, - MOTOR_BRUSHED, - MOTOR_BRUSHLESS -} awf4HardwareMotorType_e; - extern uint8_t hardwareRevision; -extern uint8_t hardwareMotorType; void updateHardwareRevision(void); void detectHardwareRevision(void); diff --git a/src/main/target/ALIENFLIGHTF4/target.h b/src/main/target/ALIENFLIGHTF4/target.h index 058759327..b85db3d9a 100644 --- a/src/main/target/ALIENFLIGHTF4/target.h +++ b/src/main/target/ALIENFLIGHTF4/target.h @@ -21,7 +21,7 @@ #define USE_HARDWARE_REVISION_DETECTION #define HW_PIN PC13 -#define MOTOR_PIN PB8 +#define BRUSHED_ESC_AUTODETECT #define CONFIG_START_FLASH_ADDRESS (0x08080000) //0x08080000 to 0x080A0000 (FLASH_Sector_8) diff --git a/src/main/target/ANYFCF7/target.h b/src/main/target/ANYFCF7/target.h index bea085ae9..007488d4f 100644 --- a/src/main/target/ANYFCF7/target.h +++ b/src/main/target/ANYFCF7/target.h @@ -24,7 +24,7 @@ #define USBD_PRODUCT_STRING "AnyFCF7" #define USE_DSHOT -#define USE_ESC_TELEMETRY +#define USE_ESC_SENSOR #define LED0 PB7 #define LED1 PB6 diff --git a/src/main/target/BETAFLIGHTF3/target.h b/src/main/target/BETAFLIGHTF3/target.h index f22a23573..bfd47caef 100755 --- a/src/main/target/BETAFLIGHTF3/target.h +++ b/src/main/target/BETAFLIGHTF3/target.h @@ -44,7 +44,8 @@ #define MPU_INT_EXTI PC13 #define USE_EXTI -#define USE_ESC_TELEMETRY +#define USE_DSHOT +#define USE_ESC_SENSOR #define REMAP_TIM16_DMA #define REMAP_TIM17_DMA diff --git a/src/main/target/BLUEJAYF4/hardware_revision.c b/src/main/target/BLUEJAYF4/hardware_revision.c index 7261aa223..cb70d05f7 100644 --- a/src/main/target/BLUEJAYF4/hardware_revision.c +++ b/src/main/target/BLUEJAYF4/hardware_revision.c @@ -85,7 +85,8 @@ void updateHardwareRevision(void) /* if flash exists on PB3 then Rev1 */ - if (m25p16_init(IO_TAG(PB3))) { + flashConfig_t flashConfig = { .csTag = IO_TAG(PB3) }; + if (m25p16_init(&flashConfig)) { hardwareRevision = BJF4_REV1; } else { IOInit(IOGetByTag(IO_TAG(PB3)), OWNER_FREE, 0); diff --git a/src/main/target/BLUEJAYF4/target.h b/src/main/target/BLUEJAYF4/target.h index ad588a23a..5ab4925f4 100644 --- a/src/main/target/BLUEJAYF4/target.h +++ b/src/main/target/BLUEJAYF4/target.h @@ -144,7 +144,8 @@ #define USE_ADC #define VBAT_ADC_PIN PC3 -#define USE_ESC_TELEMETRY +#define USE_DSHOT +#define USE_ESC_SENSOR #define LED_STRIP #define ENABLE_BLACKBOX_LOGGING_ON_SDCARD_BY_DEFAULT diff --git a/src/main/target/ALIENFLIGHTF1/hardware_revision.h b/src/main/target/CJMCU/initialisation.c similarity index 58% rename from src/main/target/ALIENFLIGHTF1/hardware_revision.h rename to src/main/target/CJMCU/initialisation.c index 8fcb761fc..817dfc540 100644 --- a/src/main/target/ALIENFLIGHTF1/hardware_revision.h +++ b/src/main/target/CJMCU/initialisation.c @@ -14,24 +14,23 @@ * You should have received a copy of the GNU General Public License * along with Cleanflight. If not, see . */ -#pragma once -typedef enum awf1HardwareRevision_t { - AFF1_UNKNOWN = 0, - AFF1_REV_1, // MPU6050 (I2C) -} awf1HardwareRevision_e; +#include +#include -typedef enum awf4HardwareMotorType_t { - MOTOR_UNKNOWN = 0, - MOTOR_BRUSHED, - MOTOR_BRUSHLESS -} awf4HardwareMotorType_e; +#include "platform.h" +#include "drivers/bus_i2c.h" +#include "drivers/bus_spi.h" +#include "io/serial.h" -extern uint8_t hardwareRevision; -extern uint8_t hardwareMotorType; +void targetBusInit(void) +{ + #if defined(USE_SPI) && defined(USE_SPI_DEVICE_1) + spiInit(SPIDEV_1); + #endif -void updateHardwareRevision(void); -void detectHardwareRevision(void); - -struct extiConfig_s; -const struct extiConfig_s *selectMPUIntExtiConfigByHardwareRevision(void); + if (!doesConfigurationUsePort(SERIAL_PORT_USART3)) { + serialRemovePort(SERIAL_PORT_USART3); + i2cInit(I2C_DEVICE); + } +} \ No newline at end of file diff --git a/src/main/target/CJMCU/target.h b/src/main/target/CJMCU/target.h index de5afbd44..4f3d274b9 100644 --- a/src/main/target/CJMCU/target.h +++ b/src/main/target/CJMCU/target.h @@ -19,6 +19,7 @@ #define TARGET_BOARD_IDENTIFIER "CJM1" // CJMCU #define USE_HARDWARE_REVISION_DETECTION +#define TARGET_BUS_INIT #define LED0 PC14 #define LED1 PC13 diff --git a/src/main/target/DOGE/target.h b/src/main/target/DOGE/target.h index 5b360ed8d..1f10fcb0f 100644 --- a/src/main/target/DOGE/target.h +++ b/src/main/target/DOGE/target.h @@ -125,7 +125,8 @@ #define ENSURE_MPU_DATA_READY_IS_LOW #define LED_STRIP -#define USE_ESC_TELEMETRY +#define USE_DSHOT +#define USE_ESC_SENSOR #define DEFAULT_RX_FEATURE FEATURE_RX_PPM diff --git a/src/main/target/FURYF3/target.h b/src/main/target/FURYF3/target.h index a858e9732..5497f9021 100644 --- a/src/main/target/FURYF3/target.h +++ b/src/main/target/FURYF3/target.h @@ -161,7 +161,8 @@ #define USE_SERIAL_4WAY_BLHELI_INTERFACE -#define USE_ESC_TELEMETRY +#define USE_DSHOT +#define USE_ESC_SENSOR #define REMAP_TIM17_DMA #define TARGET_IO_PORTA 0xffff diff --git a/src/main/target/FURYF4/target.h b/src/main/target/FURYF4/target.h index 790d3096d..4d35a98fb 100644 --- a/src/main/target/FURYF4/target.h +++ b/src/main/target/FURYF4/target.h @@ -175,7 +175,8 @@ #define USE_SERIAL_4WAY_BLHELI_INTERFACE -#define USE_ESC_TELEMETRY +#define USE_DSHOT +#define USE_ESC_SENSOR #define TARGET_IO_PORTA 0xffff #define TARGET_IO_PORTB 0xffff diff --git a/src/main/target/FURYF7/target.h b/src/main/target/FURYF7/target.h index 35410dff5..2cbffeaed 100644 --- a/src/main/target/FURYF7/target.h +++ b/src/main/target/FURYF7/target.h @@ -24,7 +24,7 @@ #define USBD_PRODUCT_STRING "FuryF7" #define USE_DSHOT -#define USE_ESC_TELEMETRY +#define USE_ESC_SENSOR #define LED0 PB5 #define LED1 PB4 diff --git a/src/main/target/IMPULSERCF3/target.h b/src/main/target/IMPULSERCF3/target.h index 9689883a5..79382b81c 100644 --- a/src/main/target/IMPULSERCF3/target.h +++ b/src/main/target/IMPULSERCF3/target.h @@ -46,7 +46,8 @@ #define USE_FLASHFS #define USE_FLASH_M25P16 -#define USE_ESC_TELEMETRY +#define USE_DSHOT +#define USE_ESC_SENSOR #define REMAP_TIM17_DMA #define USE_VCP diff --git a/src/main/target/KISSFC/target.h b/src/main/target/KISSFC/target.h index 2551072af..b7a523d9c 100644 --- a/src/main/target/KISSFC/target.h +++ b/src/main/target/KISSFC/target.h @@ -23,7 +23,8 @@ #define SBUS_PORT_OPTIONS (SERIAL_STOPBITS_2 | SERIAL_PARITY_EVEN | SERIAL_INVERTED | SERIAL_BIDIR) -#define USE_ESC_TELEMETRY +#define USE_DSHOT +#define USE_ESC_SENSOR #define USE_ESCSERIAL #define ESCSERIAL_TIMER_TX_HARDWARE 6 diff --git a/src/main/target/LUX_RACE/target.h b/src/main/target/LUX_RACE/target.h index fa6eb8a9f..a6ca94cd7 100644 --- a/src/main/target/LUX_RACE/target.h +++ b/src/main/target/LUX_RACE/target.h @@ -46,7 +46,8 @@ #define USE_MPU_DATA_READY_SIGNAL #define ENSURE_MPU_DATA_READY_IS_LOW -#define USE_ESC_TELEMETRY +#define USE_DSHOT +#define USE_ESC_SENSOR #define USE_SPI #define USE_SPI_DEVICE_1 diff --git a/src/main/target/MOTOLAB/target.h b/src/main/target/MOTOLAB/target.h index ef18dbd7c..52a6bebef 100644 --- a/src/main/target/MOTOLAB/target.h +++ b/src/main/target/MOTOLAB/target.h @@ -95,7 +95,8 @@ #define RSSI_ADC_PIN PB2 #define LED_STRIP -#define USE_ESC_TELEMETRY +#define USE_DSHOT +#define USE_ESC_SENSOR #define SPEKTRUM_BIND // USART2, PB4 diff --git a/src/main/target/MULTIFLITEPICO/target.h b/src/main/target/MULTIFLITEPICO/target.h index e56633eaf..7e5a0f045 100755 --- a/src/main/target/MULTIFLITEPICO/target.h +++ b/src/main/target/MULTIFLITEPICO/target.h @@ -105,7 +105,8 @@ #define CURRENT_METER_ADC_PIN PA5 #define RSSI_ADC_PIN PB2 -#define USE_ESC_TELEMETRY +#define USE_DSHOT +#define USE_ESC_SENSOR #define REMAP_TIM17_DMA // UART1 TX uses DMA1_Channel4, which is also used by dshot on motor 4 diff --git a/src/main/target/NAZE/config.c b/src/main/target/NAZE/config.c index b4142093e..6e8e07591 100755 --- a/src/main/target/NAZE/config.c +++ b/src/main/target/NAZE/config.c @@ -35,6 +35,8 @@ void targetConfiguration(master_t *config) { + UNUSED(config); + #ifdef BEEBRAIN // alternative defaults settings for Beebrain target config->motorConfig.motorPwmRate = 4000; @@ -88,9 +90,8 @@ void targetConfiguration(master_t *config) } else { config->beeperConfig.isOpenDrain = true; config->beeperConfig.isInverted = false; + config->flashConfig.csTag = IO_TAG_NONE; } -#else - UNUSED(config); #endif } diff --git a/src/main/target/NAZE/hardware_revision.c b/src/main/target/NAZE/hardware_revision.c index 533d8bb58..031b4d43a 100755 --- a/src/main/target/NAZE/hardware_revision.c +++ b/src/main/target/NAZE/hardware_revision.c @@ -127,3 +127,4 @@ const extiConfig_t *selectMPUIntExtiConfigByHardwareRevision(void) } #endif } + diff --git a/src/main/target/ALIENFLIGHTF1/hardware_revision.c b/src/main/target/NAZE/initialisation.c similarity index 50% rename from src/main/target/ALIENFLIGHTF1/hardware_revision.c rename to src/main/target/NAZE/initialisation.c index 4ea15ecde..9ff56b1f6 100644 --- a/src/main/target/ALIENFLIGHTF1/hardware_revision.c +++ b/src/main/target/NAZE/initialisation.c @@ -17,43 +17,28 @@ #include #include -#include #include "platform.h" - -#include "build/build_config.h" - -#include "drivers/system.h" -#include "drivers/io.h" -#include "drivers/exti.h" +#include "drivers/bus_i2c.h" +#include "drivers/bus_spi.h" +#include "io/serial.h" #include "hardware_revision.h" -uint8_t hardwareRevision = AFF1_REV_1; -uint8_t hardwareMotorType = MOTOR_UNKNOWN; - -static IO_t MotorDetectPin = IO_NONE; - -void detectHardwareRevision(void) +void targetBusInit(void) { - MotorDetectPin = IOGetByTag(IO_TAG(MOTOR_PIN)); - IOInit(MotorDetectPin, OWNER_SYSTEM, 0); - IOConfigGPIO(MotorDetectPin, IOCFG_IPU); + #ifdef USE_SPI + #ifdef USE_SPI_DEVICE_2 + spiInit(SPIDEV_2); + #endif + #endif - delayMicroseconds(10); // allow configuration to settle - - // Check presence of brushed ESC's - if (IORead(MotorDetectPin)) { - hardwareMotorType = MOTOR_BRUSHLESS; + if (hardwareRevision != NAZE32_SP) { + i2cInit(I2C_DEVICE); + serialRemovePort(SERIAL_PORT_SOFTSERIAL2); } else { - hardwareMotorType = MOTOR_BRUSHED; + if (!doesConfigurationUsePort(SERIAL_PORT_USART3)) { + serialRemovePort(SERIAL_PORT_USART3); + i2cInit(I2C_DEVICE); + } } -} - -void updateHardwareRevision(void) -{ -} - -const extiConfig_t *selectMPUIntExtiConfigByHardwareRevision(void) -{ - return NULL; -} +} \ No newline at end of file diff --git a/src/main/target/NAZE/target.h b/src/main/target/NAZE/target.h index 184ea76ee..2272a5552 100644 --- a/src/main/target/NAZE/target.h +++ b/src/main/target/NAZE/target.h @@ -19,6 +19,7 @@ #define TARGET_CONFIG #define USE_HARDWARE_REVISION_DETECTION +#define TARGET_BUS_INIT #define CLI_MINIMAL_VERBOSITY @@ -65,19 +66,14 @@ #define USE_SPI_DEVICE_2 #define NAZE_SPI_INSTANCE SPI2 -#define NAZE_SPI_CS_GPIO GPIOB #define NAZE_SPI_CS_PIN PB12 -#define NAZE_CS_GPIO_CLK_PERIPHERAL RCC_APB2Periph_GPIOB // We either have this 16mbit flash chip on SPI or the MPU6500 acc/gyro depending on board revision: -#define M25P16_CS_GPIO NAZE_SPI_CS_GPIO #define M25P16_CS_PIN NAZE_SPI_CS_PIN #define M25P16_SPI_INSTANCE NAZE_SPI_INSTANCE -#define MPU6500_CS_GPIO_CLK_PERIPHERAL NAZE_CS_GPIO_CLK_PERIPHERAL -#define MPU6500_CS_GPIO NAZE_SPI_CS_GPIO -#define MPU6500_CS_PIN NAZE_SPI_CS_PIN -#define MPU6500_SPI_INSTANCE NAZE_SPI_INSTANCE +#define MPU6500_CS_PIN NAZE_SPI_CS_PIN +#define MPU6500_SPI_INSTANCE NAZE_SPI_INSTANCE #define USE_FLASHFS #define USE_FLASH_M25P16 diff --git a/src/main/target/NUCLEOF7/stm32f7xx_hal_conf.h b/src/main/target/NUCLEOF7/stm32f7xx_hal_conf.h new file mode 100644 index 000000000..f2e5ffc8f --- /dev/null +++ b/src/main/target/NUCLEOF7/stm32f7xx_hal_conf.h @@ -0,0 +1,438 @@ +/** + ****************************************************************************** + * @file stm32f7xx_hal_conf.h + * @brief HAL configuration file. + ****************************************************************************** + * @attention + * + *

© COPYRIGHT(c) 2016 STMicroelectronics

+ * + * 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 of STMicroelectronics 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 HOLDER 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. + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __STM32F7xx_HAL_CONF_H +#define __STM32F7xx_HAL_CONF_H + +#ifdef __cplusplus + extern "C" { +#endif + +/* Exported types ------------------------------------------------------------*/ +/* Exported constants --------------------------------------------------------*/ + +/* ########################## Module Selection ############################## */ +/** + * @brief This is the list of modules to be used in the HAL driver + */ +#define HAL_MODULE_ENABLED + +#define HAL_ADC_MODULE_ENABLED +/* #define HAL_CAN_MODULE_ENABLED */ +/* #define HAL_CEC_MODULE_ENABLED */ +/* #define HAL_CRC_MODULE_ENABLED */ +/* #define HAL_CRYP_MODULE_ENABLED */ +/* #define HAL_DAC_MODULE_ENABLED */ +/* #define HAL_DCMI_MODULE_ENABLED */ +/* #define HAL_DMA2D_MODULE_ENABLED */ +/* #define HAL_ETH_MODULE_ENABLED */ +/* #define HAL_NAND_MODULE_ENABLED */ +/* #define HAL_NOR_MODULE_ENABLED */ +/* #define HAL_SRAM_MODULE_ENABLED */ +/* #define HAL_SDRAM_MODULE_ENABLED */ +/* #define HAL_HASH_MODULE_ENABLED */ +/* #define HAL_I2S_MODULE_ENABLED */ +/* #define HAL_IWDG_MODULE_ENABLED */ +/* #define HAL_LPTIM_MODULE_ENABLED */ +/* #define HAL_LTDC_MODULE_ENABLED */ +/* #define HAL_QSPI_MODULE_ENABLED */ +/* #define HAL_RNG_MODULE_ENABLED */ +/* #define HAL_RTC_MODULE_ENABLED */ +/* #define HAL_SAI_MODULE_ENABLED */ +/* #define HAL_SD_MODULE_ENABLED */ +/* #define HAL_SPDIFRX_MODULE_ENABLED */ +#define HAL_SPI_MODULE_ENABLED +#define HAL_TIM_MODULE_ENABLED +#define HAL_UART_MODULE_ENABLED +#define HAL_USART_MODULE_ENABLED +/* #define HAL_IRDA_MODULE_ENABLED */ +/* #define HAL_SMARTCARD_MODULE_ENABLED */ +/* #define HAL_WWDG_MODULE_ENABLED */ +#define HAL_PCD_MODULE_ENABLED +/* #define HAL_HCD_MODULE_ENABLED */ +/* #define HAL_DFSDM_MODULE_ENABLED */ +/* #define HAL_DSI_MODULE_ENABLED */ +/* #define HAL_JPEG_MODULE_ENABLED */ +/* #define HAL_MDIOS_MODULE_ENABLED */ +#define HAL_GPIO_MODULE_ENABLED +#define HAL_DMA_MODULE_ENABLED +#define HAL_RCC_MODULE_ENABLED +#define HAL_FLASH_MODULE_ENABLED +#define HAL_PWR_MODULE_ENABLED +#define HAL_I2C_MODULE_ENABLED +#define HAL_CORTEX_MODULE_ENABLED + +/* ########################## HSE/HSI Values adaptation ##################### */ +/** + * @brief Adjust the value of External High Speed oscillator (HSE) used in your application. + * This value is used by the RCC HAL module to compute the system frequency + * (when HSE is used as system clock source, directly or through the PLL). + */ +#if !defined (HSE_VALUE) + #define HSE_VALUE ((uint32_t)8000000U) /*!< Value of the External oscillator in Hz */ +#endif /* HSE_VALUE */ + +#if !defined (HSE_STARTUP_TIMEOUT) + #define HSE_STARTUP_TIMEOUT ((uint32_t)100U) /*!< Time out for HSE start up, in ms */ +#endif /* HSE_STARTUP_TIMEOUT */ + +/** + * @brief Internal High Speed oscillator (HSI) value. + * This value is used by the RCC HAL module to compute the system frequency + * (when HSI is used as system clock source, directly or through the PLL). + */ +#if !defined (HSI_VALUE) + #define HSI_VALUE ((uint32_t)16000000U) /*!< Value of the Internal oscillator in Hz*/ +#endif /* HSI_VALUE */ + +/** + * @brief Internal Low Speed oscillator (LSI) value. + */ +#if !defined (LSI_VALUE) + #define LSI_VALUE ((uint32_t)32000U) /*!< LSI Typical Value in Hz*/ +#endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz + The real value may vary depending on the variations + in voltage and temperature. */ +/** + * @brief External Low Speed oscillator (LSE) value. + */ +#if !defined (LSE_VALUE) + #define LSE_VALUE ((uint32_t)32768U) /*!< Value of the External Low Speed oscillator in Hz */ +#endif /* LSE_VALUE */ + +#if !defined (LSE_STARTUP_TIMEOUT) + #define LSE_STARTUP_TIMEOUT ((uint32_t)5000U) /*!< Time out for LSE start up, in ms */ +#endif /* LSE_STARTUP_TIMEOUT */ + +/** + * @brief External clock source for I2S peripheral + * This value is used by the I2S HAL module to compute the I2S clock source + * frequency, this source is inserted directly through I2S_CKIN pad. + */ +#if !defined (EXTERNAL_CLOCK_VALUE) + #define EXTERNAL_CLOCK_VALUE ((uint32_t)12288000U) /*!< Value of the Internal oscillator in Hz*/ +#endif /* EXTERNAL_CLOCK_VALUE */ + +/* Tip: To avoid modifying this file each time you need to use different HSE, + === you can define the HSE value in your toolchain compiler preprocessor. */ + +/* ########################### System Configuration ######################### */ +/** + * @brief This is the HAL system configuration section + */ +#define VDD_VALUE ((uint32_t)3300U) /*!< Value of VDD in mv */ +#define TICK_INT_PRIORITY ((uint32_t)0U) /*!< tick interrupt priority */ +#define USE_RTOS 0U +#define PREFETCH_ENABLE 0U +#define ART_ACCLERATOR_ENABLE 0U /* To enable instruction cache and prefetch */ + +/* ########################## Assert Selection ############################## */ +/** + * @brief Uncomment the line below to expanse the "assert_param" macro in the + * HAL drivers code + */ +/* #define USE_FULL_ASSERT 1 */ + +/* ################## Ethernet peripheral configuration ##################### */ + +/* Section 1 : Ethernet peripheral configuration */ + +/* MAC ADDRESS: MAC_ADDR0:MAC_ADDR1:MAC_ADDR2:MAC_ADDR3:MAC_ADDR4:MAC_ADDR5 */ +#define MAC_ADDR0 2U +#define MAC_ADDR1 0U +#define MAC_ADDR2 0U +#define MAC_ADDR3 0U +#define MAC_ADDR4 0U +#define MAC_ADDR5 0U + +/* Definition of the Ethernet driver buffers size and count */ +#define ETH_RX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for receive */ +#define ETH_TX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for transmit */ +#define ETH_RXBUFNB ((uint32_t)4U) /* 4 Rx buffers of size ETH_RX_BUF_SIZE */ +#define ETH_TXBUFNB ((uint32_t)4U) /* 4 Tx buffers of size ETH_TX_BUF_SIZE */ + +/* Section 2: PHY configuration section */ + +/* DP83848_PHY_ADDRESS Address*/ +#define DP83848_PHY_ADDRESS 0x01U +/* PHY Reset delay these values are based on a 1 ms Systick interrupt*/ +#define PHY_RESET_DELAY ((uint32_t)0x000000FFU) +/* PHY Configuration delay */ +#define PHY_CONFIG_DELAY ((uint32_t)0x00000FFFU) + +#define PHY_READ_TO ((uint32_t)0x0000FFFFU) +#define PHY_WRITE_TO ((uint32_t)0x0000FFFFU) + +/* Section 3: Common PHY Registers */ + +#define PHY_BCR ((uint16_t)0x0000U) /*!< Transceiver Basic Control Register */ +#define PHY_BSR ((uint16_t)0x0001U) /*!< Transceiver Basic Status Register */ + +#define PHY_RESET ((uint16_t)0x8000U) /*!< PHY Reset */ +#define PHY_LOOPBACK ((uint16_t)0x4000U) /*!< Select loop-back mode */ +#define PHY_FULLDUPLEX_100M ((uint16_t)0x2100U) /*!< Set the full-duplex mode at 100 Mb/s */ +#define PHY_HALFDUPLEX_100M ((uint16_t)0x2000U) /*!< Set the half-duplex mode at 100 Mb/s */ +#define PHY_FULLDUPLEX_10M ((uint16_t)0x0100U) /*!< Set the full-duplex mode at 10 Mb/s */ +#define PHY_HALFDUPLEX_10M ((uint16_t)0x0000U) /*!< Set the half-duplex mode at 10 Mb/s */ +#define PHY_AUTONEGOTIATION ((uint16_t)0x1000U) /*!< Enable auto-negotiation function */ +#define PHY_RESTART_AUTONEGOTIATION ((uint16_t)0x0200U) /*!< Restart auto-negotiation function */ +#define PHY_POWERDOWN ((uint16_t)0x0800U) /*!< Select the power down mode */ +#define PHY_ISOLATE ((uint16_t)0x0400U) /*!< Isolate PHY from MII */ + +#define PHY_AUTONEGO_COMPLETE ((uint16_t)0x0020U) /*!< Auto-Negotiation process completed */ +#define PHY_LINKED_STATUS ((uint16_t)0x0004U) /*!< Valid link established */ +#define PHY_JABBER_DETECTION ((uint16_t)0x0002U) /*!< Jabber condition detected */ + +/* Section 4: Extended PHY Registers */ +#define PHY_SR ((uint16_t)0x10U) /*!< PHY status register Offset */ + +#define PHY_SPEED_STATUS ((uint16_t)0x0002U) /*!< PHY Speed mask */ +#define PHY_DUPLEX_STATUS ((uint16_t)0x0004U) /*!< PHY Duplex mask */ + +/* ################## SPI peripheral configuration ########################## */ + +/* CRC FEATURE: Use to activate CRC feature inside HAL SPI Driver +* Activated: CRC code is present inside driver +* Deactivated: CRC code cleaned from driver +*/ + +#define USE_SPI_CRC 0U + +/* Includes ------------------------------------------------------------------*/ +/** + * @brief Include module's header file + */ + +#ifdef HAL_RCC_MODULE_ENABLED + #include "stm32f7xx_hal_rcc.h" +#endif /* HAL_RCC_MODULE_ENABLED */ + +#ifdef HAL_GPIO_MODULE_ENABLED + #include "stm32f7xx_hal_gpio.h" +#endif /* HAL_GPIO_MODULE_ENABLED */ + +#ifdef HAL_DMA_MODULE_ENABLED + #include "stm32f7xx_hal_dma.h" +#endif /* HAL_DMA_MODULE_ENABLED */ + +#ifdef HAL_CORTEX_MODULE_ENABLED + #include "stm32f7xx_hal_cortex.h" +#endif /* HAL_CORTEX_MODULE_ENABLED */ + +#ifdef HAL_ADC_MODULE_ENABLED + #include "stm32f7xx_hal_adc.h" +#endif /* HAL_ADC_MODULE_ENABLED */ + +#ifdef HAL_CAN_MODULE_ENABLED + #include "stm32f7xx_hal_can.h" +#endif /* HAL_CAN_MODULE_ENABLED */ + +#ifdef HAL_CEC_MODULE_ENABLED + #include "stm32f7xx_hal_cec.h" +#endif /* HAL_CEC_MODULE_ENABLED */ + +#ifdef HAL_CRC_MODULE_ENABLED + #include "stm32f7xx_hal_crc.h" +#endif /* HAL_CRC_MODULE_ENABLED */ + +#ifdef HAL_CRYP_MODULE_ENABLED + #include "stm32f7xx_hal_cryp.h" +#endif /* HAL_CRYP_MODULE_ENABLED */ + +#ifdef HAL_DMA2D_MODULE_ENABLED + #include "stm32f7xx_hal_dma2d.h" +#endif /* HAL_DMA2D_MODULE_ENABLED */ + +#ifdef HAL_DAC_MODULE_ENABLED + #include "stm32f7xx_hal_dac.h" +#endif /* HAL_DAC_MODULE_ENABLED */ + +#ifdef HAL_DCMI_MODULE_ENABLED + #include "stm32f7xx_hal_dcmi.h" +#endif /* HAL_DCMI_MODULE_ENABLED */ + +#ifdef HAL_ETH_MODULE_ENABLED + #include "stm32f7xx_hal_eth.h" +#endif /* HAL_ETH_MODULE_ENABLED */ + +#ifdef HAL_FLASH_MODULE_ENABLED + #include "stm32f7xx_hal_flash.h" +#endif /* HAL_FLASH_MODULE_ENABLED */ + +#ifdef HAL_SRAM_MODULE_ENABLED + #include "stm32f7xx_hal_sram.h" +#endif /* HAL_SRAM_MODULE_ENABLED */ + +#ifdef HAL_NOR_MODULE_ENABLED + #include "stm32f7xx_hal_nor.h" +#endif /* HAL_NOR_MODULE_ENABLED */ + +#ifdef HAL_NAND_MODULE_ENABLED + #include "stm32f7xx_hal_nand.h" +#endif /* HAL_NAND_MODULE_ENABLED */ + +#ifdef HAL_SDRAM_MODULE_ENABLED + #include "stm32f7xx_hal_sdram.h" +#endif /* HAL_SDRAM_MODULE_ENABLED */ + +#ifdef HAL_HASH_MODULE_ENABLED + #include "stm32f7xx_hal_hash.h" +#endif /* HAL_HASH_MODULE_ENABLED */ + +#ifdef HAL_I2C_MODULE_ENABLED + #include "stm32f7xx_hal_i2c.h" +#endif /* HAL_I2C_MODULE_ENABLED */ + +#ifdef HAL_I2S_MODULE_ENABLED + #include "stm32f7xx_hal_i2s.h" +#endif /* HAL_I2S_MODULE_ENABLED */ + +#ifdef HAL_IWDG_MODULE_ENABLED + #include "stm32f7xx_hal_iwdg.h" +#endif /* HAL_IWDG_MODULE_ENABLED */ + +#ifdef HAL_LPTIM_MODULE_ENABLED + #include "stm32f7xx_hal_lptim.h" +#endif /* HAL_LPTIM_MODULE_ENABLED */ + +#ifdef HAL_LTDC_MODULE_ENABLED + #include "stm32f7xx_hal_ltdc.h" +#endif /* HAL_LTDC_MODULE_ENABLED */ + +#ifdef HAL_PWR_MODULE_ENABLED + #include "stm32f7xx_hal_pwr.h" +#endif /* HAL_PWR_MODULE_ENABLED */ + +#ifdef HAL_QSPI_MODULE_ENABLED + #include "stm32f7xx_hal_qspi.h" +#endif /* HAL_QSPI_MODULE_ENABLED */ + +#ifdef HAL_RNG_MODULE_ENABLED + #include "stm32f7xx_hal_rng.h" +#endif /* HAL_RNG_MODULE_ENABLED */ + +#ifdef HAL_RTC_MODULE_ENABLED + #include "stm32f7xx_hal_rtc.h" +#endif /* HAL_RTC_MODULE_ENABLED */ + +#ifdef HAL_SAI_MODULE_ENABLED + #include "stm32f7xx_hal_sai.h" +#endif /* HAL_SAI_MODULE_ENABLED */ + +#ifdef HAL_SD_MODULE_ENABLED + #include "stm32f7xx_hal_sd.h" +#endif /* HAL_SD_MODULE_ENABLED */ + +#ifdef HAL_SPDIFRX_MODULE_ENABLED + #include "stm32f7xx_hal_spdifrx.h" +#endif /* HAL_SPDIFRX_MODULE_ENABLED */ + +#ifdef HAL_SPI_MODULE_ENABLED + #include "stm32f7xx_hal_spi.h" +#endif /* HAL_SPI_MODULE_ENABLED */ + +#ifdef HAL_TIM_MODULE_ENABLED + #include "stm32f7xx_hal_tim.h" +#endif /* HAL_TIM_MODULE_ENABLED */ + +#ifdef HAL_UART_MODULE_ENABLED + #include "stm32f7xx_hal_uart.h" +#endif /* HAL_UART_MODULE_ENABLED */ + +#ifdef HAL_USART_MODULE_ENABLED + #include "stm32f7xx_hal_usart.h" +#endif /* HAL_USART_MODULE_ENABLED */ + +#ifdef HAL_IRDA_MODULE_ENABLED + #include "stm32f7xx_hal_irda.h" +#endif /* HAL_IRDA_MODULE_ENABLED */ + +#ifdef HAL_SMARTCARD_MODULE_ENABLED + #include "stm32f7xx_hal_smartcard.h" +#endif /* HAL_SMARTCARD_MODULE_ENABLED */ + +#ifdef HAL_WWDG_MODULE_ENABLED + #include "stm32f7xx_hal_wwdg.h" +#endif /* HAL_WWDG_MODULE_ENABLED */ + +#ifdef HAL_PCD_MODULE_ENABLED + #include "stm32f7xx_hal_pcd.h" +#endif /* HAL_PCD_MODULE_ENABLED */ + +#ifdef HAL_HCD_MODULE_ENABLED + #include "stm32f7xx_hal_hcd.h" +#endif /* HAL_HCD_MODULE_ENABLED */ + +#ifdef HAL_DFSDM_MODULE_ENABLED + #include "stm32f7xx_hal_dfsdm.h" +#endif /* HAL_DFSDM_MODULE_ENABLED */ + +#ifdef HAL_DSI_MODULE_ENABLED + #include "stm32f7xx_hal_dsi.h" +#endif /* HAL_DSI_MODULE_ENABLED */ + +#ifdef HAL_JPEG_MODULE_ENABLED + #include "stm32f7xx_hal_jpeg.h" +#endif /* HAL_JPEG_MODULE_ENABLED */ + +#ifdef HAL_MDIOS_MODULE_ENABLED + #include "stm32f7xx_hal_mdios.h" +#endif /* HAL_MDIOS_MODULE_ENABLED */ + +/* Exported macro ------------------------------------------------------------*/ +#ifdef USE_FULL_ASSERT +/** + * @brief The assert_param macro is used for function's parameters check. + * @param expr: If expr is false, it calls assert_failed function + * which reports the name of the source file and the source + * line number of the call that failed. + * If expr is true, it returns no value. + * @retval None + */ + #define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__)) +/* Exported functions ------------------------------------------------------- */ + void assert_failed(uint8_t* file, uint32_t line); +#else + #define assert_param(expr) ((void)0U) +#endif /* USE_FULL_ASSERT */ + +#ifdef __cplusplus +} +#endif + +#endif /* __STM32F7xx_HAL_CONF_H */ + + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/src/main/target/NUCLEOF7/target.c b/src/main/target/NUCLEOF7/target.c new file mode 100644 index 000000000..f20a73af6 --- /dev/null +++ b/src/main/target/NUCLEOF7/target.c @@ -0,0 +1,58 @@ +/* + * This file is part of Cleanflight. + * + * Cleanflight 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. + * + * Cleanflight 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 Cleanflight. If not, see . + */ + +#include + +#include +#include "drivers/io.h" +#include "drivers/dma.h" + +#include "drivers/timer.h" + +#if defined(USE_DSHOT) +// DSHOT TEST +const timerHardware_t timerHardware[USABLE_TIMER_CHANNEL_COUNT] = { + { TIM12, IO_TAG(PB15), TIM_CHANNEL_2, TIM_USE_PWM | TIM_USE_PPM, 0, GPIO_AF9_TIM12, NULL, 0, 0 }, // S2_IN + { TIM8, IO_TAG(PC6), TIM_CHANNEL_1, TIM_USE_PWM, 0, GPIO_AF3_TIM8, NULL, 0, 0 }, // S3_IN + { TIM8, IO_TAG(PC7), TIM_CHANNEL_2, TIM_USE_PWM, 0, GPIO_AF3_TIM8, NULL, 0, 0 }, // S4_IN + { TIM8, IO_TAG(PC9), TIM_CHANNEL_4, TIM_USE_PWM, 0, GPIO_AF3_TIM8, NULL, 0, 0 }, // S5_IN + { TIM8, IO_TAG(PC8), TIM_CHANNEL_3, TIM_USE_PWM, 0, GPIO_AF3_TIM8, NULL, 0, 0 }, // S6_IN + + { TIM4, IO_TAG(PB8), TIM_CHANNEL_3, TIM_USE_MOTOR, 1, GPIO_AF2_TIM4, DMA1_Stream7, DMA_CHANNEL_2, DMA1_ST7_HANDLER }, // S10_OUT 1 + { TIM2, IO_TAG(PA3), TIM_CHANNEL_4, TIM_USE_MOTOR, 1, GPIO_AF1_TIM2, DMA1_Stream6, DMA_CHANNEL_3, DMA1_ST6_HANDLER }, // S1_OUT 4 + { TIM3, IO_TAG(PB5), TIM_CHANNEL_2, TIM_USE_MOTOR, 1, GPIO_AF2_TIM3, DMA1_Stream5, DMA_CHANNEL_5, DMA1_ST5_HANDLER }, // S4_OUT + { TIM4, IO_TAG(PB9), TIM_CHANNEL_4, TIM_USE_MOTOR, 1, GPIO_AF2_TIM4, NULL, 0, 0 }, // S5_OUT 3 + { TIM9, IO_TAG(PE6), TIM_CHANNEL_2, TIM_USE_MOTOR, 1, GPIO_AF3_TIM9, NULL, 0, 0 }, // S3_OUT + { TIM3, IO_TAG(PB4), TIM_CHANNEL_1, TIM_USE_MOTOR, 1, GPIO_AF2_TIM3, NULL, 0, 0 }, // S9_OUT +}; +#else +// STANDARD LAYOUT +const timerHardware_t timerHardware[USABLE_TIMER_CHANNEL_COUNT] = { + { TIM12, IO_TAG(PB15), TIM_CHANNEL_2, TIM_USE_PWM | TIM_USE_PPM, 0, GPIO_AF9_TIM12, NULL, 0, 0 }, // S2_IN + { TIM8, IO_TAG(PC6), TIM_CHANNEL_1, TIM_USE_PWM, 0, GPIO_AF3_TIM8, NULL, 0, 0 }, // S3_IN + { TIM8, IO_TAG(PC7), TIM_CHANNEL_2, TIM_USE_PWM, 0, GPIO_AF3_TIM8, NULL, 0, 0 }, // S4_IN + { TIM8, IO_TAG(PC9), TIM_CHANNEL_4, TIM_USE_PWM, 0, GPIO_AF3_TIM8, NULL, 0, 0 }, // S5_IN + { TIM8, IO_TAG(PC8), TIM_CHANNEL_3, TIM_USE_PWM, 0, GPIO_AF3_TIM8, NULL, 0, 0 }, // S6_IN + + { TIM4, IO_TAG(PB8), TIM_CHANNEL_3, TIM_USE_MOTOR | TIM_USE_LED, 1, GPIO_AF2_TIM4, DMA1_Stream7, DMA_CHANNEL_2, DMA1_ST7_HANDLER }, // S10_OUT 1 + { TIM4, IO_TAG(PB9), TIM_CHANNEL_4, TIM_USE_MOTOR, 1, GPIO_AF2_TIM4, NULL, 0, 0 }, // S5_OUT 3 + { TIM2, IO_TAG(PA3), TIM_CHANNEL_4, TIM_USE_MOTOR, 1, GPIO_AF1_TIM2, NULL, 0, 0 }, // S1_OUT 4 + { TIM9, IO_TAG(PE6), TIM_CHANNEL_2, TIM_USE_MOTOR, 1, GPIO_AF3_TIM9, NULL, 0, 0 }, // S3_OUT + { TIM3, IO_TAG(PB5), TIM_CHANNEL_2, TIM_USE_MOTOR, 1, GPIO_AF2_TIM3, NULL, 0, 0 }, // S4_OUT + { TIM3, IO_TAG(PB4), TIM_CHANNEL_1, TIM_USE_MOTOR, 1, GPIO_AF2_TIM3, NULL, 0, 0 }, // S9_OUT +}; +#endif diff --git a/src/main/target/NUCLEOF7/target.h b/src/main/target/NUCLEOF7/target.h new file mode 100644 index 000000000..a1cf620a8 --- /dev/null +++ b/src/main/target/NUCLEOF7/target.h @@ -0,0 +1,163 @@ +/* + * This file is part of Cleanflight. + * + * Cleanflight 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. + * + * Cleanflight 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 Cleanflight. If not, see . + */ + +#pragma once + +#define TARGET_BOARD_IDENTIFIER "NUC7" + +#define CONFIG_START_FLASH_ADDRESS (0x080C0000) + +#define USBD_PRODUCT_STRING "NucleoF7" + +//#define USE_DSHOT +//#define USE_ESC_TELEMETRY + +#define LED0 PB7 +#define LED1 PB14 + +//#define BEEPER PB2 +//#define BEEPER_INVERTED + +#define ACC +#define USE_FAKE_ACC +#define USE_ACC_MPU6050 +#define ACC_MPU6050_ALIGN CW270_DEG + +#define GYRO +#define USE_FAKE_GYRO +#define USE_GYRO_MPU6050 +#define GYRO_MPU6050_ALIGN CW270_DEG + +// MPU6050 interrupts +#define USE_MPU_DATA_READY_SIGNAL +#define MPU_INT_EXTI PB15 +#define USE_EXTI + +#define MAG +#define USE_FAKE_MAG +#define USE_MAG_HMC5883 +#define MAG_HMC5883_ALIGN CW270_DEG_FLIP + +#define BARO +#define USE_FAKE_BARO +#define USE_BARO_MS5611 + +#define USABLE_TIMER_CHANNEL_COUNT 16 + +#define USE_VCP +#define VBUS_SENSING_PIN PA9 + +//#define USE_UART1 +//#define UART1_RX_PIN PA10 +//#define UART1_TX_PIN PA9 + +#define USE_UART2 +#define UART2_RX_PIN PD6 +#define UART2_TX_PIN PD5 + +#define USE_UART3 +#define UART3_RX_PIN PD9 +#define UART3_TX_PIN PD8 + +#define USE_UART4 +#define UART4_RX_PIN PC11 +#define UART4_TX_PIN PC10 + +#define USE_UART5 +#define UART5_RX_PIN PD2 +#define UART5_TX_PIN PC12 + +#define USE_UART6 +#define UART6_RX_PIN PC7 +#define UART6_TX_PIN PC6 + +#define USE_UART7 +#define UART7_RX_PIN PE7 +#define UART7_TX_PIN PE8 + +#define USE_UART8 +#define UART8_RX_PIN PE0 +#define UART8_TX_PIN PE1 + +#define SERIAL_PORT_COUNT 8 //VCP, USART2, USART3, UART4, UART5, USART6, USART7, USART8 + +#define USE_SPI +#define USE_SPI_DEVICE_1 +#define USE_SPI_DEVICE_4 + +#define SPI1_NSS_PIN PA4 +#define SPI1_SCK_PIN PA5 +#define SPI1_MISO_PIN PA6 +#define SPI1_MOSI_PIN PA7 + +#define SPI4_NSS_PIN PE11 +#define SPI4_SCK_PIN PE12 +#define SPI4_MISO_PIN PE13 +#define SPI4_MOSI_PIN PE14 + +#define USE_SDCARD +#define SDCARD_DETECT_INVERTED +#define SDCARD_DETECT_PIN PF14 +#define SDCARD_DETECT_EXTI_LINE EXTI_Line14 +#define SDCARD_DETECT_EXTI_PIN_SOURCE EXTI_PinSource14 +#define SDCARD_DETECT_EXTI_PORT_SOURCE EXTI_PortSourceGPIOF +#define SDCARD_DETECT_EXTI_IRQn EXTI9_15_IRQn + +#define SDCARD_SPI_INSTANCE SPI4 +#define SDCARD_SPI_CS_PIN SPI4_NSS_PIN + +#define SDCARD_SPI_INITIALIZATION_CLOCK_DIVIDER 256 // 422kHz +// Divide to under 25MHz for normal operation: +#define SDCARD_SPI_FULL_SPEED_CLOCK_DIVIDER 8 // 27MHz + +#define SDCARD_DMA_CHANNEL_TX DMA2_Stream1 +#define SDCARD_DMA_CHANNEL_TX_COMPLETE_FLAG DMA_FLAG_TCIF1_5 +#define SDCARD_DMA_CLK RCC_AHB1Periph_DMA2 +#define SDCARD_DMA_CHANNEL DMA_CHANNEL_4 + +#define USE_I2C +#define I2C_DEVICE (I2CDEV_1) +#define I2C1_SCL PB8 +#define I2C1_SDA PB9 + +//#define I2C_DEVICE_EXT (I2CDEV_2) + +#define SENSORS_SET (SENSOR_ACC|SENSOR_MAG|SENSOR_BARO) + +#define USE_ADC +#define VBAT_ADC_PIN PA3 +#define CURRENT_METER_ADC_PIN PC0 +#define RSSI_ADC_GPIO_PIN PC3 + +#define LED_STRIP + +#define ENABLE_BLACKBOX_LOGGING_ON_SDCARD_BY_DEFAULT + +#define DEFAULT_FEATURES (FEATURE_BLACKBOX) +#define DEFAULT_RX_FEATURE FEATURE_RX_SERIAL +#define SERIALRX_PROVIDER SERIALRX_SBUS + +#define USE_SERIAL_4WAY_BLHELI_INTERFACE + +#define TARGET_IO_PORTA 0xffff +#define TARGET_IO_PORTB 0xffff +#define TARGET_IO_PORTC 0xffff +#define TARGET_IO_PORTD 0xffff +#define TARGET_IO_PORTE 0xffff +#define TARGET_IO_PORTF 0xffff + +#define USED_TIMERS ( TIM_N(2) | TIM_N(3) | TIM_N(4) | TIM_N(5) | TIM_N(12) | TIM_N(8) | TIM_N(9) | TIM_N(10) | TIM_N(11)) diff --git a/src/main/target/NUCLEOF7/target.mk b/src/main/target/NUCLEOF7/target.mk new file mode 100644 index 000000000..f1e20157b --- /dev/null +++ b/src/main/target/NUCLEOF7/target.mk @@ -0,0 +1,12 @@ +F7X6XG_TARGETS += $(TARGET) +FEATURES += SDCARD VCP + +TARGET_SRC = \ + drivers/accgyro_fake.c \ + drivers/accgyro_mpu6050.c \ + drivers/barometer_fake.c \ + drivers/barometer_ms5611.c \ + drivers/compass_fake.c \ + drivers/compass_hmc5883l.c \ + drivers/light_ws2811strip.c \ + drivers/light_ws2811strip_hal.c diff --git a/src/main/target/OMNIBUS/target.h b/src/main/target/OMNIBUS/target.h index 7eb4b8e0b..238579fd8 100644 --- a/src/main/target/OMNIBUS/target.h +++ b/src/main/target/OMNIBUS/target.h @@ -133,7 +133,8 @@ // Divide to under 25MHz for normal operation: #define SDCARD_SPI_FULL_SPEED_CLOCK_DIVIDER 2 -#define USE_ESC_TELEMETRY +#define USE_DSHOT +#define USE_ESC_SENSOR // DSHOT output 4 uses DMA1_Channel5, so don't use it for the SDCARD until we find an alternative #ifndef USE_DSHOT @@ -176,10 +177,8 @@ #define DEFAULT_FEATURES (FEATURE_VBAT | FEATURE_CURRENT_METER | FEATURE_BLACKBOX) #define BUTTONS -#define BUTTON_A_PORT GPIOB -#define BUTTON_A_PIN Pin_1 -#define BUTTON_B_PORT GPIOB -#define BUTTON_B_PIN Pin_0 +#define BUTTON_A_PIN PB1 +#define BUTTON_B_PIN PB0 //#define AVOID_UART3_FOR_PWM_PPM // Disable this for using UART3 diff --git a/src/main/target/OMNIBUSF4/target.h b/src/main/target/OMNIBUSF4/target.h index 48b6f5e5f..abc338b68 100644 --- a/src/main/target/OMNIBUSF4/target.h +++ b/src/main/target/OMNIBUSF4/target.h @@ -160,7 +160,8 @@ #define VBAT_ADC_PIN PC2 //#define RSSI_ADC_PIN PA0 -#define USE_ESC_TELEMETRY +#define USE_DSHOT +#define USE_ESC_SENSOR #define LED_STRIP diff --git a/src/main/target/REVO/target.c b/src/main/target/REVO/target.c index 955d052cc..310ee9807 100644 --- a/src/main/target/REVO/target.c +++ b/src/main/target/REVO/target.c @@ -32,10 +32,10 @@ const timerHardware_t timerHardware[USABLE_TIMER_CHANNEL_COUNT] = { DEF_TIM(TIM8, CH3, PC8, TIM_USE_PWM, 0, 0), // S5_IN DEF_TIM(TIM8, CH4, PC9, TIM_USE_PWM, 0, 0), // S6_IN #ifdef REVOLT - DEF_TIM(TIM2, CH3, PA2, TIM_USE_MOTOR, 1, 0), // S4_OUT D1_ST1 - DEF_TIM(TIM3, CH4, PB1, TIM_USE_MOTOR, 1, 0), // S2_OUT D1_ST2 - DEF_TIM(TIM3, CH3, PB0, TIM_USE_MOTOR, 1, 0), // S1_OUT D1_ST7 DEF_TIM(TIM2, CH4, PA3, TIM_USE_MOTOR, 1, 1), // S3_OUT D1_ST6 + DEF_TIM(TIM3, CH4, PB1, TIM_USE_MOTOR, 1, 0), // S2_OUT D1_ST2 + DEF_TIM(TIM2, CH3, PA2, TIM_USE_MOTOR, 1, 0), // S4_OUT D1_ST1 + DEF_TIM(TIM3, CH3, PB0, TIM_USE_MOTOR, 1, 0), // S1_OUT D1_ST7 DEF_TIM(TIM4, CH1, PB6, TIM_USE_LED, 0, 0), // LED for REVOLT D1_ST0 #else DEF_TIM(TIM3, CH3, PB0, TIM_USE_MOTOR, 1, 0), // S1_OUT D1_ST7 diff --git a/src/main/target/REVO/target.h b/src/main/target/REVO/target.h index 710590d1d..82d0217de 100644 --- a/src/main/target/REVO/target.h +++ b/src/main/target/REVO/target.h @@ -20,43 +20,44 @@ #define CONFIG_START_FLASH_ADDRESS (0x08080000) //0x08080000 to 0x080A0000 (FLASH_Sector_8) #if defined(AIRBOTF4) - #define TARGET_BOARD_IDENTIFIER "AIR4" - #define USBD_PRODUCT_STRING "AirbotF4" +#define TARGET_BOARD_IDENTIFIER "AIR4" +#define USBD_PRODUCT_STRING "AirbotF4" #elif defined(REVOLT) - #define TARGET_BOARD_IDENTIFIER "RVLT" - #define USBD_PRODUCT_STRING "Revolt" +#define TARGET_BOARD_IDENTIFIER "RVLT" +#define USBD_PRODUCT_STRING "Revolt" #elif defined(SOULF4) - #define TARGET_BOARD_IDENTIFIER "SOUL" - #define USBD_PRODUCT_STRING "DemonSoulF4" +#define TARGET_BOARD_IDENTIFIER "SOUL" +#define USBD_PRODUCT_STRING "DemonSoulF4" #else - #define TARGET_BOARD_IDENTIFIER "REVO" - #define USBD_PRODUCT_STRING "Revolution" +#define TARGET_BOARD_IDENTIFIER "REVO" +#define USBD_PRODUCT_STRING "Revolution" - #ifdef OPBL - #define USBD_SERIALNUMBER_STRING "0x8020000" - #endif +#ifdef OPBL +#define USBD_SERIALNUMBER_STRING "0x8020000" +#endif #endif -#define USE_ESC_TELEMETRY +#define USE_DSHOT +#define USE_ESC_SENSOR #define LED0 PB5 // Disable LED1, conflicts with AirbotF4/Flip32F4/Revolt beeper #if defined(AIRBOTF4) - #define BEEPER PB4 - #define BEEPER_INVERTED +#define BEEPER PB4 +#define BEEPER_INVERTED #elif defined(REVOLT) - #define BEEPER PB4 +#define BEEPER PB4 #elif defined(SOULF4) - #define BEEPER PB6 - #define BEEPER_INVERTED +#define BEEPER PB6 +#define BEEPER_INVERTED #else - #define LED1 PB4 - // Leave beeper here but with none as io - so disabled unless mapped. - #define BEEPER NONE +#define LED1 PB4 +// Leave beeper here but with none as io - so disabled unless mapped. +#define BEEPER NONE #endif // PC0 used as inverter select GPIO @@ -70,30 +71,40 @@ #define MPU6500_SPI_INSTANCE SPI1 #if defined(SOULF4) - #define ACC - #define USE_ACC_SPI_MPU6000 - #define GYRO_MPU6000_ALIGN CW180_DEG +#define ACC +#define USE_ACC_SPI_MPU6000 +#define GYRO_MPU6000_ALIGN CW180_DEG - #define GYRO - #define USE_GYRO_SPI_MPU6000 - #define ACC_MPU6000_ALIGN CW180_DEG +#define GYRO +#define USE_GYRO_SPI_MPU6000 +#define ACC_MPU6000_ALIGN CW180_DEG + +#elif defined(REVOLT) + +#define USE_ACC_MPU6500 +#define USE_ACC_SPI_MPU6500 +#define ACC_MPU6500_ALIGN CW0_DEG + +#define USE_GYRO_MPU6500 +#define USE_GYRO_SPI_MPU6500 +#define GYRO_MPU6500_ALIGN CW0_DEG #else - #define ACC - #define USE_ACC_SPI_MPU6000 - #define GYRO_MPU6000_ALIGN CW270_DEG +#define ACC +#define USE_ACC_SPI_MPU6000 +#define GYRO_MPU6000_ALIGN CW270_DEG - #define USE_ACC_MPU6500 - #define USE_ACC_SPI_MPU6500 - #define ACC_MPU6500_ALIGN CW270_DEG +#define USE_ACC_MPU6500 +#define USE_ACC_SPI_MPU6500 +#define ACC_MPU6500_ALIGN CW270_DEG - #define GYRO - #define USE_GYRO_SPI_MPU6000 - #define ACC_MPU6000_ALIGN CW270_DEG +#define GYRO +#define USE_GYRO_SPI_MPU6000 +#define ACC_MPU6000_ALIGN CW270_DEG - #define USE_GYRO_MPU6500 - #define USE_GYRO_SPI_MPU6500 - #define GYRO_MPU6500_ALIGN CW270_DEG +#define USE_GYRO_MPU6500 +#define USE_GYRO_SPI_MPU6500 +#define GYRO_MPU6500_ALIGN CW270_DEG #endif @@ -103,12 +114,12 @@ #define USE_MPU_DATA_READY_SIGNAL #if !defined(AIRBOTF4) && !defined(REVOLT) && !defined(SOULF4) - #define MAG - #define USE_MAG_HMC5883 - #define MAG_HMC5883_ALIGN CW90_DEG +#define MAG +#define USE_MAG_HMC5883 +#define MAG_HMC5883_ALIGN CW90_DEG - #define BARO - #define USE_BARO_MS5611 +#define BARO +#define USE_BARO_MS5611 #endif diff --git a/src/main/target/SPARKY2/target.h b/src/main/target/SPARKY2/target.h index 5a33df421..f404c6ac4 100644 --- a/src/main/target/SPARKY2/target.h +++ b/src/main/target/SPARKY2/target.h @@ -35,7 +35,8 @@ #define INVERTER PC6 #define INVERTER_USART USART6 -#define USE_ESC_TELEMETRY +#define USE_DSHOT +#define USE_ESC_SENSOR // MPU9250 interrupt #define USE_EXTI diff --git a/src/main/target/SPRACINGF3/target.h b/src/main/target/SPRACINGF3/target.h index 3d906295e..e1b9bd419 100644 --- a/src/main/target/SPRACINGF3/target.h +++ b/src/main/target/SPRACINGF3/target.h @@ -98,6 +98,7 @@ #define SOFTSERIAL_2_TIMER TIM3 #define SOFTSERIAL_2_TIMER_RX_HARDWARE 6 // PWM 7 #define SOFTSERIAL_2_TIMER_TX_HARDWARE 7 // PWM 8 +#define SONAR_SOFTSERIAL2_EXCLUSIVE #define USE_I2C #define I2C_DEVICE (I2CDEV_1) // PB6/SCL, PB7/SDA @@ -115,7 +116,8 @@ #define CURRENT_METER_ADC_PIN PA5 #define RSSI_ADC_PIN PB2 -#define USE_ESC_TELEMETRY +#define USE_DSHOT +#define USE_ESC_SENSOR #define REMAP_TIM17_DMA // UART1 TX uses DMA1_Channel4, which is also used by dshot on motor 4 diff --git a/src/main/target/SPRACINGF3EVO/target.h b/src/main/target/SPRACINGF3EVO/target.h index 88e7d09f4..40f8af637 100755 --- a/src/main/target/SPRACINGF3EVO/target.h +++ b/src/main/target/SPRACINGF3EVO/target.h @@ -21,6 +21,8 @@ #define CONFIG_FASTLOOP_PREFERRED_ACC ACC_DEFAULT +#define BRUSHED_ESC_AUTODETECT + #define LED0 PB8 #define BEEPER PC15 @@ -35,7 +37,8 @@ #define USE_MAG_DATA_READY_SIGNAL #define ENSURE_MAG_DATA_READY_IS_HIGH -#define USE_ESC_TELEMETRY +#define USE_DSHOT +#define USE_ESC_SENSOR #define GYRO #define USE_GYRO_SPI_MPU6500 diff --git a/src/main/target/SPRACINGF3MINI/target.h b/src/main/target/SPRACINGF3MINI/target.h index 79c1508ac..24bfcfc5e 100644 --- a/src/main/target/SPRACINGF3MINI/target.h +++ b/src/main/target/SPRACINGF3MINI/target.h @@ -88,6 +88,7 @@ #define SOFTSERIAL_1_TIMER TIM2 #define SOFTSERIAL_1_TIMER_RX_HARDWARE 9 // PA0 / PAD3 #define SOFTSERIAL_1_TIMER_TX_HARDWARE 10 // PA1 / PAD4 +#define SONAR_SOFTSERIAL1_EXCLUSIVE #define USE_I2C #define I2C_DEVICE (I2CDEV_1) // PB6/SCL, PB7/SDA @@ -129,13 +130,6 @@ #define RSSI_ADC_PIN PB2 #define LED_STRIP -#define WS2811_PIN PA8 -#define WS2811_TIMER TIM1 -#define WS2811_DMA_CHANNEL DMA1_Channel2 -#define WS2811_IRQ DMA1_Channel2_IRQn -#define WS2811_DMA_TC_FLAG DMA1_FLAG_TC2 -#define WS2811_DMA_HANDLER_IDENTIFER DMA1_CH2_HANDLER -#define WS2811_TIMER_GPIO_AF GPIO_AF_6 #define TRANSPONDER @@ -147,10 +141,8 @@ #define DEFAULT_FEATURES FEATURE_BLACKBOX #define BUTTONS -#define BUTTON_A_PORT GPIOB -#define BUTTON_A_PIN Pin_1 -#define BUTTON_B_PORT GPIOB -#define BUTTON_B_PIN Pin_0 +#define BUTTON_A_PIN PB1 +#define BUTTON_B_PIN PB0 #define SPEKTRUM_BIND // USART3, diff --git a/src/main/target/STM32F3DISCOVERY/target.h b/src/main/target/STM32F3DISCOVERY/target.h index a43b50faf..1e7670eb3 100644 --- a/src/main/target/STM32F3DISCOVERY/target.h +++ b/src/main/target/STM32F3DISCOVERY/target.h @@ -169,7 +169,8 @@ #define RSSI_ADC_PIN PC2 #define EXTERNAL1_ADC_PIN PC3 -#define USE_ESC_TELEMETRY +#define USE_DSHOT +#define USE_ESC_SENSOR #define LED_STRIP diff --git a/src/main/target/X_RACERSPI/target.h b/src/main/target/X_RACERSPI/target.h index 8ade29012..5e5ae8f66 100644 --- a/src/main/target/X_RACERSPI/target.h +++ b/src/main/target/X_RACERSPI/target.h @@ -71,7 +71,7 @@ #define SOFTSERIAL_1_TIMER TIM3 #define SOFTSERIAL_1_TIMER_RX_HARDWARE 4 // PWM 5 #define SOFTSERIAL_1_TIMER_TX_HARDWARE 5 // PWM 6 - +#define SONAR_SOFTSERIAL1_EXCLUSIVE #define USE_I2C #define I2C_DEVICE (I2CDEV_1) // PB6/SCL, PB7/SDA @@ -101,7 +101,8 @@ #define CURRENT_METER_ADC_PIN PA5 #define RSSI_ADC_PIN PB2 -#define USE_ESC_TELEMETRY +#define USE_DSHOT +#define USE_ESC_SENSOR #define REMAP_TIM17_DMA // UART1 TX uses DMA1_Channel4, which is also used by dshot on motor 4 diff --git a/src/main/target/link/stm32_flash_f746.ld b/src/main/target/link/stm32_flash_f746.ld new file mode 100644 index 000000000..1b92f2ba3 --- /dev/null +++ b/src/main/target/link/stm32_flash_f746.ld @@ -0,0 +1,28 @@ +/* +***************************************************************************** +** +** File : stm32_flash_f746.ld +** +** Abstract : Linker script for STM32F746VGTx Device with +** 1024KByte FLASH, 320KByte RAM +** +***************************************************************************** +*/ + +/* Entry Point */ +ENTRY(Reset_Handler) + +/* Specify the memory areas */ +MEMORY +{ + FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 768K + FLASH_CONFIG (r) : ORIGIN = 0x080C0000, LENGTH = 256K + + TCM (rwx) : ORIGIN = 0x20000000, LENGTH = 64K + RAM (rwx) : ORIGIN = 0x20010000, LENGTH = 256K + MEMORY_B1 (rx) : ORIGIN = 0x60000000, LENGTH = 0K +} +/* note CCM could be used for stack */ +REGION_ALIAS("STACKRAM", TCM) + +INCLUDE "stm32_flash.ld" diff --git a/src/main/telemetry/esc_telemetry.c b/src/main/telemetry/esc_telemetry.c deleted file mode 100644 index 0bde741ab..000000000 --- a/src/main/telemetry/esc_telemetry.c +++ /dev/null @@ -1,312 +0,0 @@ -#include -#include -#include - -#include - -#include "fc/config.h" -#include "config/feature.h" -#include "config/config_master.h" - -#include "common/utils.h" - -#include "drivers/system.h" -#include "drivers/serial.h" -#include "drivers/serial_uart.h" -#include "drivers/pwm_output.h" - -#include "io/serial.h" - -#include "flight/mixer.h" - -#include "sensors/battery.h" - -#include "esc_telemetry.h" - -#include "build/debug.h" - -/* -KISS ESC TELEMETRY PROTOCOL ---------------------------- - -One transmission will have 10 times 8-bit bytes sent with 115200 baud and 3.6V. - -Byte 0: Temperature -Byte 1: Voltage high byte -Byte 2: Voltage low byte -Byte 3: Current high byte -Byte 4: Current low byte -Byte 5: Consumption high byte -Byte 6: Consumption low byte -Byte 7: Rpm high byte -Byte 8: Rpm low byte -Byte 9: 8-bit CRC - -*/ - -/* -DEBUG INFORMATION ------------------ - -set debug_mode = DEBUG_ESC_TELEMETRY in cli - -0: current motor index requested -1: number of timeouts -2: voltage -3: current -*/ - -#ifdef USE_DSHOT - -typedef struct { - bool skipped; - int16_t temperature; - int16_t voltage; - int16_t current; - int16_t consumption; - int16_t rpm; -} esc_telemetry_t; - -typedef enum { - ESC_TLM_FRAME_PENDING = 1 << 0, // 1 - ESC_TLM_FRAME_COMPLETE = 1 << 1 // 2 -} escTlmFrameState_t; - -typedef enum { - ESC_TLM_TRIGGER_WAIT = 0, - ESC_TLM_TRIGGER_READY = 1 << 0, // 1 - ESC_TLM_TRIGGER_PENDING = 1 << 1 // 2 -} escTlmTriggerState_t; - -#define ESC_TLM_BAUDRATE 115200 -#define ESC_TLM_BUFFSIZE 10 -#define ESC_BOOTTIME 5000 // 5 seconds -#define ESC_REQUEST_TIMEOUT 100 // 100 ms (data transfer takes only 900us) - -static bool tlmFrameDone = false; -static uint8_t tlm[ESC_TLM_BUFFSIZE] = { 0, }; -static uint8_t tlmFramePosition = 0; -static serialPort_t *escTelemetryPort = NULL; -static esc_telemetry_t escTelemetryData[MAX_SUPPORTED_MOTORS]; -static uint32_t escTriggerTimestamp = -1; -static uint32_t escTriggerLastTimestamp = -1; -static uint8_t timeoutRetryCount = 0; - -static uint8_t escTelemetryMotor = 0; // motor index -static bool escTelemetryEnabled = false; -static escTlmTriggerState_t escTelemetryTriggerState = ESC_TLM_TRIGGER_WAIT; - -static int16_t escVbat = 0; -static int16_t escCurrent = 0; -static int16_t escConsumption = 0; - -static void escTelemetryDataReceive(uint16_t c); -static uint8_t update_crc8(uint8_t crc, uint8_t crc_seed); -static uint8_t get_crc8(uint8_t *Buf, uint8_t BufLen); -static void selectNextMotor(void); - -bool isEscTelemetryActive(void) -{ - return escTelemetryEnabled; -} - -int16_t getEscTelemetryVbat(void) -{ - return escVbat / 10; -} - -int16_t getEscTelemetryCurrent(void) -{ - return escCurrent; -} - -int16_t getEscTelemetryConsumption(void) -{ - return escConsumption; -} - -bool escTelemetryInit(void) -{ - serialPortConfig_t *portConfig = findSerialPortConfig(FUNCTION_TELEMETRY_ESC); - if (!portConfig) { - return false; - } - - portOptions_t options = (SERIAL_NOT_INVERTED); - - // Initialize serial port - escTelemetryPort = openSerialPort(portConfig->identifier, FUNCTION_TELEMETRY_ESC, escTelemetryDataReceive, ESC_TLM_BAUDRATE, MODE_RX, options); - - if (escTelemetryPort) { - escTelemetryEnabled = true; - batteryConfig()->currentMeterType = CURRENT_SENSOR_ESC; - batteryConfig()->batteryMeterType = BATTERY_SENSOR_ESC; - } - - return escTelemetryPort != NULL; -} - -void freeEscTelemetryPort(void) -{ - closeSerialPort(escTelemetryPort); - escTelemetryPort = NULL; - escTelemetryEnabled = false; -} - -// Receive ISR callback -static void escTelemetryDataReceive(uint16_t c) -{ - // KISS ESC sends some data during startup, ignore this for now (maybe future use) - // startup data could be firmware version and serialnumber - - if (escTelemetryTriggerState == ESC_TLM_TRIGGER_WAIT) return; - - tlm[tlmFramePosition] = (uint8_t)c; - - if (tlmFramePosition == ESC_TLM_BUFFSIZE - 1) { - tlmFrameDone = true; - tlmFramePosition = 0; - } else { - tlmFramePosition++; - } -} - -uint8_t escTelemetryFrameStatus(void) -{ - uint8_t frameStatus = ESC_TLM_FRAME_PENDING; - uint16_t chksum, tlmsum; - - if (!tlmFrameDone) { - return frameStatus; - } - - tlmFrameDone = false; - - // Get CRC8 checksum - chksum = get_crc8(tlm, ESC_TLM_BUFFSIZE - 1); - tlmsum = tlm[ESC_TLM_BUFFSIZE - 1]; // last byte contains CRC value - - if (chksum == tlmsum) { - escTelemetryData[escTelemetryMotor].skipped = false; - escTelemetryData[escTelemetryMotor].temperature = tlm[0]; - escTelemetryData[escTelemetryMotor].voltage = tlm[1] << 8 | tlm[2]; - escTelemetryData[escTelemetryMotor].current = tlm[3] << 8 | tlm[4]; - escTelemetryData[escTelemetryMotor].consumption = tlm[5] << 8 | tlm[6]; - escTelemetryData[escTelemetryMotor].rpm = tlm[7] << 8 | tlm[8]; - - frameStatus = ESC_TLM_FRAME_COMPLETE; - } - - return frameStatus; -} - -void escTelemetryProcess(timeUs_t currentTimeUs) -{ - const timeMs_t currentTimeMs = currentTimeUs / 1000; - - if (!escTelemetryEnabled) { - return; - } - - // Wait period of time before requesting telemetry (let the system boot first) - if (millis() < ESC_BOOTTIME) { - return; - } - else if (escTelemetryTriggerState == ESC_TLM_TRIGGER_WAIT) { - // Ready for starting requesting telemetry - escTelemetryTriggerState = ESC_TLM_TRIGGER_READY; - escTelemetryMotor = 0; - escTriggerTimestamp = currentTimeMs; - escTriggerLastTimestamp = escTriggerTimestamp; - } - else if (escTelemetryTriggerState == ESC_TLM_TRIGGER_READY) { - if (debugMode == DEBUG_ESC_TELEMETRY) debug[0] = escTelemetryMotor+1; - - motorDmaOutput_t * const motor = getMotorDmaOutput(escTelemetryMotor); - motor->requestTelemetry = true; - escTelemetryTriggerState = ESC_TLM_TRIGGER_PENDING; - } - - if (escTriggerTimestamp + ESC_REQUEST_TIMEOUT < currentTimeMs) { - // ESC did not repond in time, retry - timeoutRetryCount++; - escTriggerTimestamp = currentTimeMs; - escTelemetryTriggerState = ESC_TLM_TRIGGER_READY; - - if (timeoutRetryCount == 4) { - // Not responding after 3 times, skip motor - escTelemetryData[escTelemetryMotor].skipped = true; - selectNextMotor(); - } - - if (debugMode == DEBUG_ESC_TELEMETRY) debug[1]++; - } - - // Get received frame status - uint8_t state = escTelemetryFrameStatus(); - - if (state == ESC_TLM_FRAME_COMPLETE) { - // Wait until all ESCs are processed - if (escTelemetryMotor == getMotorCount()-1) { - escCurrent = 0; - escConsumption = 0; - escVbat = 0; - - for (int i = 0; i < getMotorCount(); i++) { - if (!escTelemetryData[i].skipped) { - escVbat = i > 0 ? ((escVbat + escTelemetryData[i].voltage) / 2) : escTelemetryData[i].voltage; - escCurrent = escCurrent + escTelemetryData[i].current; - escConsumption = escConsumption + escTelemetryData[i].consumption; - } - } - } - - if (debugMode == DEBUG_ESC_TELEMETRY) debug[2] = escVbat; - if (debugMode == DEBUG_ESC_TELEMETRY) debug[3] = escCurrent; - - selectNextMotor(); - escTelemetryTriggerState = ESC_TLM_TRIGGER_READY; - } - - if (escTriggerLastTimestamp + 10000 < currentTimeMs) { - // ESCs did not respond for 10 seconds - // Disable ESC telemetry and fallback to onboard vbat sensor - freeEscTelemetryPort(); - escVbat = 0; - escCurrent = 0; - escConsumption = 0; - } -} - -static void selectNextMotor(void) -{ - escTelemetryMotor++; - if (escTelemetryMotor == getMotorCount()) { - escTelemetryMotor = 0; - } - escTriggerTimestamp = millis(); - escTriggerLastTimestamp = escTriggerTimestamp; -} - -//-- CRC - -static uint8_t update_crc8(uint8_t crc, uint8_t crc_seed) -{ - uint8_t crc_u = crc; - crc_u ^= crc_seed; - - for (int i=0; i<8; i++) { - crc_u = ( crc_u & 0x80 ) ? 0x7 ^ ( crc_u << 1 ) : ( crc_u << 1 ); - } - - return (crc_u); -} - -static uint8_t get_crc8(uint8_t *Buf, uint8_t BufLen) -{ - uint8_t crc = 0; - for(int i=0; i 0) { + if ((feature(FEATURE_VBAT) || feature(FEATURE_ESC_SENSOR)) && batteryCellCount > 0) { sendVoltage(); sendVoltageAmp(); sendAmperage(); diff --git a/src/main/telemetry/smartport.c b/src/main/telemetry/smartport.c index 496013f14..4d1d19718 100644 --- a/src/main/telemetry/smartport.c +++ b/src/main/telemetry/smartport.c @@ -646,7 +646,7 @@ void handleSmartPortTelemetry(void) } break; case FSSP_DATAID_CURRENT : - if (feature(FEATURE_CURRENT_METER) || feature(FEATURE_ESC_TELEMETRY)) { + if (feature(FEATURE_CURRENT_METER) || feature(FEATURE_ESC_SENSOR)) { smartPortSendPackage(id, amperage / 10); // given in 10mA steps, unknown requested unit smartPortHasRequest = 0; } @@ -659,7 +659,7 @@ void handleSmartPortTelemetry(void) } break; case FSSP_DATAID_FUEL : - if (feature(FEATURE_CURRENT_METER) || feature(FEATURE_ESC_TELEMETRY)) { + if (feature(FEATURE_CURRENT_METER) || feature(FEATURE_ESC_SENSOR)) { smartPortSendPackage(id, mAhDrawn); // given in mAh, unknown requested unit smartPortHasRequest = 0; }