Some STM32 CPUs include two banks of memory: the standard SRAM and another bank of Core-Coupled-Memory (a.k.a. CCM) which may be faster than the standard SRAM and is usually smaller.
In some cases it may be interesting to place datain this area.
For this there is several possibilities, depending on the amount of memory needed by your program.In all cases you may need to manually edit the linker script file (LinkerScript.ld, except if generated by CubeMX where the name depend on the chip reference).
Checking if CCM was declared
You must first look for the MEMORY section and, if it is not present, add a line looking like (of course you must check the address of the CCM block; this comes from a STM32F429i chip).Placing full data sections in CCM
Then you must decide which sections must be placed in CCM.
Placing all initialized data in CCM
This is quite simple; You may place all initialized data in CCRAM by changing the line that reads at the end of the .data section byPlacing all zero-initialized data in CCM
You may also place all BSS (zero initialized) data in CCRAM by changing the line that reads at the end of the .bss section byPlacing individual variables in CCM
You may place individual variables in the CCRAM area, although this may be a bit more complex.
Placing uninitialized variables in CCM
You can very simply place uninitialized variables in CCM by adding to their definition a section attribute, like, for variable in_ccmram_buffer declaring it by: (Yes, there is double underscores and double parentheses in this ugly syntax, mainly to be sure you do not use it by mistake...) If it does not exist, you must create the .ccmram section by:If it exist, in your linker script be careful not to initialize ythe variable, even to zero, as it will take space in flash; optionally you may suppress the AT> FLASH stance at the end of the default .ccmram section definition.
Placing zero-initialized variables in CCM
By default, variables placed in CCMRAM by attributes can’t be initialized, even to zero.
If you needed to initilalize them to zero, you must slightly enhance the startup_stm32xxxxx.S file to add a second zero-initialization loop (using symbols _sccmram and _eccmram) by duplicating the code for the bss, just after its final bcc FillZerobss, modifying it to look like:Placing initialized data in CCM
Conversely you can create initialized ccmram data sections by placing initailized variables in a .ccmidata section.
You must first define this section in the linker script by:The you must duplicate the data section copying code (using symbols _siccmram, _sccmidata and _eccmidata) just after its bcc CopyDataInit:
Placing the heap and stack in CCM
Finally to place the heap and stack in CCMRAM (possibly after other data) you just have to do two small modifications in the linker script:
- Redirect the output of the ._user_heap_stack to the CCMRAM memory area instead of RAM.
- Redefine the _estack symbol to the end of the CCMRAM by replacing by (for example, if the CCM RAM goew from 0x10000000 to 0x1000FFFF, again specific addresses may change)