We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I am using the 'Arm Workbench IDE 4.0'. And I can compile the file access functions
like Following. But when run the image using the 'RealView Debugger v4.0', I can't
find out the xxx.txt file withing the system and ARM tool's directory.
FILE *pFile=NULL;
pFile = fopen(50, (char*)"c:\\temp\\xxx.txt", "wt"); // 50 is file identifier
rv=ferror(pFile);
rv=fprintf(pFile, "test\n");
if(pFile){
fclose(pFile);
pFile = NULL;}
I could have used the 'printf' with debugger tool's stdio so I think that there may be method for file management.
Can I use the file management functions?
And if so how?
fopen is defined by the C standard and you should #include <stdio.h> in files that call it. I expect the example above to give an error when you compile it with #include <stdio.h> because fopen takes two arguments not three; remove the '50,'. Also "wt" is not a legal mode -- but an implementation might allow it as an extension; just use "w".
As written and without #include <stdio.h>, I would expect it to compile with a warning (about fopen being implicitly declared) and give undefined behaviour at runtime. fopen might crash or return NULL. You could use the debugger to stop and see what fopen is returning.
Also:
you should not call ferror nor fprintf if pFile is NULL; calling them with NULL is also undefined behaviour
the (char *) cast is not needed; it's not causing any harm here, but it's a good idea to avoid casting as it prevents the compiler from helping you find type errors
If you build your software to use the ARM C runtime semihosting support, RVD will handle file operations.
I don't know about implementing hosting. And just used the printf with StdIO. My concern is how to access file in the my win7 file system with fopen of firmware source code.
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.faqs/ka3652.html
From above web address, I see the my setting with following: Semihosting Enabled => True Vector => 8 Arm svc num => 0x123456 Thum svc num => 0xAB
What is the proper option for host file access?
If this is not the proper approach, how can I handle the host file from firmware fopen?
Actually above code is obtained from some website. But it can be compiled and pFile pointer value is non-NULL when I confirm with debugger.
But I can't find the file location of xxx.txt. The problem is how can I access the host file system with RVDS. With firmware itself, verification
process is too hard for that the memory space is too short.
How can I access the host file system with RVDS firmware?
Does your build give any warnings? Does your actual code have #include <stdio.h>?
If you rebuild after removing the '50,' and changing "wt" to "w" and are running under the debugger on a Windows host and C:\temp exists, then I expect your image to create C:\temp\xxx.txt on the host.
Thank you! As your answer, it's working. Thank you very much!!!