PropGCC SD Card File?
SRLM
Posts: 5,045
I've looked through all the documentation that I can find, but I can't figure out:
How do I get the equivalent functionality to FSRW with PropGCC?
Basically, I want to
- read a list of files in the top level directory
- create a text file and write to it (fast!)
I'd prefer it if it was as close to FSRW in implementation as possible, and lean. I'm not worried about folders (although that would be nice), and I won't be running XMM programs.
How do I get the equivalent functionality to FSRW with PropGCC?
Basically, I want to
- read a list of files in the top level directory
- create a text file and write to it (fast!)
I'd prefer it if it was as close to FSRW in implementation as possible, and lean. I'm not worried about folders (although that would be nice), and I won't be running XMM programs.
Comments
Ray
Use MONITOR define to reenable the demo. The "abe.txt" demo without the monitor files is about 17KB in CMM.
This would seem to indicate that there isn't enough memory, but the downloader only loads 15016 bytes. Here is the main function: If I change the fopen("abe2.txt","r") in the main to open abe.txt (an existing text file on the SD card), the read works correctly. So, it appears that I have just two problems:
1. Why, on the fopen, would errno give an error of 4 ("interrupted system call") instead of a 2 ("no such file or directory") error?
2. Why doesn't it write to the SD card? I'll mention that this is a micro SD card, without a R/W switch and that the previous version (posted by Jazzed) worked.
errno is changed only when there is an error, so the initial value of 12 may not represent a real error number. You should check the result of the mount to see if it mounted the SD card OK.
BTW, an errno of 12 is EIO, which is an unspecified file error.
I see now where the Propeller specific errno codes are declared (here). I'm curious as to why they don't match the "standard" meaning of the error codes, at least as far as possible (such as this list).
So, if the error that I get to create the abe2.txt file is no such file or directory, then where am I going wrong? From fopen documentation I'd expect that fopen will create the file.
You fopen should create abe2.txt. I don't do much C++, so maybe there's a problem with that. Have you tried C instead of C++? You can convert the debug prints to printf's.
I assume this is due to PropGCC initializing stdin/out/err behind the scenes, and trying to initialize the SD card as the IO driver.
I tested my theory by first making a program with just printfs. I compiled with both GCC and G++, and in both C and C++ modes it worked. Then I made a C++ program with a custom serial driver (FFDS1) outputting to pins 2 and 3, which were hooked up to a second Prop Plug. I was able to get this communication, so I removed all the printf statements from my code. The program still worked.
Finally, I removed the SimpleSerial driver entry in the driver table, along with it's extern declaration. The program no longer worked (as indicated on pins 2 and 3 with the FFDS1 driver).
I think this is a bug somewhere is the stdio system. Is there anyway where we can force stdin/out/err not to be initialized?
As Dave said, you have to use either the symbolic values or the strerror() or perror() functions to make sense of the error codes.
Eric
I don't think it's a bug, but perhaps it's a surprising feature. It is documented; see for example http://propgcc.googlecode.com/hg/doc/Library.html#drivers:
The first driver in the list is the "default" driver, and is used to open the stdin, stdout, and stderr FILE descriptors. If you want finer control over how these files are opened, you can either use the freopen function on them at the start of your code, or define a function _InitIO which will set up the file handles.
So if you don't want stdout/stderr/stdin you can either put a dummy entry as the first entry in the list (like _NullDriver) or else write your own version of _InitIO, which is the constructor function which is called to set up stdio. The source code for _InitIO may be found in lib/stdio/init_io.c, but it's pretty simple:
For comparison, switching the code from _SimpleSerialDriver to _NullDriver reduced the code from 15744 bytes to 14764 bytes (~1KB) in CMM Os mode . In both cases, there is no printf or anything in the user code that uses the stdin/out/err. I'm also able to use pins 31 and 30 with user C++ code.
With this code, it is noticably slow: 1kB/s slow. The C++ version of FSRW, when running a similar test, writes at 80kB/s or more. Am I missing something?
Terminal Output:
Long time listener, first time caller...
I put together a S-Ide gcc (plain C, not ++) project with the program assembled from all the bits/comments above, and plain printf's.
Kind of a combination of everything said in the thread, included the corrected driver order so it doesn't lock up on a printf (that one had me stumped all last night).
I'm using propgcc as an excuse to finally learn C properly (I think I've taken in about 4 times, and never went further with it). So excuse any wtf's, or why would you do it that ways..
Cheers, Joe
sd_test_c.zip
I'll help as time allows. Others will too. WTF's are ok
Thanks.
--Steve