This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

how to save data into file in keil IDE

hi
I want to save my intermediate data into a file.
I tried to use fopen, fwrite, it can not even read. how should i use rtl.h ?

  int  count[10];
  FILE *fout;

  fout = fopen ("Counter.bin","w");
  if (fout != NULL) {
    fwrite (&count[0], sizeof (int), 10, fout);   // write an item 10 times to the file
    fclose (fout);

my keil version 4.6
ARM core is cortex-M0.
I am using the startup_MPS_CM0.s startup file to do the work.

Thanks for help!

  • Did your hardware come with an installed hard disk?

    Embedded products normally don't have any fopen(), fread(), ... because there are normally no standard hardware available to store files.

    So - what have you done to map your code to your hardware for file support? Have you linked your project with any file system support? Memory card support?

  • Thanks for your reply!
    I did this in simulation mode, no hardware related.
    All I want to do is to save a long array into a file.

    Thanks

  • After running debugging, I can use "save" command to save the data in memory to one file.
    is there any way to do it in code ?

    Thanks

  • Not sure what you are trying to save but would LOG or SLOG save the data you need? If so, you can write a simple script to LOG the data to a file.

    Then set a BreakExec at a code point where you would like to save the data. A BreakExec will fire the script but will not stop code execution.

    Might this work for you? Good luck.

    Bradford

  • Thanks for reply!

    I want to save a long array into a file, this file can be .hex or .bin format.
    it is good to do this in the c coding.

    The LOG or SLOG are the commands, similar as SAVE. can you give an example about your suggestion?

    Thanks again.

  • Thanks for your link. it seems like that I have to set the .ini file with creation of the exec("save") and button.

    I understand that "Embedded products normally don't have any fopen(), fread(), ... because there are normally no standard hardware available to store files."

    why could not we use potential stream functions (if not fopen, fwrite )in the simulation mode to save the data to a file? should I have to run in specific mode or use some special library?

    Keil IDE should be able to do so, theoretically, it is doable .

  • If you skip fopen() etc, then yes. There are support for having Cortex chips "print" debug data to the debugger. Documentation available on this site.

    For other chips, the normal route is to just connect printf() to a serial port and then log all data sent out on that port.

    But then we are talking about strict write of data on a stream. You did also mention "read" in your original post. If you need two-way communication, then it's time to implement a server application and use RS232, USB, Ethernet, ... to communicate between your device and the server. Then you can do whatever you want. Including having the server "tunnel" accesses to the file system of a PC.

  • Another thing to consider, is to have the program store the data you want to save into a RAM buffer or known address. Let the debugger retrieve this data and save to file. On another run, load this file and have the debugger send it to the RAM of your device.

    So similar operations as when programming, or reading, the contents of the flash memory.