1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-12 19:10:32 +03:00

REFACTOR: Moving code sections to platform (#14509)

* REFACTOR: Moving code sections to platform

* Correct build error (FAST_CODE_PREF redefined)

* Re-ordered

* Updated comment (as per @ledvinap)
This commit is contained in:
Jay Blackman 2025-07-08 09:14:34 +10:00 committed by GitHub
parent cbf070af8f
commit 4985d315d5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 85 additions and 57 deletions

View file

@ -49,41 +49,45 @@
#define DEFAULT_AUX_CHANNEL_COUNT 6
#endif
#ifdef USE_ITCM_RAM
#if defined(ITCM_RAM_OPTIMISATION) && !defined(DEBUG)
#define FAST_CODE __attribute__((section(".tcm_code"))) __attribute__((optimize(ITCM_RAM_OPTIMISATION)))
#else
#define FAST_CODE __attribute__((section(".tcm_code")))
#endif
#ifndef FAST_CODE_PREF
#define FAST_CODE_PREF FAST_CODE
// If a particular target is short of ITCM RAM, defining FAST_CODE_PREF in the target.h file will
// cause functions decorated FAST_CODE_PREF to *not* go into ITCM RAM
// but if FAST_CODE_PREF is not defined for the target, FAST_CODE_PREF is an alias to FAST_CODE, and
// functions decorated with FAST_CODE_PREF *will* go into ITCM RAM.
#endif
#define FAST_CODE_NOINLINE NOINLINE
#else
#ifndef FAST_CODE
#define FAST_CODE
#define FAST_CODE_PREF
#define FAST_CODE_NOINLINE
#endif // USE_ITCM_RAM
#endif
#ifdef USE_CCM_CODE
#define CCM_CODE __attribute__((section(".ccm_code")))
#else
#ifndef FAST_CODE_PREF
#define FAST_CODE_PREF FAST_CODE
#endif
#ifndef FAST_CODE_NOINLINE
#define FAST_CODE_NOINLINE
#endif
#ifndef CCM_CODE
#define CCM_CODE
#endif
#ifdef USE_FAST_DATA
#define FAST_DATA_ZERO_INIT __attribute__ ((section(".fastram_bss"), aligned(4)))
#define FAST_DATA __attribute__ ((section(".fastram_data"), aligned(4)))
#else
#define FAST_DATA_ZERO_INIT
#ifndef FAST_DATA
#define FAST_DATA
#endif // USE_FAST_DATA
#endif
#ifndef FAST_DATA_ZERO_INIT
#define FAST_DATA_ZERO_INIT
#endif
#ifndef MMFLASH_CODE
#define MMFLASH_CODE
#endif
#ifndef MMFLASH_CODE_NOINLINE
#define MMFLASH_CODE_NOINLINE
#endif
#ifndef MMFLASH_DATA
#define MMFLASH_DATA
#endif
#ifndef MMFLASH_DATA_ZERO_INIT
#define MMFLASH_DATA_ZERO_INIT
#endif
/*
BEGIN HARDWARE INCLUSIONS
@ -630,33 +634,6 @@ extern struct linker_symbol __config_start; // configured via linker script wh
extern struct linker_symbol __config_end;
#endif
#if defined(USE_EXST) && !defined(RAMBASED)
#define USE_FLASH_BOOT_LOADER
#endif
#if defined(USE_FLASH_MEMORY_MAPPED)
#if !defined(USE_RAM_CODE)
#define USE_RAM_CODE
#endif
#define MMFLASH_CODE RAM_CODE
#define MMFLASH_CODE_NOINLINE RAM_CODE NOINLINE
#define MMFLASH_DATA FAST_DATA
#define MMFLASH_DATA_ZERO_INIT FAST_DATA_ZERO_INIT
#else
#define MMFLASH_CODE
#define MMFLASH_CODE_NOINLINE
#define MMFLASH_DATA
#define MMFLASH_DATA_ZERO_INIT
#endif
#ifdef USE_RAM_CODE
// RAM_CODE for methods that need to be in RAM, but don't need to be in the fastest type of memory.
// Note: if code is marked as RAM_CODE it *MUST* be in RAM, there is no alternative unlike functions marked with FAST_CODE/CCM_CODE
#define RAM_CODE __attribute__((section(".ram_code")))
#endif
#ifndef USE_ITERM_RELAX
#undef USE_ABSOLUTE_CONTROL
#endif

View file

@ -212,3 +212,8 @@
#define DMA_STCH_STRING "Stream"
#endif
#ifdef USE_FAST_DATA
#define FAST_DATA_ZERO_INIT __attribute__ ((section(".fastram_bss"), aligned(4)))
#define FAST_DATA __attribute__ ((section(".fastram_data"), aligned(4)))
#endif // USE_FAST_DATA

View file

@ -471,3 +471,49 @@ extern uint8_t _dmaram_end__;
#if defined(STM32F4) || defined(STM32F7) || defined(STM32H7)
#define DMA_STCH_STRING "Stream"
#endif
#ifdef USE_ITCM_RAM
#if defined(ITCM_RAM_OPTIMISATION) && !defined(DEBUG)
#define FAST_CODE __attribute__((section(".tcm_code"))) __attribute__((optimize(ITCM_RAM_OPTIMISATION)))
#else
#define FAST_CODE __attribute__((section(".tcm_code")))
#endif
// If a particular target is short of ITCM RAM, defining FAST_CODE_PREF in the target.h file will
// cause functions decorated FAST_CODE_PREF to *not* go into ITCM RAM but if FAST_CODE_PREF is not
// defined for the target, FAST_CODE_PREF will become an alias to FAST_CODE (in the common post
// header file), and functions decorated with FAST_CODE_PREF *will* go into ITCM RAM.
#define FAST_CODE_NOINLINE NOINLINE
#endif // USE_ITCM_RAM
// noting this is not used anywhere in the codebase at the moment
#ifdef USE_CCM_CODE
#define CCM_CODE __attribute__((section(".ccm_code")))
#endif
#ifdef USE_FAST_DATA
#define FAST_DATA_ZERO_INIT __attribute__ ((section(".fastram_bss"), aligned(4)))
#define FAST_DATA __attribute__ ((section(".fastram_data"), aligned(4)))
#endif // USE_FAST_DATA
#if defined(USE_EXST) && !defined(RAMBASED)
#define USE_FLASH_BOOT_LOADER
#endif
#if defined(USE_FLASH_MEMORY_MAPPED)
#if !defined(USE_RAM_CODE)
#define USE_RAM_CODE
#endif
#define MMFLASH_CODE RAM_CODE
#define MMFLASH_CODE_NOINLINE RAM_CODE NOINLINE
#define MMFLASH_DATA FAST_DATA
#define MMFLASH_DATA_ZERO_INIT FAST_DATA_ZERO_INIT
#endif
#ifdef USE_RAM_CODE
// RAM_CODE for methods that need to be in RAM, but don't need to be in the fastest type of memory.
// Note: if code is marked as RAM_CODE it *MUST* be in RAM, there is no alternative unlike functions marked with FAST_CODE/CCM_CODE
#define RAM_CODE __attribute__((section(".ram_code")))
#endif

View file

@ -77,6 +77,6 @@
#define FLASH_PAGE_SIZE ((uint32_t)0x4000) // 16K sectors
// ITCM is in short supply for this target.
// For this target, functions decorated FAST_CODE_PREF will not be put into ITCM RAM;
// For this target, functions decorated FAST_CODE_PREF will not be put into ITCM RAM;
// on other targets, the same function *will* go into ITCM RAM
#define FAST_CODE_PREF