FreeRTOS内存溢出
如下图所示,FreeRTOS编译完成后可以看到,系统提示无法分配内存到堆。
.\Objects\Template.axf: Error: L6406E: No space in execution regions with .ANY selector matching heap_4.o(.bss).
.\Objects\Template.axf: Error: L6406E: No space in execution regions with .ANY selector matching startup_gd32f10x_md.o(STACK).
.\Objects\Template.axf: Error: L6406E: No space in execution regions with .ANY selector matching tasks.o(.bss).
.\Objects\Template.axf: Error: L6406E: No space in execution regions with .ANY selector matching tasks.o(.data).
.\Objects\Template.axf: Error: L6406E: No space in execution regions with .ANY selector matching heap_4.o(.data).
.\Objects\Template.axf: Error: L6406E: No space in execution regions with .ANY selector matching port.o(.data).
.\Objects\Template.axf: Error: L6406E: No space in execution regions with .ANY selector matching main.o(.data).
.\Objects\Template.axf: Error: L6406E: No space in execution regions with .ANY selector matching system_gd32f10x.o(.data).
.\Objects\Template.axf: Error: L6406E: No space in execution regions with .ANY selector matching stdout.o(.data).
.\Objects\Template.axf: Error: L6407E: Sections of aggregate size 0x7f54 bytes could not fit into .ANY selector(s).
注意这句话是空间超限的意思:
“No space in execution regions with”
这里需要我们重新设置堆空间的大小,打开FreeRTOSConfig.h 即FreeRTOS的配置文件。
可以看到我这里设置的堆的大小为30k 而我是用的芯片GD32F103C8T6 的SRAM的大小却只有20k,显然超了,这里改为10*1024再次进行编译,完美解决问题。
//支持动态内存申请
#define configSUPPORT_DYNAMIC_ALLOCATION 1
//支持静态内存
#define configSUPPORT_STATIC_ALLOCATION 0
//系统所有总的堆大小
#define configTOTAL_HEAP_SIZE ((size_t)(10*1024))