From 376441f89fa40c3f36166f14c29228f261939f96 Mon Sep 17 00:00:00 2001 From: Dominic Clifton Date: Wed, 28 Aug 2019 14:41:21 +0200 Subject: [PATCH] F3 - Add support for code in CCM RAM. --- src/link/stm32_flash.ld | 13 +++++++++++++ src/main/drivers/system.c | 8 ++++++++ src/main/target/common_pre.h | 8 ++++++++ 3 files changed, 29 insertions(+) diff --git a/src/link/stm32_flash.ld b/src/link/stm32_flash.ld index 89d3e97f5..c88e3fc53 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 b36c1f799..0226a878c 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 5a662b0c8..60923be76 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)))