diff --git a/src/link/stm32_flash.ld b/src/link/stm32_flash.ld index 89d3e97f52..c88e3fc53a 100644 --- a/src/link/stm32_flash.ld +++ b/src/link/stm32_flash.ld @@ -53,6 +53,19 @@ SECTIONS _etext = .; /* define a global symbols at end of code */ } >FLASH + /* Critical program code goes into CCM RAM */ + /* Copy specific fast-executing code to CCM RAM */ + ccm_code = LOADADDR(.ccm_code); + .ccm_code : + { + . = ALIGN(4); + ccm_code_start = .; + *(.ccm_code) + *(.ccm_code*) + . = ALIGN(4); + ccm_code_end = .; + } >CCM AT >FLASH + .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH .ARM : { diff --git a/src/main/drivers/system.c b/src/main/drivers/system.c index b36c1f7990..0226a878c5 100644 --- a/src/main/drivers/system.c +++ b/src/main/drivers/system.c @@ -253,6 +253,14 @@ void initialiseMemorySections(void) memcpy(&tcm_code_start, &tcm_code, (size_t) (&tcm_code_end - &tcm_code_start)); #endif +#ifdef USE_CCM_CODE + /* Load functions into RAM */ + extern uint8_t ccm_code_start; + extern uint8_t ccm_code_end; + extern uint8_t ccm_code; + memcpy(&ccm_code_start, &ccm_code, (size_t) (&ccm_code_end - &ccm_code_start)); +#endif + #ifdef USE_FAST_RAM /* Load FAST_RAM variable intializers into DTCM RAM */ extern uint8_t _sfastram_data; diff --git a/src/main/target/common_pre.h b/src/main/target/common_pre.h index 5a662b0c8a..60923be76d 100644 --- a/src/main/target/common_pre.h +++ b/src/main/target/common_pre.h @@ -44,6 +44,7 @@ #define MINIMAL_CLI #define USE_DSHOT #define USE_GYRO_DATA_ANALYSE +#define USE_CCM_CODE #endif #ifdef STM32F4 @@ -133,6 +134,7 @@ #define DEFAULT_AUX_CHANNEL_COUNT 6 #endif + #ifdef USE_ITCM_RAM #define FAST_CODE __attribute__((section(".tcm_code"))) #define FAST_CODE_NOINLINE NOINLINE @@ -141,6 +143,12 @@ #define FAST_CODE_NOINLINE #endif // USE_ITCM_RAM +#ifdef USE_CCM_CODE +#define CCM_CODE __attribute__((section(".ccm_code"))) +#else +#define CCM_CODE +#endif + #ifdef USE_FAST_RAM #define FAST_RAM_ZERO_INIT __attribute__ ((section(".fastram_bss"), aligned(4))) #define FAST_RAM __attribute__ ((section(".fastram_data"), aligned(4)))