From 91d6a1cc8d5bbe225acff939ee0d354afe4f1090 Mon Sep 17 00:00:00 2001 From: Dominic Clifton Date: Tue, 19 Feb 2019 18:46:19 +0100 Subject: [PATCH] Move memory section initialisation earlier into the init sequence. Allows startup-code/libs/etc to be moved into different memory regions. --- src/main/drivers/system.c | 20 ++++++++++++++++++++ src/main/drivers/system.h | 2 ++ src/main/fc/init.c | 16 ---------------- src/main/startup/system_stm32f30x.c | 3 +++ src/main/startup/system_stm32f4xx.c | 3 +++ src/main/startup/system_stm32f7xx.c | 3 +++ 6 files changed, 31 insertions(+), 16 deletions(-) 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 1b78b59bf2..07fb97b76f 100644 --- a/src/main/fc/init.c +++ b/src/main/fc/init.c @@ -229,22 +229,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 36cfea6760..9bb5eb2236 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;