diff --git a/libraries/AP_Generator/AP_Generator.cpp b/libraries/AP_Generator/AP_Generator.cpp
index f1906bdc8f..7cac48cf78 100644
--- a/libraries/AP_Generator/AP_Generator.cpp
+++ b/libraries/AP_Generator/AP_Generator.cpp
@@ -13,6 +13,8 @@
along with this program. If not, see .
*/
+#pragma GCC optimize("Os")
+
#include "AP_Generator.h"
#if HAL_GENERATOR_ENABLED
diff --git a/libraries/AP_Generator/AP_Generator_Backend.cpp b/libraries/AP_Generator/AP_Generator_Backend.cpp
index 6a74ee53e2..c3405ceec0 100644
--- a/libraries/AP_Generator/AP_Generator_Backend.cpp
+++ b/libraries/AP_Generator/AP_Generator_Backend.cpp
@@ -12,6 +12,8 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
+#pragma GCC optimize("Os")
+
#include "AP_Generator_Backend.h"
#if HAL_GENERATOR_ENABLED
diff --git a/libraries/AP_Generator/AP_Generator_IE_2400.cpp b/libraries/AP_Generator/AP_Generator_IE_2400.cpp
index 26f2bf35b6..7c0a5f05e4 100644
--- a/libraries/AP_Generator/AP_Generator_IE_2400.cpp
+++ b/libraries/AP_Generator/AP_Generator_IE_2400.cpp
@@ -13,6 +13,8 @@
along with this program. If not, see .
*/
+#pragma GCC optimize("Os")
+
#include "AP_Generator_IE_2400.h"
#if AP_GENERATOR_IE_2400_ENABLED
diff --git a/libraries/AP_Generator/AP_Generator_IE_650_800.cpp b/libraries/AP_Generator/AP_Generator_IE_650_800.cpp
index c0e9aae3a2..c1a78e8a6f 100644
--- a/libraries/AP_Generator/AP_Generator_IE_650_800.cpp
+++ b/libraries/AP_Generator/AP_Generator_IE_650_800.cpp
@@ -13,6 +13,8 @@
along with this program. If not, see .
*/
+#pragma GCC optimize("Os")
+
#include "AP_Generator_IE_650_800.h"
#if AP_GENERATOR_IE_650_800_ENABLED
diff --git a/libraries/AP_Generator/AP_Generator_IE_FuelCell.cpp b/libraries/AP_Generator/AP_Generator_IE_FuelCell.cpp
index 7a13bed22e..4af0f8cbd8 100644
--- a/libraries/AP_Generator/AP_Generator_IE_FuelCell.cpp
+++ b/libraries/AP_Generator/AP_Generator_IE_FuelCell.cpp
@@ -13,6 +13,8 @@
along with this program. If not, see .
*/
+#pragma GCC optimize("Os")
+
#include "AP_Generator_IE_FuelCell.h"
#if AP_GENERATOR_IE_ENABLED
diff --git a/libraries/AP_Generator/AP_Generator_RichenPower.cpp b/libraries/AP_Generator/AP_Generator_RichenPower.cpp
index 21750784e5..d5e0337c5f 100644
--- a/libraries/AP_Generator/AP_Generator_RichenPower.cpp
+++ b/libraries/AP_Generator/AP_Generator_RichenPower.cpp
@@ -13,6 +13,8 @@
along with this program. If not, see .
*/
+#pragma GCC optimize("Os")
+
#include "AP_Generator_config.h"
#if AP_GENERATOR_RICHENPOWER_ENABLED