Can we use fopen, fread, fwrite, fclose standard io function?

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Can we use fopen, fread, fwrite, fclose standard io function?

2,842 次查看
isaotakashima
Contributor IV


I want to read, write a file in the PC using fopen, fread, fwrite, fclose standard io function.

Can we use fopen, fread, fwrite, fclose standard io function?

If yes, please send sample code.

 

Best regards,

Takashima

标签 (1)
0 项奖励
回复
4 回复数

2,162 次查看
BlackNight
NXP Employee
NXP Employee

Hi Takashima,

that depends on the semihosting implementation of the debug connection. E.g. it works fully for Segger J-Link (see https://mcuoneclipse.com/2014/12/26/code-coverage-for-embedded-target-with-eclipse-gcc-and-gcov/ ) but afaik not for P&E (yet?).

Erich

0 项奖励
回复

2,162 次查看
isaotakashima
Contributor IV

Dear Erich,

Thank you for your quick reply.

I'm using TWR-K65F180M with J-Link lite OpenSDA, and I wrote the following code, but I cannot open WAVE.wav file.

  FILE *fp;

  if ((fp = fopen("WAVE.wav", "rb"))==NULL){

    PRINTF("Cannot read file.\r\n");

    for(;;){};

  }

Please advise to fix this issue.

Best regards,

Takashima

0 项奖励
回复

2,162 次查看
BlackNight
NXP Employee
NXP Employee

Dear Takashima,

The question is: what is the current directory of your system?

See https://mcuoneclipse.com/2015/08/23/tutorial-using-gnu-profiling-gprof-with-arm-cortex-m/  where it uses fwrite() to write files. There the current directory is the project root folder. You should use an absolute path or find out what is the current directory on your system (e.g. with creating a file first).

I hope this helps,

Erich

0 项奖励
回复

2,162 次查看
isaotakashima
Contributor IV

Dear Erich,

Thank you for your reply.

I refer https://mcuoneclipse.com/2015/08/23/tutorial-using-gnu-profiling-gprof-with-arm-cortex-m/ , but I cannot find out sample code which use fopen(), fwrite() functions.

Can you send sample code?

Best regards,

Takashima

0 项奖励
回复