From 08f1f91c502f203ab6091a69bc6f340a1067854e Mon Sep 17 00:00:00 2001 From: jflyper Date: Thu, 26 Sep 2019 20:44:17 +0900 Subject: [PATCH] [G4] CLI and config changes for overclocking --- src/main/cli/cli.c | 4 ++-- src/main/cli/settings.c | 4 ++-- src/main/config/config.c | 2 +- src/main/config/config.h | 4 ++-- src/main/fc/init.c | 5 +++-- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main/cli/cli.c b/src/main/cli/cli.c index 375ce78acd..1a87b7b174 100644 --- a/src/main/cli/cli.c +++ b/src/main/cli/cli.c @@ -4673,8 +4673,8 @@ static void cliStatus(const char *cmdName, char *cmdline) cliPrintf("MCU %s Clock=%dMHz", getMcuTypeById(getMcuTypeId()), (SystemCoreClock / 1000000)); -#ifdef STM32F4 - // Only F4 is capable of switching between HSE/HSI (for now) +#if defined(STM32F4) || defined(STM32G4) + // Only F4 and G4 is capable of switching between HSE/HSI (for now) int sysclkSource = SystemSYSCLKSource(); const char *SYSCLKSource[] = { "HSI", "HSE", "PLLP", "PLLR" }; diff --git a/src/main/cli/settings.c b/src/main/cli/settings.c index b1020c8eb4..0092f6d2f7 100644 --- a/src/main/cli/settings.c +++ b/src/main/cli/settings.c @@ -351,7 +351,7 @@ static const char * const lookupTableRatesType[] = { #ifdef USE_OVERCLOCK static const char * const lookupOverclock[] = { "OFF", -#if defined(STM32F40_41xxx) +#if defined(STM32F40_41xxx) || defined(STM32G4) "192MHZ", "216MHZ", "240MHZ" #elif defined(STM32F411xE) "108MHZ", "120MHZ" @@ -1429,7 +1429,7 @@ const clivalue_t valueTable[] = { #endif // end of #ifdef USE_OSD // PG_SYSTEM_CONFIG -#if defined(STM32F4) +#if defined(STM32F4) || defined(STM32G4) { "system_hse_mhz", VAR_UINT8 | HARDWARE_VALUE, .config.minmaxUnsigned = { 0, 30 }, PG_SYSTEM_CONFIG, offsetof(systemConfig_t, hseMhz) }, #endif #if defined(USE_TASK_STATISTICS) diff --git a/src/main/config/config.c b/src/main/config/config.c index 388cf5cca1..e3c75ac270 100644 --- a/src/main/config/config.c +++ b/src/main/config/config.c @@ -126,7 +126,7 @@ PG_RESET_TEMPLATE(systemConfig_t, systemConfig, .cpu_overclock = DEFAULT_CPU_OVERCLOCK, .powerOnArmingGraceTime = 5, .boardIdentifier = TARGET_BOARD_IDENTIFIER, - .hseMhz = SYSTEM_HSE_VALUE, // Not used for non-F4 targets + .hseMhz = SYSTEM_HSE_VALUE, // Only used for F4 and G4 targets .configurationState = CONFIGURATION_STATE_DEFAULTS_BARE, .schedulerOptimizeRate = SCHEDULER_OPTIMIZE_RATE_AUTO, .enableStickArming = false, diff --git a/src/main/config/config.h b/src/main/config/config.h index 7c94486ff7..49b2d04bf5 100644 --- a/src/main/config/config.h +++ b/src/main/config/config.h @@ -55,8 +55,8 @@ typedef struct systemConfig_s { uint8_t cpu_overclock; uint8_t powerOnArmingGraceTime; // in seconds char boardIdentifier[sizeof(TARGET_BOARD_IDENTIFIER) + 1]; - uint8_t hseMhz; // Not used for non-F4 targets - uint8_t configurationState; // The state of the configuration (defaults / configured) + uint8_t hseMhz; // Only used for F4 and G4 targets + uint8_t configurationState; // The state of the configuration (defaults / configured) uint8_t schedulerOptimizeRate; uint8_t enableStickArming; // boolean that determines whether stick arming can be used } systemConfig_t; diff --git a/src/main/fc/init.c b/src/main/fc/init.c index 1363b66a04..2b2684fd9f 100644 --- a/src/main/fc/init.c +++ b/src/main/fc/init.c @@ -529,8 +529,9 @@ void init(void) } #endif -#ifdef STM32F4 - // Only F4 has non-8MHz boards +#if defined(STM32F4) || defined(STM32G4) + // F4 has non-8MHz boards + // G4 for Betaflight allow 24 or 27MHz oscillator systemClockSetHSEValue(systemConfig()->hseMhz * 1000000U); #endif