diff --git a/docs/Cli.md b/docs/Cli.md index 62f75cc2ad..7b5105da21 100644 --- a/docs/Cli.md +++ b/docs/Cli.md @@ -105,6 +105,7 @@ Re-apply any new defaults as desired. |---------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------|--------|---------------|--------------|----------| | `looptime` | This is the main loop time (in us). Changing this affects PID effect with some PID controllers (see PID section for details). Default of 3500us/285Hz should work for everyone. Setting it to zero does not limit loop time, so it will go as fast as possible. | 0 | 9000 | 3500 | Master | UINT16 | | `emf_avoidance` | Default value is 0 for 72MHz processor speed. Setting this to 1 increases the processor speed, to move the 6th harmonic away from 432MHz. | 0 | 1 | 0 | Master | UINT8 | +| `i2c_overclock` | Default value is 0 for disabled. Enabling this feature speeds up IMU speed significantly and faster looptimes are possible. | 0 | 1 | 0 | Master | UINT8 | | `mid_rc` | This is an important number to set in order to avoid trimming receiver/transmitter. Most standard receivers will have this at 1500, however Futaba transmitters will need this set to 1520. A way to find out if this needs to be changed, is to clear all trim/subtrim on transmitter, and connect to GUI. Note the value most channels idle at - this should be the number to choose. Once midrc is set, use subtrim on transmitter to make sure all channels (except throttle of course) are centered at midrc value. | 1200 | 1700 | 1500 | Master | UINT16 | | `min_check` | These are min/max values (in us) which, when a channel is smaller (min) or larger (max) than the value will activate various RC commands, such as arming, or stick configuration. Normally, every RC channel should be set so that min = 1000us, max = 2000us. On most transmitters this usually means 125% endpoints. Default check values are 100us above/below this value. | 0 | 2000 | 1100 | Master | UINT16 | | `max_check` | These are min/max values (in us) which, when a channel is smaller (min) or larger (max) than the value will activate various RC commands, such as arming, or stick configuration. Normally, every RC channel should be set so that min = 1000us, max = 2000us. On most transmitters this usually means 125% endpoints. Default check values are 100us above/below this value. | 0 | 2000 | 1900 | Master | UINT16 | diff --git a/src/main/config/config.c b/src/main/config/config.c index c88c60fb0e..f3387c1d15 100755 --- a/src/main/config/config.c +++ b/src/main/config/config.c @@ -132,7 +132,7 @@ static uint32_t activeFeaturesLatch = 0; static uint8_t currentControlRateProfileIndex = 0; controlRateConfig_t *currentControlRateProfile; -static const uint8_t EEPROM_CONF_VERSION = 106; +static const uint8_t EEPROM_CONF_VERSION = 107; static void resetAccelerometerTrims(flightDynamicsTrims_t *accelerometerTrims) { @@ -476,6 +476,7 @@ static void resetConf(void) masterConfig.looptime = 3500; masterConfig.emf_avoidance = 0; + masterConfig.i2c_overclock = 0; resetPidProfile(¤tProfile->pidProfile); diff --git a/src/main/config/config_master.h b/src/main/config/config_master.h index 71b29f22f4..b7836fef1f 100644 --- a/src/main/config/config_master.h +++ b/src/main/config/config_master.h @@ -27,6 +27,7 @@ typedef struct master_t { uint32_t enabledFeatures; uint16_t looptime; // imu loop time in us uint8_t emf_avoidance; // change pll settings to avoid noise in the uhf band + uint8_t i2c_overclock; // Overclock i2c Bus for faster IMU readings motorMixer_t customMotorMixer[MAX_SUPPORTED_MOTORS]; #ifdef USE_SERVOS diff --git a/src/main/drivers/bus_i2c.h b/src/main/drivers/bus_i2c.h index 39db2094ec..68d1a52fc4 100644 --- a/src/main/drivers/bus_i2c.h +++ b/src/main/drivers/bus_i2c.h @@ -28,3 +28,4 @@ bool i2cWriteBuffer(uint8_t addr_, uint8_t reg_, uint8_t len_, uint8_t *data); bool i2cWrite(uint8_t addr_, uint8_t reg, uint8_t data); bool i2cRead(uint8_t addr_, uint8_t reg, uint8_t len, uint8_t* buf); uint16_t i2cGetErrorCounter(void); +void i2cSetOverclock(uint8_t OverClock); diff --git a/src/main/drivers/bus_i2c_stm32f10x.c b/src/main/drivers/bus_i2c_stm32f10x.c index 38fde8e45c..591843c528 100644 --- a/src/main/drivers/bus_i2c_stm32f10x.c +++ b/src/main/drivers/bus_i2c_stm32f10x.c @@ -61,6 +61,11 @@ static const i2cDevice_t i2cHardwareMap[] = { static I2C_TypeDef *I2Cx = NULL; // Copy of device index for reinit, etc purposes static I2CDevice I2Cx_index; +static bool i2cOverClock; + +void i2cSetOverclock(uint8_t OverClock) { + i2cOverClock = (OverClock) ? true : false; +} void I2C1_ER_IRQHandler(void) { @@ -340,7 +345,13 @@ void i2cInit(I2CDevice index) i2c.I2C_Mode = I2C_Mode_I2C; i2c.I2C_DutyCycle = I2C_DutyCycle_2; i2c.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; - i2c.I2C_ClockSpeed = 400000; + + if (i2cOverClock) { + i2c.I2C_ClockSpeed = 800000; // 800khz Maximum speed tested on various boards without issues + } else { + i2c.I2C_ClockSpeed = 400000; // 400khz Operation according specs + } + I2C_Cmd(I2Cx, ENABLE); I2C_Init(I2Cx, &i2c); diff --git a/src/main/drivers/bus_i2c_stm32f30x.c b/src/main/drivers/bus_i2c_stm32f30x.c index 80141ac636..9bd089d46d 100644 --- a/src/main/drivers/bus_i2c_stm32f30x.c +++ b/src/main/drivers/bus_i2c_stm32f30x.c @@ -69,6 +69,12 @@ static I2C_TypeDef *I2Cx = NULL; // I2C TimeoutUserCallback /////////////////////////////////////////////////////////////////////////////// +static bool i2cOverClock; + +void i2cSetOverclock(uint8_t OverClock) { + i2cOverClock = (OverClock) ? true : false; +} + uint32_t i2cTimeoutUserCallback(I2C_TypeDef *I2Cx) { if (I2Cx == I2C1) { @@ -118,7 +124,11 @@ void i2cInitPort(I2C_TypeDef *I2Cx) I2C_InitStructure.I2C_OwnAddress1 = 0x00; I2C_InitStructure.I2C_Ack = I2C_Ack_Enable; I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; - I2C_InitStructure.I2C_Timing = 0x00E0257A; // 400 Khz, 72Mhz Clock, Analog Filter Delay ON, Rise 100, Fall 10. + if (i2cOverClock) { + I2C_InitStructure.I2C_Timing = 0x00500E30; // 1000 Khz, 72Mhz Clock, Analog Filter Delay ON, Setup 40, Hold 4. + } else { + I2C_InitStructure.I2C_Timing = 0x00E0257A; // 400 Khz, 72Mhz Clock, Analog Filter Delay ON, Rise 100, Fall 10 + } //I2C_InitStructure.I2C_Timing = 0x8000050B; I2C_Init(I2C1, &I2C_InitStructure); @@ -165,7 +175,11 @@ void i2cInitPort(I2C_TypeDef *I2Cx) // ^ when using this setting and after a few seconds of a scope probe being attached to the I2C bus it was observed that the bus enters // a busy state and does not recover. - I2C_InitStructure.I2C_Timing = 0x00E0257A; // 400 Khz, 72Mhz Clock, Analog Filter Delay ON, Rise 100, Fall 10. + if (i2cOverClock) { + I2C_InitStructure.I2C_Timing = 0x00500E30; // 1000 Khz, 72Mhz Clock, Analog Filter Delay ON, Setup 40, Hold 4. + } else { + I2C_InitStructure.I2C_Timing = 0x00E0257A; // 400 Khz, 72Mhz Clock, Analog Filter Delay ON, Rise 100, Fall 10 + } //I2C_InitStructure.I2C_Timing = 0x8000050B; diff --git a/src/main/io/serial_cli.c b/src/main/io/serial_cli.c index c3458a930b..430c357bf3 100644 --- a/src/main/io/serial_cli.c +++ b/src/main/io/serial_cli.c @@ -325,6 +325,7 @@ typedef struct { const clivalue_t valueTable[] = { { "looptime", VAR_UINT16 | MASTER_VALUE, &masterConfig.looptime, 0, 9000 }, { "emf_avoidance", VAR_UINT8 | MASTER_VALUE, &masterConfig.emf_avoidance, 0, 1 }, + { "i2c_overclock", VAR_UINT8 | MASTER_VALUE, &masterConfig.i2c_overclock, 0, 1 }, { "mid_rc", VAR_UINT16 | MASTER_VALUE, &masterConfig.rxConfig.midrc, 1200, 1700 }, { "min_check", VAR_UINT16 | MASTER_VALUE, &masterConfig.rxConfig.mincheck, PWM_RANGE_ZERO, PWM_RANGE_MAX }, diff --git a/src/main/main.c b/src/main/main.c index 36c9d7c090..49c5b32288 100644 --- a/src/main/main.c +++ b/src/main/main.c @@ -169,6 +169,7 @@ void init(void) // Configure the Flash Latency cycles and enable prefetch buffer SetSysClock(masterConfig.emf_avoidance); #endif + i2cSetOverclock(masterConfig.i2c_overclock); #ifdef USE_HARDWARE_REVISION_DETECTION detectHardwareRevision();