原因是因为arm-none-eabi编译器为了节省空间,删减了一部分代码, 导致有些方法只有声明没有实现,只要在项目中添加实现的代码就可以了,使用__weak修饰语,如果其他地方有实现就自动失效
在项目中新建一个.c文件,随意取名,例如my_syscalls.c,内容如下。
然后将 printf 重定向(网络上有很多方法),把 printf 打印的内容透过串口发送到上位机,就可以用来调试代码了
#include <stdio.h>
#include <stdarg.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdarg.h>
#undef errno
extern int errno;
extern int _end;
__weak caddr_t _sbrk(int incr)
{
static unsigned char *heap = NULL;
unsigned char *prev_heap;
if (heap == NULL)
{
heap = (unsigned char *) &_end;
}
prev_heap = heap;
heap += incr;
return (caddr_t) prev_heap;
}
__weak int link(char *old, char *new)
{
return -1;
}
__weak int _close(int file)
{
return -1;
}
__weak int _fstat(int file, struct stat *st)
{
st->st_mode = S_IFCHR;
return 0;
}
__weak int _isatty(int file)
{
return 1;
}
__weak int _lseek(int file, int ptr, int dir)
{
return 0;
}
__weak int _read(int file, char *ptr, int len)
{
return 0;
}
__weak void abort(void)
{
/* Abort called */
while (1)
;
}