From 1187c575ed3a26c9bfa3b3731b15bb8d61fe38b7 Mon Sep 17 00:00:00 2001
From: borisbstyle <dreambb1982@gmail.com>
Date: Tue, 8 Mar 2016 22:46:54 +0100
Subject: [PATCH 01/10] Gyro Calibration scaled to looptime setting

---
 src/main/io/rc_controls.c | 3 ++-
 src/main/main.c           | 2 +-
 src/main/sensors/gyro.c   | 6 +++---
 3 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/src/main/io/rc_controls.c b/src/main/io/rc_controls.c
index c89c50bef..2a66bb19a 100644
--- a/src/main/io/rc_controls.c
+++ b/src/main/io/rc_controls.c
@@ -34,6 +34,7 @@
 #include "drivers/system.h"
 #include "drivers/sensor.h"
 #include "drivers/accgyro.h"
+#include "drivers/gyro_sync.h"
 
 #include "sensors/barometer.h"
 #include "sensors/battery.h"
@@ -215,7 +216,7 @@ void processRcStickPositions(rxConfig_t *rxConfig, throttleStatus_e throttleStat
 
     if (rcSticks == THR_LO + YAW_LO + PIT_LO + ROL_CE) {
         // GYRO calibration
-        gyroSetCalibrationCycles(CALIBRATING_GYRO_CYCLES);
+        gyroSetCalibrationCycles((CALIBRATING_GYRO_CYCLES / targetLooptime) * CALIBRATING_GYRO_CYCLES);
 
 #ifdef GPS
         if (feature(FEATURE_GPS)) {
diff --git a/src/main/main.c b/src/main/main.c
index d856a36ea..e0c80f93b 100644
--- a/src/main/main.c
+++ b/src/main/main.c
@@ -598,7 +598,7 @@ void init(void)
     if (masterConfig.mixerMode == MIXER_GIMBAL) {
         accSetCalibrationCycles(CALIBRATING_ACC_CYCLES);
     }
-    gyroSetCalibrationCycles(CALIBRATING_GYRO_CYCLES);
+    gyroSetCalibrationCycles((CALIBRATING_GYRO_CYCLES / targetLooptime) * CALIBRATING_GYRO_CYCLES);
 #ifdef BARO
     baroSetCalibrationCycles(CALIBRATING_BARO_CYCLES);
 #endif
diff --git a/src/main/sensors/gyro.c b/src/main/sensors/gyro.c
index 5fe75d281..824969413 100644
--- a/src/main/sensors/gyro.c
+++ b/src/main/sensors/gyro.c
@@ -79,7 +79,7 @@ bool isOnFinalGyroCalibrationCycle(void)
 
 bool isOnFirstGyroCalibrationCycle(void)
 {
-    return calibratingG == CALIBRATING_GYRO_CYCLES;
+    return calibratingG == (CALIBRATING_GYRO_CYCLES / targetLooptime) * CALIBRATING_GYRO_CYCLES;
 }
 
 static void performAcclerationCalibration(uint8_t gyroMovementCalibrationThreshold)
@@ -108,10 +108,10 @@ static void performAcclerationCalibration(uint8_t gyroMovementCalibrationThresho
             float dev = devStandardDeviation(&var[axis]);
             // check deviation and startover in case the model was moved
             if (gyroMovementCalibrationThreshold && dev > gyroMovementCalibrationThreshold) {
-                gyroSetCalibrationCycles(CALIBRATING_GYRO_CYCLES);
+                gyroSetCalibrationCycles((CALIBRATING_GYRO_CYCLES / targetLooptime) * CALIBRATING_GYRO_CYCLES);
                 return;
             }
-            gyroZero[axis] = (g[axis] + (CALIBRATING_GYRO_CYCLES / 2)) / CALIBRATING_GYRO_CYCLES;
+            gyroZero[axis] = (g[axis] + ((CALIBRATING_GYRO_CYCLES / targetLooptime) * CALIBRATING_GYRO_CYCLES / 2)) / (CALIBRATING_GYRO_CYCLES / targetLooptime) * CALIBRATING_GYRO_CYCLES;
         }
     }
 

From 21bc85335e47b401facc9b76140d530c8680df1f Mon Sep 17 00:00:00 2001
From: borisbstyle <dreambb1982@gmail.com>
Date: Wed, 9 Mar 2016 00:05:13 +0100
Subject: [PATCH 02/10] pidUpdateCountdown set based on condition

---
 src/main/mw.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/main/mw.c b/src/main/mw.c
index 70396af39..d9ad9453b 100644
--- a/src/main/mw.c
+++ b/src/main/mw.c
@@ -741,6 +741,14 @@ void taskMotorUpdate(void) {
     }
 }
 
+uint8_t setPidUpdateCountDown(void) {
+    if (masterConfig.gyro_soft_lpf_hz) {
+	    return masterConfig.pid_process_denom - 1;
+    } else {
+        return 1;
+    }
+}
+
 // Check for oneshot125 protection. With fast looptimes oneshot125 pulse duration gets more near the pid looptime
 bool shouldUpdateMotorsAfterPIDLoop(void) {
     if (targetPidLooptime > 375 ) {
@@ -782,7 +790,7 @@ void taskMainPidLoopCheck(void) {
             if (pidUpdateCountdown) {
                 pidUpdateCountdown--;
             } else {
-                pidUpdateCountdown = masterConfig.pid_process_denom - 1;
+                pidUpdateCountdown = setPidUpdateCountDown();
                 taskMainPidLoop();
                 if (shouldUpdateMotorsAfterPIDLoop()) taskMotorUpdate();
                 runTaskMainSubprocesses = true;

From 03cc5fa4388ef21670e818b688e37aef90865723 Mon Sep 17 00:00:00 2001
From: borisbstyle <dreambb1982@gmail.com>
Date: Wed, 9 Mar 2016 22:31:16 +0100
Subject: [PATCH 03/10] Function for calculating calibration cycles

---
 src/main/io/rc_controls.c |  2 +-
 src/main/main.c           |  2 +-
 src/main/sensors/gyro.c   | 10 +++++++---
 src/main/sensors/gyro.h   |  1 +
 4 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/src/main/io/rc_controls.c b/src/main/io/rc_controls.c
index 2a66bb19a..03a108d6f 100644
--- a/src/main/io/rc_controls.c
+++ b/src/main/io/rc_controls.c
@@ -216,7 +216,7 @@ void processRcStickPositions(rxConfig_t *rxConfig, throttleStatus_e throttleStat
 
     if (rcSticks == THR_LO + YAW_LO + PIT_LO + ROL_CE) {
         // GYRO calibration
-        gyroSetCalibrationCycles((CALIBRATING_GYRO_CYCLES / targetLooptime) * CALIBRATING_GYRO_CYCLES);
+        gyroSetCalibrationCycles(calculateCalibratingCycles());
 
 #ifdef GPS
         if (feature(FEATURE_GPS)) {
diff --git a/src/main/main.c b/src/main/main.c
index e0c80f93b..f75dc570e 100644
--- a/src/main/main.c
+++ b/src/main/main.c
@@ -598,7 +598,7 @@ void init(void)
     if (masterConfig.mixerMode == MIXER_GIMBAL) {
         accSetCalibrationCycles(CALIBRATING_ACC_CYCLES);
     }
-    gyroSetCalibrationCycles((CALIBRATING_GYRO_CYCLES / targetLooptime) * CALIBRATING_GYRO_CYCLES);
+    gyroSetCalibrationCycles(calculateCalibratingCycles());
 #ifdef BARO
     baroSetCalibrationCycles(CALIBRATING_BARO_CYCLES);
 #endif
diff --git a/src/main/sensors/gyro.c b/src/main/sensors/gyro.c
index 824969413..de3412760 100644
--- a/src/main/sensors/gyro.c
+++ b/src/main/sensors/gyro.c
@@ -77,9 +77,13 @@ bool isOnFinalGyroCalibrationCycle(void)
     return calibratingG == 1;
 }
 
+uint16_t calculateCalibratingCycles(void) {
+    return (CALIBRATING_GYRO_CYCLES / targetLooptime) * CALIBRATING_GYRO_CYCLES;
+}
+
 bool isOnFirstGyroCalibrationCycle(void)
 {
-    return calibratingG == (CALIBRATING_GYRO_CYCLES / targetLooptime) * CALIBRATING_GYRO_CYCLES;
+    return calibratingG == calculateCalibratingCycles();
 }
 
 static void performAcclerationCalibration(uint8_t gyroMovementCalibrationThreshold)
@@ -108,10 +112,10 @@ static void performAcclerationCalibration(uint8_t gyroMovementCalibrationThresho
             float dev = devStandardDeviation(&var[axis]);
             // check deviation and startover in case the model was moved
             if (gyroMovementCalibrationThreshold && dev > gyroMovementCalibrationThreshold) {
-                gyroSetCalibrationCycles((CALIBRATING_GYRO_CYCLES / targetLooptime) * CALIBRATING_GYRO_CYCLES);
+                gyroSetCalibrationCycles(calculateCalibratingCycles());
                 return;
             }
-            gyroZero[axis] = (g[axis] + ((CALIBRATING_GYRO_CYCLES / targetLooptime) * CALIBRATING_GYRO_CYCLES / 2)) / (CALIBRATING_GYRO_CYCLES / targetLooptime) * CALIBRATING_GYRO_CYCLES;
+            gyroZero[axis] = (g[axis] + (calculateCalibratingCycles() / 2)) / calculateCalibratingCycles();
         }
     }
 
diff --git a/src/main/sensors/gyro.h b/src/main/sensors/gyro.h
index bb7a152f0..48e5e677e 100644
--- a/src/main/sensors/gyro.h
+++ b/src/main/sensors/gyro.h
@@ -43,4 +43,5 @@ void useGyroConfig(gyroConfig_t *gyroConfigToUse, float gyro_lpf_hz);
 void gyroSetCalibrationCycles(uint16_t calibrationCyclesRequired);
 void gyroUpdate(void);
 bool isGyroCalibrationComplete(void);
+uint16_t calculateCalibratingCycles(void);
 

From fa63ab52e148cd8cb03053085e638ddd0a492632 Mon Sep 17 00:00:00 2001
From: borisbstyle <dreambb1982@gmail.com>
Date: Thu, 10 Mar 2016 00:27:44 +0100
Subject: [PATCH 04/10] Disabling of 3D Feature on switch

---
 .testThrottle.c.swp       | Bin 0 -> 1024 bytes
 src/main/flight/mixer.c   |  10 +++++-----
 src/main/io/rc_controls.h |   3 ++-
 src/main/io/rc_curves.c   |   5 ++++-
 src/main/io/serial_msp.c  |   3 ++-
 src/main/mw.c             |  14 ++++++++++++--
 src/main/version.h        |   2 +-
 7 files changed, 26 insertions(+), 11 deletions(-)
 create mode 100644 .testThrottle.c.swp

diff --git a/.testThrottle.c.swp b/.testThrottle.c.swp
new file mode 100644
index 0000000000000000000000000000000000000000..d53eb7fc58a9e35a883bcc6a29354427711bf836
GIT binary patch
literal 1024
zcmYc?$V<%2S1{5u(KBK|0ylIR7?SdfGK-PKa4}0#i*hsb5=-)n%*@PiDFTY?=ccA)
zChCKY)ptoONz_kCElbVGFUU>JE74C%ElEtv$xP2E(Jx6YE(ysf$}cI&N!3fnW8$dP
PXb6mk00|)wimny_;r1ZO

literal 0
HcmV?d00001

diff --git a/src/main/flight/mixer.c b/src/main/flight/mixer.c
index 29c0ac41b..f61c068ee 100755
--- a/src/main/flight/mixer.c
+++ b/src/main/flight/mixer.c
@@ -822,18 +822,18 @@ void mixTable(void)
     int16_t throttleMin, throttleMax;
     static int16_t throttlePrevious = 0;   // Store the last throttle direction for deadband transitions
 
-    // Find min and max throttle based on condition. Use rcData for 3D to prevent loss of power due to min_check
+    // Find min and max throttle based on condition.
     if (feature(FEATURE_3D)) {
         if (!ARMING_FLAG(ARMED)) throttlePrevious = rxConfig->midrc; // When disarmed set to mid_rc. It always results in positive direction after arming.
 
-        if ((rcData[THROTTLE] <= (rxConfig->midrc - flight3DConfig->deadband3d_throttle))) { // Out of band handling
+        if ((rcCommand[THROTTLE] <= (rxConfig->midrc - flight3DConfig->deadband3d_throttle))) { // Out of band handling
             throttleMax = flight3DConfig->deadband3d_low;
             throttleMin = escAndServoConfig->minthrottle;
-            throttlePrevious = throttle = rcData[THROTTLE];
-        } else if (rcData[THROTTLE] >= (rxConfig->midrc + flight3DConfig->deadband3d_throttle)) { // Positive handling
+            throttlePrevious = throttle = rcCommand[THROTTLE];
+        } else if (rcCommand[THROTTLE] >= (rxConfig->midrc + flight3DConfig->deadband3d_throttle)) { // Positive handling
             throttleMax = escAndServoConfig->maxthrottle;
             throttleMin = flight3DConfig->deadband3d_high;
-            throttlePrevious = throttle = rcData[THROTTLE];
+            throttlePrevious = throttle = rcCommand[THROTTLE];
         } else if ((throttlePrevious <= (rxConfig->midrc - flight3DConfig->deadband3d_throttle)))  { // Deadband handling from negative to positive
             throttle = throttleMax = flight3DConfig->deadband3d_low;
             throttleMin = escAndServoConfig->minthrottle;
diff --git a/src/main/io/rc_controls.h b/src/main/io/rc_controls.h
index 8cdc3c775..c512ed64b 100644
--- a/src/main/io/rc_controls.h
+++ b/src/main/io/rc_controls.h
@@ -49,7 +49,8 @@ typedef enum {
     BOXBLACKBOX,
     BOXFAILSAFE,
     BOXAIRMODE,
-	BOXACROPLUS,
+    BOXACROPLUS,
+    BOX3DDISABLESWITCH,
     CHECKBOX_ITEM_COUNT
 } boxId_e;
 
diff --git a/src/main/io/rc_curves.c b/src/main/io/rc_curves.c
index 80b0bd4aa..e6abf1d86 100644
--- a/src/main/io/rc_curves.c
+++ b/src/main/io/rc_curves.c
@@ -24,6 +24,8 @@
 
 #include "io/rc_curves.h"
 
+#include "config/config.h"
+
 int16_t lookupPitchRollRC[PITCH_LOOKUP_LENGTH];     // lookup table for expo & RC rate PITCH+ROLL
 int16_t lookupYawRC[YAW_LOOKUP_LENGTH];     // lookup table for expo & RC rate YAW
 int16_t lookupThrottleRC[THROTTLE_LOOKUP_LENGTH];   // lookup table for expo & mid THROTTLE
@@ -48,6 +50,7 @@ void generateYawCurve(controlRateConfig_t *controlRateConfig)
 void generateThrottleCurve(controlRateConfig_t *controlRateConfig, escAndServoConfig_t *escAndServoConfig)
 {
     uint8_t i;
+    uint16_t minThrottle = (feature(FEATURE_3D && IS_RC_MODE_ACTIVE(BOX3DDISABLESWITCH)) ? PWM_RANGE_MIN : escAndServoConfig->minthrottle);
 
     for (i = 0; i < THROTTLE_LOOKUP_LENGTH; i++) {
         int16_t tmp = 10 * i - controlRateConfig->thrMid8;
@@ -57,6 +60,6 @@ void generateThrottleCurve(controlRateConfig_t *controlRateConfig, escAndServoCo
         if (tmp < 0)
             y = controlRateConfig->thrMid8;
         lookupThrottleRC[i] = 10 * controlRateConfig->thrMid8 + tmp * (100 - controlRateConfig->thrExpo8 + (int32_t) controlRateConfig->thrExpo8 * (tmp * tmp) / (y * y)) / 10;
-        lookupThrottleRC[i] = escAndServoConfig->minthrottle + (int32_t) (escAndServoConfig->maxthrottle - escAndServoConfig->minthrottle) * lookupThrottleRC[i] / 1000; // [MINTHROTTLE;MAXTHROTTLE]
+        lookupThrottleRC[i] = minThrottle + (int32_t) (escAndServoConfig->maxthrottle - minThrottle) * lookupThrottleRC[i] / 1000; // [MINTHROTTLE;MAXTHROTTLE]
     }
 }
diff --git a/src/main/io/serial_msp.c b/src/main/io/serial_msp.c
index 122f2e77b..a2a09fabf 100644
--- a/src/main/io/serial_msp.c
+++ b/src/main/io/serial_msp.c
@@ -217,6 +217,7 @@ static const box_t boxes[CHECKBOX_ITEM_COUNT + 1] = {
     { BOXFAILSAFE, "FAILSAFE;", 27 },
     { BOXAIRMODE, "AIR MODE;", 28 },
     { BOXACROPLUS, "ACRO PLUS;", 29 },
+    { BOX3DDISABLESWITCH, "DISABLE 3D SWITCH;", 30},
     { CHECKBOX_ITEM_COUNT, NULL, 0xFF }
 };
 
@@ -544,7 +545,7 @@ void mspInit(serialConfig_t *serialConfig)
 
     activeBoxIds[activeBoxIdCount++] = BOXAIRMODE;
     activeBoxIds[activeBoxIdCount++] = BOXACROPLUS;
-
+    activeBoxIds[activeBoxIdCount++] = BOX3DDISABLESWITCH;
 
     if (sensors(SENSOR_BARO)) {
         activeBoxIds[activeBoxIdCount++] = BOXBARO;
diff --git a/src/main/mw.c b/src/main/mw.c
index d9ad9453b..2c8dad31a 100644
--- a/src/main/mw.c
+++ b/src/main/mw.c
@@ -270,11 +270,21 @@ void annexCode(void)
             rcCommand[axis] = -rcCommand[axis];
     }
 
-    tmp = constrain(rcData[THROTTLE], masterConfig.rxConfig.mincheck, PWM_RANGE_MAX);
-    tmp = (uint32_t)(tmp - masterConfig.rxConfig.mincheck) * PWM_RANGE_MIN / (PWM_RANGE_MAX - masterConfig.rxConfig.mincheck);
+    if (feature(FEATURE_3D)) {
+        tmp = constrain(rcData[THROTTLE], PWM_RANGE_MIN, PWM_RANGE_MAX);
+        tmp = (uint32_t)(tmp - PWM_RANGE_MIN);
+    } else {
+        tmp = constrain(rcData[THROTTLE], masterConfig.rxConfig.mincheck, PWM_RANGE_MAX);
+        tmp = (uint32_t)(tmp - masterConfig.rxConfig.mincheck) * PWM_RANGE_MIN / (PWM_RANGE_MAX - masterConfig.rxConfig.mincheck);
+    }
     tmp2 = tmp / 100;
     rcCommand[THROTTLE] = lookupThrottleRC[tmp2] + (tmp - tmp2 * 100) * (lookupThrottleRC[tmp2 + 1] - lookupThrottleRC[tmp2]) / 100;    // [0;1000] -> expo -> [MINTHROTTLE;MAXTHROTTLE]
 
+    if (IS_RC_MODE_ACTIVE(BOX3DDISABLESWITCH) && !failsafeIsActive()) {
+        fix12_t throttleScaler = qConstruct(rcCommand[THROTTLE] - 1000, 1000);
+        rcCommand[THROTTLE] = masterConfig.rxConfig.midrc + qMultiply(throttleScaler, PWM_RANGE_MAX - masterConfig.rxConfig.midrc);
+    }
+
     if (FLIGHT_MODE(HEADFREE_MODE)) {
         float radDiff = degreesToRadians(DECIDEGREES_TO_DEGREES(attitude.values.yaw) - headFreeModeHold);
         float cosDiff = cos_approx(radDiff);
diff --git a/src/main/version.h b/src/main/version.h
index f2581c2ec..65e7dc436 100644
--- a/src/main/version.h
+++ b/src/main/version.h
@@ -17,7 +17,7 @@
 
 #define FC_VERSION_MAJOR            2  // increment when a major release is made (big new feature, etc)
 #define FC_VERSION_MINOR            5  // increment when a minor release is made (small new feature, change etc)
-#define FC_VERSION_PATCH_LEVEL      3  // increment when a bug is fixed
+#define FC_VERSION_PATCH_LEVEL      4  // increment when a bug is fixed
 
 #define STR_HELPER(x) #x
 #define STR(x) STR_HELPER(x)

From 1e8f2bacb871dac9630698f3641b71301d838bab Mon Sep 17 00:00:00 2001
From: borisbstyle <dreambb1982@gmail.com>
Date: Thu, 10 Mar 2016 00:35:19 +0100
Subject: [PATCH 05/10] Oops only 3D Mode needs this

---
 src/main/mw.c       | 2 +-
 testThrottle.c.save | 5 +++++
 2 files changed, 6 insertions(+), 1 deletion(-)
 create mode 100644 testThrottle.c.save

diff --git a/src/main/mw.c b/src/main/mw.c
index 2c8dad31a..d8e2f3082 100644
--- a/src/main/mw.c
+++ b/src/main/mw.c
@@ -280,7 +280,7 @@ void annexCode(void)
     tmp2 = tmp / 100;
     rcCommand[THROTTLE] = lookupThrottleRC[tmp2] + (tmp - tmp2 * 100) * (lookupThrottleRC[tmp2 + 1] - lookupThrottleRC[tmp2]) / 100;    // [0;1000] -> expo -> [MINTHROTTLE;MAXTHROTTLE]
 
-    if (IS_RC_MODE_ACTIVE(BOX3DDISABLESWITCH) && !failsafeIsActive()) {
+    if (feature(FEATURE_3D) && IS_RC_MODE_ACTIVE(BOX3DDISABLESWITCH) && !failsafeIsActive()) {
         fix12_t throttleScaler = qConstruct(rcCommand[THROTTLE] - 1000, 1000);
         rcCommand[THROTTLE] = masterConfig.rxConfig.midrc + qMultiply(throttleScaler, PWM_RANGE_MAX - masterConfig.rxConfig.midrc);
     }
diff --git a/testThrottle.c.save b/testThrottle.c.save
new file mode 100644
index 000000000..51cab990b
--- /dev/null
+++ b/testThrottle.c.save
@@ -0,0 +1,5 @@
+#include "stdint.h"
+#include "stdio.h"
+
+
+int main()

From e9731ea5e62430321e77998d7432898c62fb9bc1 Mon Sep 17 00:00:00 2001
From: Brian Balogh <bbalogh@users.noreply.github.com>
Date: Thu, 10 Mar 2016 15:42:32 -0500
Subject: [PATCH 06/10] Cleanup temp files and add them to .gitignore

---
 .gitignore          |   2 ++
 .testThrottle.c.swp | Bin 1024 -> 0 bytes
 testThrottle.c.save |   5 -----
 3 files changed, 2 insertions(+), 5 deletions(-)
 delete mode 100644 .testThrottle.c.swp
 delete mode 100644 testThrottle.c.save

diff --git a/.gitignore b/.gitignore
index 34dd269dd..245d33be9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,6 +5,8 @@
 *.dep
 *.bak
 *.uvgui.*
+*.swp
+*.save
 .project
 .settings
 .cproject
diff --git a/.testThrottle.c.swp b/.testThrottle.c.swp
deleted file mode 100644
index d53eb7fc58a9e35a883bcc6a29354427711bf836..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001

literal 1024
zcmYc?$V<%2S1{5u(KBK|0ylIR7?SdfGK-PKa4}0#i*hsb5=-)n%*@PiDFTY?=ccA)
zChCKY)ptoONz_kCElbVGFUU>JE74C%ElEtv$xP2E(Jx6YE(ysf$}cI&N!3fnW8$dP
PXb6mk00|)wimny_;r1ZO

diff --git a/testThrottle.c.save b/testThrottle.c.save
deleted file mode 100644
index 51cab990b..000000000
--- a/testThrottle.c.save
+++ /dev/null
@@ -1,5 +0,0 @@
-#include "stdint.h"
-#include "stdio.h"
-
-
-int main()

From 3df01ac21d4951544285933f5935804aaa7dee10 Mon Sep 17 00:00:00 2001
From: KiteAnton <anton.stalheim@gmail.com>
Date: Sat, 12 Mar 2016 09:01:26 +0100
Subject: [PATCH 07/10] Output all profiles and rateprofiles in cli dump

---
 src/main/io/serial_cli.c | 68 +++++++++++++++++++++++++---------------
 1 file changed, 43 insertions(+), 25 deletions(-)

diff --git a/src/main/io/serial_cli.c b/src/main/io/serial_cli.c
index 6595b1f0f..58e704e97 100644
--- a/src/main/io/serial_cli.c
+++ b/src/main/io/serial_cli.c
@@ -109,6 +109,8 @@ static void cliAdjustmentRange(char *cmdline);
 static void cliMotorMix(char *cmdline);
 static void cliDefaults(char *cmdline);
 static void cliDump(char *cmdLine);
+void cliDumpProfile(uint8_t profileIndex);
+void cliDumpRateProfile(uint8_t rateProfileIndex) ;
 static void cliExit(char *cmdline);
 static void cliFeature(char *cmdline);
 static void cliMotor(char *cmdline);
@@ -1789,8 +1791,6 @@ typedef enum {
     DUMP_RATES = (1 << 2),
 } dumpFlags_e;
 
-#define DUMP_ALL (DUMP_MASTER | DUMP_PROFILE | DUMP_RATES)
-
 
 static const char* const sectionBreak = "\r\n";
 
@@ -1806,7 +1806,7 @@ static void cliDump(char *cmdline)
     float thr, roll, pitch, yaw;
 #endif
 
-    uint8_t dumpMask = DUMP_ALL;
+    uint8_t dumpMask = DUMP_MASTER;
     if (strcasecmp(cmdline, "master") == 0) {
         dumpMask = DUMP_MASTER; // only
     }
@@ -1958,38 +1958,56 @@ static void cliDump(char *cmdline)
 
         cliPrint("\r\n# rxfail\r\n");
         cliRxFail("");
+        
+        uint8_t activeProfile = masterConfig.current_profile_index;
+        uint8_t i;
+        for (i=0; i<MAX_PROFILE_COUNT;i++) 
+            cliDumpProfile(i);
+        
+        changeProfile(activeProfile);
+        
     }
 
     if (dumpMask & DUMP_PROFILE) {
-        cliPrint("\r\n# dump profile\r\n");
+        cliDumpProfile(masterConfig.current_profile_index);
+
+    }
+    if (dumpMask & DUMP_RATES) {				
+        cliDumpRateProfile(currentProfile->activeRateProfile);
+ }
+    
+}
 
+void cliDumpProfile(uint8_t profileIndex) {
+        if (profileIndex >= MAX_PROFILE_COUNT) // Faulty values
+            return;
+        
+        changeProfile(profileIndex);
         cliPrint("\r\n# profile\r\n");
         cliProfile("");
-
         printSectionBreak();
-
         dumpValues(PROFILE_VALUE);
-
-        cliPrint("\r\n# rateprofile\r\n");		
-        cliRateProfile("");		
-
-        printSectionBreak();		
-
-        dumpValues(PROFILE_RATE_VALUE);
-    }
-    if (dumpMask & DUMP_RATES) {		
-        cliPrint("\r\n# dump rates\r\n");		
-
-        cliPrint("\r\n# rateprofile\r\n");		
-        cliRateProfile("");		
-
-        printSectionBreak();		
- 
-        dumpValues(PROFILE_RATE_VALUE);
- }
-    
+        uint8_t currentRateIndex = currentProfile->activeRateProfile;
+        uint8_t i;
+        for (i=0; i<MAX_RATEPROFILES; i++)
+            cliDumpRateProfile(i);
+        
+        changeControlRateProfile(currentRateIndex);
+        cliPrintf("\r\n# Active rateprofile for profile %d, \r\n", profileIndex);	// output rateprofile again to mark "active rateprofile" 
+        cliRateProfile("");
 }
+void cliDumpRateProfile(uint8_t rateProfileIndex) {
+    if (rateProfileIndex >= MAX_RATEPROFILES) // Faulty values
+            return;
+    
+    changeControlRateProfile(rateProfileIndex);
+    cliPrint("\r\n# rateprofile\r\n");		
+    cliRateProfile("");		
+    printSectionBreak();		
 
+    dumpValues(PROFILE_RATE_VALUE);
+            
+}
 void cliEnter(serialPort_t *serialPort)
 {
     cliMode = 1;

From ee57ba387a24848958ae4895e74503a0ae3cbf59 Mon Sep 17 00:00:00 2001
From: KiteAnton <anton.stalheim@gmail.com>
Date: Sat, 12 Mar 2016 10:30:26 +0100
Subject: [PATCH 08/10] Fix beeper dump output bug

---
 src/main/io/serial_cli.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/main/io/serial_cli.c b/src/main/io/serial_cli.c
index 58e704e97..bc0275874 100644
--- a/src/main/io/serial_cli.c
+++ b/src/main/io/serial_cli.c
@@ -1901,7 +1901,7 @@ static void cliDump(char *cmdline)
             if (mask & (1 << i))
                 cliPrintf("beeper -%s\r\n", beeperNameForTableIndex(i));
             else
-                cliPrintf("beeper  %s\r\n", beeperNameForTableIndex(i));
+                cliPrintf("beeper %s\r\n", beeperNameForTableIndex(i));
         }
 #endif
 

From 3fa671e47995d6b78032be15a720c497dfa44e28 Mon Sep 17 00:00:00 2001
From: blckmn <blackman@xtra.com.au>
Date: Wed, 16 Mar 2016 07:31:16 +1100
Subject: [PATCH 09/10] Adjusted pulse MHZ for onshot back to 12

---
 src/main/drivers/light_ws2811strip_stm32f30x.c | 1 -
 src/main/drivers/pwm_mapping.h                 | 2 +-
 src/main/drivers/pwm_output.c                  | 8 +++-----
 src/main/drivers/timer.h                       | 7 +++++++
 src/main/io/serial_msp.c                       | 3 +--
 5 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/src/main/drivers/light_ws2811strip_stm32f30x.c b/src/main/drivers/light_ws2811strip_stm32f30x.c
index 853f81b81..1685dcb1f 100644
--- a/src/main/drivers/light_ws2811strip_stm32f30x.c
+++ b/src/main/drivers/light_ws2811strip_stm32f30x.c
@@ -39,7 +39,6 @@
 #define WS2811_IRQ                      DMA1_Channel3_IRQn
 #define WS2811_DMA_TC_FLAG              DMA1_FLAG_TC3
 #define WS2811_DMA_HANDLER_IDENTIFER    DMA1_CH3_HANDLER
-
 #endif
 
 void ws2811DMAHandler(DMA_Channel_TypeDef *channel) {
diff --git a/src/main/drivers/pwm_mapping.h b/src/main/drivers/pwm_mapping.h
index ab6b58893..fade65b1c 100644
--- a/src/main/drivers/pwm_mapping.h
+++ b/src/main/drivers/pwm_mapping.h
@@ -36,8 +36,8 @@
 #define MAX_INPUTS  8
 
 #define PWM_TIMER_MHZ 1
-#define ONESHOT_TIMER_MHZ 24
 //these three have to be the same because of the ppmAvoidPWMTimerClash functions
+#define ONESHOT_TIMER_MHZ 12
 #define MULTISHOT_TIMER_MHZ 12
 #define PWM_BRUSHED_TIMER_MHZ 12
 
diff --git a/src/main/drivers/pwm_output.c b/src/main/drivers/pwm_output.c
index 6f95ef59a..ba1ec28cf 100644
--- a/src/main/drivers/pwm_output.c
+++ b/src/main/drivers/pwm_output.c
@@ -28,7 +28,6 @@
 #include "flight/failsafe.h" // FIXME dependency into the main code from a driver
 
 #include "pwm_mapping.h"
-
 #include "pwm_output.h"
 
 typedef void (*pwmWriteFuncPtr)(uint8_t index, uint16_t value);  // function pointer used to write motors
@@ -99,7 +98,6 @@ static pwmOutputPort_t *pwmOutConfig(const timerHardware_t *timerHardware, uint8
     configTimeBase(timerHardware->tim, period, mhz);
     pwmGPIOConfig(timerHardware->gpio, timerHardware->pin, Mode_AF_PP);
 
-
     pwmOCConfig(timerHardware->tim, timerHardware->channel, value);
     if (timerHardware->outputEnable)
         TIM_CtrlPWMOutputs(timerHardware->tim, ENABLE);
@@ -134,6 +132,7 @@ static void pwmWriteStandard(uint8_t index, uint16_t value)
 {
     *motors[index]->ccr = value;
 }
+
 #if defined(STM32F10X) && !defined(CC3D)
 static void pwmWriteOneshot125(uint8_t index, uint16_t value)
 {
@@ -147,7 +146,7 @@ static void pwmWriteOneshot42(uint8_t index, uint16_t value)
 #else
 static void pwmWriteOneshot125(uint8_t index, uint16_t value)
 {
-    *motors[index]->ccr = value * 3;  // 24Mhz -> 8Mhz
+    *motors[index]->ccr = value * 3;
 }
 
 static void pwmWriteOneshot42(uint8_t index, uint16_t value)
@@ -158,7 +157,7 @@ static void pwmWriteOneshot42(uint8_t index, uint16_t value)
 
 static void pwmWriteMultiShot(uint8_t index, uint16_t value)
 {
-    *motors[index]->ccr = (uint16_t)((float)(value-1000) / 4.1666f)+ 60;
+    *motors[index]->ccr = (uint16_t)((float)(value-1000) / 4.1666f) + 60;
 }
 
 void pwmWriteMotor(uint8_t index, uint16_t value)
@@ -235,7 +234,6 @@ void pwmOneshotMotorConfig(const timerHardware_t *timerHardware, uint8_t motorIn
     } else {
         motors[motorIndex]->pwmWritePtr = pwmWriteOneshot125;
     }
-
 }
 
 void pwmMultiShotPwmRateMotorConfig(const timerHardware_t *timerHardware, uint8_t motorIndex, uint16_t motorPwmRate, uint16_t idlePulse)
diff --git a/src/main/drivers/timer.h b/src/main/drivers/timer.h
index 14c937155..31aed125b 100644
--- a/src/main/drivers/timer.h
+++ b/src/main/drivers/timer.h
@@ -17,6 +17,13 @@
 
 #pragma once
 
+#include <stdbool.h>
+#include <stdint.h>
+
+#include "platform.h"
+#include "gpio.h"
+#include "system.h"
+
 #if !defined(USABLE_TIMER_CHANNEL_COUNT)
 #define USABLE_TIMER_CHANNEL_COUNT 14
 #endif
diff --git a/src/main/io/serial_msp.c b/src/main/io/serial_msp.c
index 3f35b3f84..11113add3 100644
--- a/src/main/io/serial_msp.c
+++ b/src/main/io/serial_msp.c
@@ -671,8 +671,7 @@ static uint32_t packFlightModeFlags(void)
         IS_ENABLED(IS_RC_MODE_ACTIVE(BOXAIRMODE)) << BOXAIRMODE|
         IS_ENABLED(IS_RC_MODE_ACTIVE(BOXACROPLUS)) << BOXACROPLUS|
 		IS_ENABLED(IS_RC_MODE_ACTIVE(BOXALWAYSSTABILIZED)) << BOXALWAYSSTABILIZED|
-       	IS_ENABLED(IS_RC_MODE_ACTIVE(BOXTEST1)) << BOXTEST1|
-        IS_ENABLED(IS_RC_MODE_ACTIVE(BOXTEST2)) << BOXTEST2;
+       	IS_ENABLED(IS_RC_MODE_ACTIVE(BOXTEST1)) << BOXTEST1;
 
     for (i = 0; i < activeBoxIdCount; i++) {
         int flag = (tmp & (1 << activeBoxIds[i]));

From 1afa103250ba451ae0d182efa98271f5ae925019 Mon Sep 17 00:00:00 2001
From: blckmn <blackman@xtra.com.au>
Date: Thu, 17 Mar 2016 18:52:14 +1100
Subject: [PATCH 10/10] set motor_pwm_rate at 2600 by default, and use_pwm_rate
 feature on for F4s.

---
 src/main/config/config.c      | 11 ++++++++++-
 src/main/target/NAZE/target.h |  6 +++---
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/main/config/config.c b/src/main/config/config.c
index e18f3dba8..db8a7425d 100755
--- a/src/main/config/config.c
+++ b/src/main/config/config.c
@@ -75,7 +75,12 @@
 #include "config/config_master.h"
 
 #define BRUSHED_MOTORS_PWM_RATE 16000
+#ifdef STM32F4
+#define BRUSHLESS_MOTORS_PWM_RATE 2600
+#else
 #define BRUSHLESS_MOTORS_PWM_RATE 400
+#endif // STM32F4
+
 
 void useRcControlsConfig(modeActivationCondition_t *modeActivationConditions, escAndServoConfig_t *escAndServoConfigToUse, pidProfile_t *pidProfileToUse);
 
@@ -200,7 +205,7 @@ void resetPidProfile(pidProfile_t *pidProfile)
     pidProfile->dterm_lpf_hz = 0;    // filtering ON by default
     pidProfile->deltaMethod = DELTA_FROM_MEASUREMENT;
 
-#if defined(STM32F411xE) || defined(STM32F40_41xxx)
+#if defined(STM32F4)
     pidProfile->dterm_lpf_hz = 60;   // filtering ON by default
     pidProfile->P_f[ROLL] = 5.012f;     // new PID for raceflight. test carefully
     pidProfile->I_f[ROLL] = 1.021f;
@@ -451,6 +456,10 @@ static void resetConf(void)
     featureSet(FEATURE_FAILSAFE);
     featureSet(FEATURE_ONESHOT125);
     featureSet(FEATURE_SBUS_INVERTER);
+    
+#ifdef STM32F4
+    featureSet(FEATURE_USE_PWM_RATE);
+#endif
 
     // global settings
     masterConfig.current_profile_index = 0;     // default profile
diff --git a/src/main/target/NAZE/target.h b/src/main/target/NAZE/target.h
index 32255ac6b..4b3a7b816 100644
--- a/src/main/target/NAZE/target.h
+++ b/src/main/target/NAZE/target.h
@@ -149,9 +149,9 @@
 
 
 #define LED_STRIP
-#define LED_STRIP_TIMER TIM3
-#define WS2811_DMA_TC_FLAG           DMA1_FLAG_TC6
-#define WS2811_DMA_HANDLER_IDENTIFER DMA1_CH6_HANDLER
+#define LED_STRIP_TIMER                 TIM3
+#define WS2811_DMA_TC_FLAG              DMA1_FLAG_TC6
+#define WS2811_DMA_HANDLER_IDENTIFER    DMA1_CH6_HANDLER
 
 //#define GPS
 //#define GTUNE