浏览代码

Fix malloc, using OCRAM rather than DTCM

teensy4-core
PaulStoffregen 6 年前
父节点
当前提交
1989b49cf3
共有 2 个文件被更改,包括 21 次插入15 次删除
  1. +4
    -0
      teensy4/imxrt.ld
  2. +17
    -15
      teensy4/libc.c

+ 4
- 0
teensy4/imxrt.ld 查看文件

@@ -73,6 +73,10 @@ SECTIONS
_sbss = ADDR(.bss);
_ebss = ADDR(.bss) + SIZEOF(.bss);

_sdmamem = ADDR(.bss.dma);
_edmamem = ADDR(.bss.dma) + SIZEOF(.bss.dma);
_emallocmem = ORIGIN(RAM) + LENGTH(RAM);

_flashimagelen = SIZEOF(.text.progmem) + SIZEOF(.text) + SIZEOF(.data);
_teensy_model_identifier = 0x23;


+ 17
- 15
teensy4/libc.c 查看文件

@@ -1,24 +1,26 @@
#include <errno.h>
#include "debug/printf.h"

extern unsigned long _ebss;

char *__brkval = (char *)&_ebss; // TODO: put heap into OCRAM, not DTCM
#define STACK_MARGIN 8192
// from the linker script
extern unsigned long _edmamem;
extern unsigned long _emallocmem;

char *__brkval = (char *)&_edmamem;

void * _sbrk(int incr)
{
char *prev, *stack;
char *prev;

printf("sbrk incr = %d\n", incr);

prev = __brkval;
if (incr != 0) {
__asm__ volatile("mov %0, sp" : "=r" (stack) ::);
if (prev + incr >= stack - STACK_MARGIN) {
errno = ENOMEM;
return (void *)-1;
}
__brkval = prev + incr;
}
return prev;
prev = __brkval;
if (incr != 0) {
if (prev + incr > (char *)&_emallocmem) {
errno = ENOMEM;
return (void *)-1;
}
__brkval = prev + incr;
}
return prev;
}


正在加载...
取消
保存