1. 修改.ld文件
在STM32F407ZGTx_FLASH.ld增加如下内容。
/* Uninitialized data section */
. = ALIGN(4);
.bss :
{
/* This is used by the startup in order to initialize the .bss secion */
_sbss = .; /* define a global symbol at bss start */
__bss_start__ = _sbss;
*(.bss)
*(.bss*)
*(COMMON)
. = ALIGN(8); //8字节对齐
_ebss = .; /* define a global symbol at bss end */
__bss_end__ = _ebss;
__heap_addr_end__ = ORIGIN(RAM) + LENGTH(RAM); //主要是增加__heap_addr_end__ 。
. = ALIGN(8);
} >RAM
2. FreeRTOSConfig.h
FreeRTOSConfig.h中增加如下内容:
extern uint32_t __bss_end__;
extern uint32_t __heap_addr_end__;
3. 初始化
在main.c中增加如下内容:
static HeapRegion_t xHeapRegions[2];
int main(void)
{
...
/* OS使用的内存 */
xHeapRegions[0].pucStartAddress = (uint8_t *)(&__bss_end__);
xHeapRegions[0].xSizeInBytes = (uint8_t *)(&__heap_addr_end__) - (uint8_t *)(&__bss_end__);
xHeapRegions[1].pucStartAddress = NULL;
xHeapRegions[1].xSizeInBytes = 0;
vPortDefineHeapRegions(xHeapRegions);
/* 初始化任务 */
xTaskCreate(start_task_code, "start", START_TASK_STACK_SIZE, NULL, START_TASK_PRIORITY, &start_tid);
vTaskStartScheduler();
while (1) {
}
}
网友评论