我在我的Cortex M3处理器STM32F103VE代码中使用#pragma import(__ use_full_stdio)。但是当我使用这个pragma时,我的程序不起作用。代码不会进入main()函数。如果我注释行#pragma import(__ use_full_stdio),代码进入main()但在fopen()中给出错误。我已经在ARM网站上看到,如果我想使用像ANSI C这样的文件操作,我必须使用#pragma import(__ use_full_stdio)。
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0376c/BABEJEEB.html
任何人都可以在这里帮忙吗?
我的代码是这样的
#include "stm32f10x.h"
#include "stm32f10x_flash.h"
#include "stm32f10x_rcc.h"
#include "device_init.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#pragma import(__use_full_stdio)
#ifdef __GNUC__
/* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
set to 'Yes') calls __io_putchar() */
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */
PUTCHAR_PROTOTYPE
{
USART_SendData(USART1, (unsigned char) ch);
/* Loop until the end of transmission */
while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET);
return ch;
}
int main(void)
{
char buf[60]={0}, out_buf[60]={0};
FILE *fp = NULL;
// Device specific init APIs like
device_RCCInit();
device_USART1Init(115200);
device_LedInit();
device_LcdInit();
device_TimeInit();
device_FlashInit();
device_EepromInit();
device_MiscInit();
device_AdcInit();
device_BackUpInit();
strncpy(buf, "hello world", sizeof(buf));
fp = fopen("username.txt", "w");
if(fp){
fwrite(buf, strlen(buf), 1, fp);
fclose(fp);
}else{
printf("File open failed\n");
goto end;
}
fp = fopen("username.txt", "r");
if(fp){
fread(out_buf, 20, 1, fp);
fclose(fp);
}else{
printf("File open failed\n");
goto end;
}
printf("data is: %s", out_buf);
end:
while(1)
{
printf("Infinite loop \n");
}
}