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

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

2,847 Views
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

Labels (1)
0 Kudos
Reply
4 Replies

2,167 Views
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 Kudos
Reply

2,167 Views
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 Kudos
Reply

2,167 Views
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 Kudos
Reply

2,167 Views
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 Kudos
Reply