硬件:STM32F103ZET6 + 512Kbyte 外扩的SRAM
使用原子的内存管理函数给 EMWIN分配内存,分为内部RAM和外部RAM两个内存池
define region RAM_region = mem:[from __ICFEDIT_region_RAM_start__ to __ICFEDIT_region_RAM_end__]
| mem:[from __ICFEDIT_region_EXTRAM_start__ to __ICFEDIT_region_EXTRAM_end__];
这里采用这种写法时,内外部RAM放在一起供编译器链接时自动分配,
编译器链接.data / .bss段时会自动给各个.o 文件中的对应段分配RAM,但是当内部RAM空进不足时编译器将内部RAM内存池或者EMWIN函数.o文件中的
.data、.bss分配到外部RAM时,刷屏就会变得很慢。
这里可以自行定义一个section ,将大数组,读取不太频繁的数据放进这个section,同时在ICF文件中将这个section放入外部RAM,仅让编译器自动分配内部RAM,手动指定
外部RAM的分配即可。
如下:
在 程序中:定义一个section :#pragma section = “MYSECTION”
定义变量或数组时:
#pragma location = "MYSECTION"
UartItem uart1;//定义的串口设备变量
或者
unsigned char buf [100]@"MYSECTION";
在ICF配置中:
define region EXRAM_region = mem:[from __ICFEDIT_region_EXTRAM_start__ to __ICFEDIT_region_EXTRAM_end__];
place in EXRAM_region { readwrite section MYSECTION};
//
ICF配置
/*###ICF### Section handled by ICF editor, don't touch! ****/
/*-Editor annotation file-*//* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */
/*-Specials-*/
define symbol __ICFEDIT_intvec_start__ = 0x08000000;
/*-Memory Regions-*/
define symbol __ICFEDIT_region_ROM_start__ = 0x08000000;
define symbol __ICFEDIT_region_ROM_end__ = 0x0807d800;
define symbol __ICFEDIT_region_EXTRAM_start__ = 0x60000000;
define symbol __ICFEDIT_region_EXTRAM_end__ = 0x60060000;
define symbol __ICFEDIT_region_RAM_start__ = 0x20000000;
define symbol __ICFEDIT_region_RAM_end__ = 0x2000FFFF;
/*-Sizes-*/
define symbol __ICFEDIT_size_cstack__ = 0x800;
define symbol __ICFEDIT_size_heap__ = 0x800;
/**** End of ICF editor section. ###ICF###*/
define memory mem with size = 4G;
define region ROM_region = mem:[from __ICFEDIT_region_ROM_start__ to __ICFEDIT_region_ROM_end__];
define region RAM_region = mem:[from __ICFEDIT_region_RAM_start__ to __ICFEDIT_region_RAM_end__];
define region EXRAM_region = mem:[from __ICFEDIT_region_EXTRAM_start__ to __ICFEDIT_region_EXTRAM_end__];
define block CSTACK with alignment = 8, size = __ICFEDIT_size_cstack__ { };
define block HEAP with alignment = 8, size = __ICFEDIT_size_heap__ { };
initialize by copy { readwrite };
do not initialize { section .noinit };
place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec };
place in ROM_region { readonly };
place at address mem: __ICFEDIT_region_RAM_start__ { block CSTACK, block HEAP};
place in EXRAM_region { readwrite section MYSECTION};
place in RAM_region { readwrite };