CoIDE 1.6.2下使用ARM GCC 4.7 Newlib-nano printf 重定向到UART
来源:互联网 发布:人脸识别pca算法代码 编辑:程序博客网 时间:2024/06/18 12:01
下载安装CoIDE1.6.2: http://www.coocox.org/Tools/CoIDE-1.6.2.exe
并用文件(登陆注册CooCox论坛http://www.coocox.org/forum/topic.php?id=2611打开有道云笔记链接,将目标文件另存为即可)替换CoIDE安装目录下/plugins/org.coocox.builder.ui_1.0.0.201212141638.jar()
下载 GNU Tools for ARM Embedded Processors Version: 4.7
下载地址是:
https://launchpad.net/gcc-arm-embedded/+milestone/4.7-2012-q4-major
CoIDE中设置工具链,这里不详细说明
这里以Cookie板子为例,说明CoIDE下 Newlib-nano printf 重定向到UART过程,一共分为三步
1.新建工程,并添加printf语句
2.选择Newlib-nano,支持打印浮点数
3.重定向printf
1.新建工程,并添加printf语句
新建一个M051的工程,如何新建工程这里不详细说明
勾选如下组件
在UART组件中添加cookie_printf例子到工程
打开cookie_printf.c文件,添加 #include <stdio.h>这个头文件
并在while(1)循环中加上
printf("Nano Clib test:int=%d float=%f\r\n",255,123.456);
2.选择Newlib-nano,支持打印浮点数
点击配置按钮进入配置:
进入link标签页
在Linked Library中添加
D:\Program Files\GNU Tools ARM Embedded\4.7 2012q4\arm-none-eabi\lib\armv6-m\libc_s.a
D:\Program Files\GNU Tools ARM Embedded\4.7 2012q4\arm-none-eabi\lib\armv6-m\libg_s.a
注意:用于Cookie是M0的芯片所以选armv6-m下面的库,如果使用M3则选armv7-m,M4则选armv7e-m
ARM Core
multilib
Cortex-M0+
armv6-m
Cortex-M0
armv6-m
Cortex-M1
armv6-m
Cortex-M3
armv7-m
Cortex-M4
armv7e-m
如果需要支持浮点数打印,则在Misc Consle中添加 -u;_printf_float;(注意,标准命令是 -u _printf_float,CoIDE的原因,不得已而为之)
3.重定向printf
打开syscalls.c,编写如下代码
/**************************************************************************//*****
* @file stdio.c
* @brief Implementation of newlib syscall
********************************************************************************/
#include <stdio.h>
#include <stdarg.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdarg.h>
#include "xhw_types.h"
#include "xhw_ints.h"
#include "xhw_memmap.h"
#include "xuart.h"
#undef errno
extern int errno;
extern int _end;
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;
}
int link(char *old, char *new) {
return -1;
}
int _close(int file)
{
return -1;
}
int _fstat(int file, struct stat *st)
{
st->st_mode = S_IFCHR;
return 0;
}
int _isatty(int file)
{
return 1;
}
int _lseek(int file, int ptr, int dir)
{
return 0;
}
int _read(int file, char *ptr, int len)
{
return 0;
}
int _write(int file, char *ptr, int len) {
int txCount;
(void) file;
for (txCount = 0; txCount < len; txCount++)
{
xUARTCharPut(xUART0_BASE,*ptr++);
}
return len;
}
void abort(void)
{
/* Abort called */
while(1);
}
/* --------------------------------- End Of File ------------------------------ */
用ColinkEx下载就可以看到串口打印了。
Newlib-nano 的好处,看看size就知道
不使用浮点数:
使用浮点数
- CoIDE 1.6.2下使用ARM GCC 4.7 Newlib-nano printf 重定向到UART
- COIDE下重定向printf
- CoIDE串口重定向printf
- STM32Cube Printf uart重定向
- Keil重定向printf到串口UART输出
- PSOC 编程时将printf()重定向到UART
- 单片机的printf重定向到OLED/UART/SEGGER_RTT
- printf重定向输出到文件
- 嵌入式调试printf重定向到文件
- vc6 printf重定向输出到文件
- STM32中printf重定向到串口
- STM32中printf重定向到串口
- 关于printf重定向到串口
- Keil C51重定向printf到串口
- STM32中printf重定向到串口
- Keil C51重定向printf到串口
- STM32-printf重定向到USART
- 串口输出重定向到 printf
- 再次写给我们这些浮躁的程序员
- Android开发学习笔记(十三) ProgressDialog学习
- MQ Command
- 微软发布安全公告2798897,更新证书信任列表
- 常用web.config公共配置
- CoIDE 1.6.2下使用ARM GCC 4.7 Newlib-nano printf 重定向到UART
- view 没有达到自己预料的效果 找不见
- Android开发(2)---- HelloWorld 显示
- 查找中位数,在线算法
- ubantu下解决 Could not get lock /var/lib/dpkg/lock 问题方法
- shell脚本补充
- BCGControlBar入门使用手册(1)
- mysql数据去除重复记录小结
- 使用ajax得到返回值时执行顺序问题