LVGL dynamic memory uses CCMRAM
Use STM32F407VET6 to develop a project, use LVGL, and then pay attention to the RAM information of STM32. The official introduction of the RAM of STM32F407 The available RAM is 192K, but this 192K is not continuous, but divided into three blocks, only two of which are continuous , and because STM32F4 does not have a memory management unit such as MMU, it can translate continuous virtual kernel addresses to non-contiguous physical addresses, so we must pay attention to the address and the size of the memory space when using the RAM of STM32F407!
Flip the chip manual to see the specific RAM information:
It can be seen that the 192K RAM is divided into 112K SRAM1 , 16K SRAM2 , and 64K CCMRAM
Among them, SRAM1 and SRAM2 are connected by the core bus through the bus matrix, while CCMRAM is directly connected to the core bus.
The bus matrix is used to establish the transmission connection between the kernel command bus and the external device bus. It also has functions such as arbitration and simultaneous access to prevent access conflicts and improve access efficiency.
SRAM1 and 2 are two pieces of memory, the addresses are consecutive, starting from 0x20000000, we use this memory segment by default
CCMRAM is separate from the above memory address, its starting address is 0x10000000, the address can be seen in the manual
Because CCMRAM does not go through the matrix bus and is directly connected to the data bus of the kernel, it can only be used for data access, and the access operation is extremely fast and efficient. I just use LVGL as a graphics framework, so I am going to use this 64K In terms of memory usage, as the dynamic memory storage space of LVGL, the ARM-GCC compiler is used. Briefly introduce the usage of this memory. My development environment is VSCode, and then the STM32 peripheral code is the Makefile generated by STM32CubeMX. The project, the project helped me generate the link file STM32F407VETx_FLASH.ld, which contains the following code, which is a description of the memory space, with 64K CCMRAM
At the same time, there is a piece of code that specifies the starting and ending addresses of ccmram: _sccmram and _eccmram, and the byte alignment
/* CCM-RAM section
*
* IMPORTANT NOTE!
* If initialized variables will be placed in this section,
* the startup code needs to be modified to copy the init-values.
*/
.ccmram :
{
. = ALIGN(4);
_sccmram = .; /* create a global symbol at ccmram start */
*(.ccmram)
*(.ccmram*)
. = ALIGN(4);
_eccmram = .; /* create a global symbol at ccmram end */
} >CCMRAM AT> FLASH
So when we use CCMRAM in our own code, we can specify the use of CCMRAM, such as defining a variable
__attribute__((section("CCMRAM"))) int one_dat;
But note that it is mentioned in the comments of his code generation that if we want to put the initialized variables in CCMRAM, we also need to add a piece of initialization code to the startup code to copy the initialized variable values from Flash to CCMRAM , like copying to SRAM, I will make a special explanation later, here I do not need to initialize because it is used to store dynamic memory
The above describes how to use CCMRAM. Let's analyze how to associate dynamic memory with LVGL, enter lv_conf.h, and find the following memory management code:
Change Size to 64K, then change LV_MEM_ATTR to CCMRAM, and change the memory start address LV_MEM_ADR to 0x10000000
Add a test pointer to the task and use lvgl to allocate a piece of dynamic memory:
Then simulate, look at the address of this memory test pointer, you can see that this dynamic memory points to the address space of 0x10000d44, which is located on CCMRAM