From f18448e8dc04428cfcdff02a5fe3f9b29dbaa245 Mon Sep 17 00:00:00 2001 From: Andrey Mironov Date: Sat, 21 Apr 2018 16:04:07 +0300 Subject: [PATCH] Added FAST_RAM_INITIALIZED (#5733) * Added FAST_RAM_INITIALIZED for those who really want it * Added the white crow of KISSFCV2F7 * Made initialized data LMAs robust * Fixed indirection when initializing fast memory --- src/main/fc/fc_init.c | 16 ++++++++++++---- src/main/flight/pid.c | 2 +- .../KISSFCV2F7/stm32_flash_f722_no_split.ld | 17 ++++++++++++++++- src/main/target/common_fc_pre.h | 4 +++- src/main/target/link/stm32_flash_f7_split.ld | 17 ++++++++++++++++- src/main/target/link/stm32_flash_split.ld | 18 +++++++++++++++++- 6 files changed, 65 insertions(+), 9 deletions(-) diff --git a/src/main/fc/fc_init.c b/src/main/fc/fc_init.c index 94e3554e26..2147681235 100644 --- a/src/main/fc/fc_init.c +++ b/src/main/fc/fc_init.c @@ -265,10 +265,18 @@ void init(void) { #ifdef USE_ITCM_RAM /* Load functions into ITCM RAM */ - extern unsigned char tcm_code_start; - extern unsigned char tcm_code_end; - extern unsigned char tcm_code; - memcpy(&tcm_code_start, &tcm_code, (int)(&tcm_code_end - &tcm_code_start)); + 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_INITIALIZED variable intializers into FAST 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 diff --git a/src/main/flight/pid.c b/src/main/flight/pid.c index f312ca6dab..c54e7b2478 100644 --- a/src/main/flight/pid.c +++ b/src/main/flight/pid.c @@ -158,7 +158,7 @@ void pidResetITerm(void) } } -static FAST_RAM float itermAccelerator = 1.0f; +static FAST_RAM_INITIALIZED float itermAccelerator = 1.0f; void pidSetItermAccelerator(float newItermAccelerator) { diff --git a/src/main/target/KISSFCV2F7/stm32_flash_f722_no_split.ld b/src/main/target/KISSFCV2F7/stm32_flash_f722_no_split.ld index 9ab1a6bae9..14fefb0fd5 100644 --- a/src/main/target/KISSFCV2F7/stm32_flash_f722_no_split.ld +++ b/src/main/target/KISSFCV2F7/stm32_flash_f722_no_split.ld @@ -136,7 +136,7 @@ SECTIONS } >FLASH /* used by the startup to initialize data */ - _sidata = .; + _sidata = LOADADDR(.data); /* Initialized data sections goes into RAM, load LMA copy after code */ .data : @@ -182,6 +182,21 @@ SECTIONS __sram2_end__ = _esram2; } >SRAM2 + /* used during startup to initialized fastram_data */ + _sfastram_idata = LOADADDR(.fastram_data); + + /* Initialized FAST_RAM section for unsuspecting developers */ + .fastram_data : + { + . = ALIGN(4); + _sfastram_data = .; /* create a global symbol at data start */ + *(.fastram_data) /* .data sections */ + *(.fastram_data*) /* .data* sections */ + + . = ALIGN(4); + _efastram_data = .; /* define a global symbol at data end */ + } >FASTRAM AT> FLASH + . = ALIGN(4); .fastram_bss (NOLOAD) : { diff --git a/src/main/target/common_fc_pre.h b/src/main/target/common_fc_pre.h index 89d441d542..69e3021022 100644 --- a/src/main/target/common_fc_pre.h +++ b/src/main/target/common_fc_pre.h @@ -92,15 +92,17 @@ #endif #ifdef USE_ITCM_RAM -#define FAST_CODE __attribute__((section(".tcm_code"))) +#define FAST_CODE __attribute__((section(".tcm_code"))) #else #define FAST_CODE #endif // USE_ITCM_RAM #ifdef USE_FAST_RAM #define FAST_RAM __attribute__ ((section(".fastram_bss"), aligned(4))) +#define FAST_RAM_INITIALIZED __attribute__ ((section(".fastram_data"), aligned(4))) #else #define FAST_RAM +#define FAST_RAM_INITIALIZED #endif // USE_FAST_RAM #ifdef STM32F4 diff --git a/src/main/target/link/stm32_flash_f7_split.ld b/src/main/target/link/stm32_flash_f7_split.ld index 03a4b97f69..a649a51323 100644 --- a/src/main/target/link/stm32_flash_f7_split.ld +++ b/src/main/target/link/stm32_flash_f7_split.ld @@ -93,7 +93,7 @@ SECTIONS } >FLASH AT >AXIM_FLASH /* used by the startup to initialize data */ - _sidata = .; + _sidata = LOADADDR(.data); /* Initialized data sections goes into RAM, load LMA copy after code */ .data : @@ -139,6 +139,21 @@ SECTIONS __sram2_end__ = _esram2; } >SRAM2 + /* used during startup to initialized fastram_data */ + _sfastram_idata = LOADADDR(.fastram_data); + + /* Initialized FAST_RAM section for unsuspecting developers */ + .fastram_data : + { + . = ALIGN(4); + _sfastram_data = .; /* create a global symbol at data start */ + *(.fastram_data) /* .data sections */ + *(.fastram_data*) /* .data* sections */ + + . = ALIGN(4); + _efastram_data = .; /* define a global symbol at data end */ + } >FASTRAM AT> FLASH + . = ALIGN(4); .fastram_bss (NOLOAD) : { diff --git a/src/main/target/link/stm32_flash_split.ld b/src/main/target/link/stm32_flash_split.ld index 2e86c747b9..304f041d80 100644 --- a/src/main/target/link/stm32_flash_split.ld +++ b/src/main/target/link/stm32_flash_split.ld @@ -106,7 +106,7 @@ SECTIONS } >FLASH /* used by the startup to initialize data */ - _sidata = .; + _sidata = LOADADDR(.data); /* Initialized data sections goes into RAM, load LMA copy after code */ .data : @@ -136,6 +136,22 @@ SECTIONS __bss_end__ = _ebss; } >RAM + /* used during startup to initialized fastram_data */ + _sfastram_idata = LOADADDR(.fastram_data); + + /* Initialized FAST_RAM section for unsuspecting developers */ + .fastram_data : + { + . = ALIGN(4); + _sfastram_data = .; /* create a global symbol at data start */ + *(.fastram_data) /* .data sections */ + *(.fastram_data*) /* .data* sections */ + + . = ALIGN(4); + _efastram_data = .; /* define a global symbol at data end */ + } >FASTRAM AT> FLASH + + . = ALIGN(4); .fastram_bss (NOLOAD) : { __fastram_bss_start__ = .;