IAR 9.30.1 GD32F427 printf无法打印
由于编译的工程文件存在typeof函数,编译一直不通过:查询得知低版本的IAR不支持typeof()
原因:typeof()是GNU C的关键字,有的编译器支持,有的编译器不支持。因此将低版本替换至高版本iar
低版本的9.10.1工程中可正常打印信息,高版本9.30.1打开该工程无法使用。总结一下方法步骤:
1、打开IAR的安装目录,查找write.c文件 D:\IAR\arm\src\lib\file
2、修改write.c文件,修改以下位置:
(1)将原版本重定义函数复制到write.c文件:(本文以gd为例)
`int fputc(int ch, FILE *f)
{
usart_data_transmit(USART0, (uint8_t)ch);
while(RESET == usart_flag_get(USART0, USART_FLAG_TBE));
return ch;
}`
原write.c文件修改为:
`int MyLowLevelPutchar(int ch);
{
usart_data_transmit(USART0, (uint8_t)ch);
while(RESET == usart_flag_get(USART0, USART_FLAG_TBE));
return ch;
}`
(2)将原函数的if#0 修改为if 1
修改完成后的write.c文件如下:
#include <LowLevelIOInterface.h>
#include "gd32f4xx.h"
#include <stdio.h>
#pragma module_name = "?__write"
#define EVAL_COM1 USART0
int MyLowLevelPutchar(int ch);
int MyLowLevelPutchar(int ch);
{
usart_data_transmit(EVAL_COM1, (uint8_t)ch);
while(RESET == usart_flag_get(EVAL_COM1, USART_FLAG_TBE));
return ch;
}
/*
* If the __write implementation uses internal buffering, uncomment
* the following line to ensure that we are called with "buffer" as 0
* (i.e. flush) when the application terminates.
*/
size_t __write(int handle, const unsigned char * buffer, size_t size)
{
/* Remove the #if #endif pair to enable the implementation */
#if 1
size_t nChars = 0;
if (buffer == 0)
{
/*
* This means that we should flush internal buffers. Since we
* don't we just return. (Remember, "handle" == -1 means that all
* handles should be flushed.)
*/
return 0;
}
/* This template only writes to "standard out" and "standard err",
* for all other file handles it returns failure. */
if (handle != _LLIO_STDOUT && handle != _LLIO_STDERR)
{
return _LLIO_ERROR;
}
for (/* Empty */; size != 0; --size)
{
if (MyLowLevelPutchar(*buffer++) < 0)
{
return _LLIO_ERROR;
}
++nChars;
}
return nChars;
#else
/* Always return error code when implementation is disabled. */
return _LLIO_ERROR;
#endif
}