diff --git a/src/main/drivers/system.c b/src/main/drivers/system.c index e620687726..ac3bbc19db 100644 --- a/src/main/drivers/system.c +++ b/src/main/drivers/system.c @@ -20,6 +20,7 @@ #include #include +#include #include "platform.h" @@ -204,3 +205,22 @@ void failureMode(failureMode_e mode) systemResetToBootloader(); #endif } + +void initialiseMemorySections(void) +{ +#ifdef USE_ITCM_RAM + /* Load functions into ITCM RAM */ + extern uint8_t tcm_code_start; + extern uint8_t tcm_code_end; + extern uint8_t tcm_code; + memcpy(&tcm_code_start, &tcm_code, (size_t) (&tcm_code_end - &tcm_code_start)); +#endif + +#ifdef USE_FAST_RAM + /* Load FAST_RAM variable intializers into DTCM RAM */ + extern uint8_t _sfastram_data; + extern uint8_t _efastram_data; + extern uint8_t _sfastram_idata; + memcpy(&_sfastram_data, &_sfastram_idata, (size_t) (&_efastram_data - &_sfastram_data)); +#endif +} diff --git a/src/main/drivers/system.h b/src/main/drivers/system.h index 285aefdfb6..01c9eca595 100644 --- a/src/main/drivers/system.h +++ b/src/main/drivers/system.h @@ -52,6 +52,8 @@ void checkForBootLoaderRequest(void); bool isMPUSoftReset(void); void cycleCounterInit(void); +void initialiseMemorySections(void); + void enableGPIOPowerUsageAndNoiseReductions(void); // current crystal frequency - 8 or 12MHz diff --git a/src/main/fc/init.c b/src/main/fc/init.c index 156560d173..0dd3129e13 100644 --- a/src/main/fc/init.c +++ b/src/main/fc/init.c @@ -226,22 +226,6 @@ dispatchEntry_t activateDshotTelemetryEntry = void init(void) { -#ifdef USE_ITCM_RAM - /* Load functions into ITCM RAM */ - extern uint8_t tcm_code_start; - extern uint8_t tcm_code_end; - extern uint8_t tcm_code; - memcpy(&tcm_code_start, &tcm_code, (size_t) (&tcm_code_end - &tcm_code_start)); -#endif - -#ifdef USE_FAST_RAM - /* Load FAST_RAM variable intializers into DTCM RAM */ - extern uint8_t _sfastram_data; - extern uint8_t _efastram_data; - extern uint8_t _sfastram_idata; - memcpy(&_sfastram_data, &_sfastram_idata, (size_t) (&_efastram_data - &_sfastram_data)); -#endif - #ifdef USE_HAL_DRIVER HAL_Init(); #endif diff --git a/src/main/startup/system_stm32f30x.c b/src/main/startup/system_stm32f30x.c index 950daac7f2..b8a5b68906 100644 --- a/src/main/startup/system_stm32f30x.c +++ b/src/main/startup/system_stm32f30x.c @@ -102,6 +102,7 @@ #include "platform.h" #include "stm32f30x.h" +#include "drivers/system.h" uint32_t hse_value = HSE_VALUE; @@ -160,6 +161,8 @@ void SetSysClock(void); */ void SystemInit(void) { + initialiseMemorySections(); + /* FPU settings ------------------------------------------------------------*/ #if (__FPU_PRESENT == 1) && (__FPU_USED == 1) SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2)); /* set CP10 and CP11 Full Access */ diff --git a/src/main/startup/system_stm32f4xx.c b/src/main/startup/system_stm32f4xx.c index ed251b2fe6..e604a3b525 100644 --- a/src/main/startup/system_stm32f4xx.c +++ b/src/main/startup/system_stm32f4xx.c @@ -316,6 +316,7 @@ #include #include "stm32f4xx.h" +#include "drivers/system.h" #include "system_stm32f4xx.h" #include "platform.h" #include "drivers/persistent.h" @@ -506,6 +507,8 @@ void systemClockSetHSEValue(uint32_t frequency) void SystemInit(void) { + initialiseMemorySections(); + /* FPU settings ------------------------------------------------------------*/ #if (__FPU_PRESENT == 1) && (__FPU_USED == 1) SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2)); /* set CP10 and CP11 Full Access */ diff --git a/src/main/startup/system_stm32f7xx.c b/src/main/startup/system_stm32f7xx.c index 182b8a789c..2c080bde73 100644 --- a/src/main/startup/system_stm32f7xx.c +++ b/src/main/startup/system_stm32f7xx.c @@ -64,6 +64,7 @@ */ #include "stm32f7xx.h" +#include "drivers/system.h" #include "system_stm32f7xx.h" #include "platform.h" #include "drivers/persistent.h" @@ -308,6 +309,8 @@ void OverclockRebootIfNecessary(uint32_t overclockLevel) */ void SystemInit(void) { + initialiseMemorySections(); + SystemInitOC(); SystemCoreClock = (pll_n / pll_p) * 1000000;