SD Card Engine Errors
n_ermosh
Posts: 294
I am working on a project where I use a VGA monitor and an SD card for reading/writing data, along with a keyboard. I am using the AN006 driver without an RTC. By itself, I can write to the SD card just fine, directories and subdirectories work fine. But once i implement the code into my project, I can't write into subdirectories and whenever i use a "/" in any input string, the VGA monitor start display completely random pixels across the whole screen and the entire program crashes. Any ideas on what might be causing this? Memory issues? And where are the return strings stored in the memory that the SD driver returns when calling a method? I am using memory starting at $7000 for storing my own strings. Right now, i am using the demo board for everything, so is there a chance of a cog running one device changing pins states used by another?
Comments
If your program is long, $7000 area may be used by stack or other variables. Don't use absolute adresses until these are not necessary; better declare your buffers as variables and use @ to get address of your variable.
One cog can change all pins according to its dira setting, so cogs can interfere.
The best way to get help here is attaching your code, then maybe someone of us can find a bug in it.
Thanks,
So, you need to abort trap the FATEngine functions. AN006 mentions that you need to do this. If you don't then the first error the file system encounters will halt the whatever cog was running the code. Aborts and abort traps are like throw and catch statements in other languages.
What do you mean by write data?
So... the FATEngine does not implicity create files or folders like open() is C. You have to tell the driver to create a file or folder first before being able to open a file or change the directory into a folder.
Please post the snippet that is having problems.
Thanks,
I mean if i create a directory, change to it, create a new file, write some bytes to it, then open the SD on a computer, the file that should be inside is in the root directory.
The FATEngine does indeed work. So... please post your zip of your code .
---
The example file distributed with the FATEngine shows how to abort trap functions.
Thanks,
Basically, an abort statement is like a return statement that keeps returning until it is trapped. It if is not trapped the abort statement will shut the processor down. Here's an example of what abort statement are for:
Notice the '\' character. This is the abort trap. By using the abort I can directly return the result of the abort straight back from method 'e' by passing the entire method call chain that called method 'e'. Otherwise I would have to pass the result from method 'e' back through every method. This would be tedious and can extraordinary bloat code depending on how deep the error comes from in the call chain. So, abort traps are a very clean and efficient way of handling errors.
If the abort is not caught with the abort trap character the processor just shuts down because the abort statement pops the call stack until there is nothing to do anymore.
---
I see your problem in the code. You don't want to unmount the partition after doing every command. The mount function resets the file system back to a default state using the root directory.
In general, only call mount partition once... and unmount partition once you are done. In you plan to mount and unmount constantly then you can't use the change directory function because you always reset the working director back to the root directory on mounting the SD card.
It looks like you got the idea otherwise.
Thanks,
I tried to implement a printWorkingDirectory function... but the cost of making one is too much. So... the user will need to keep track of where they are.
---
The reason a print working directory function is hard is because you need a lot of string manipulation functions to handle the working directory string. Alternatively something could be done with linked list... but I have keep to the FATEngine memory usage static. The harder problem is that you can pass really crazy path strings to the FATEngine. For example: "/folder/./../directory/anotherfolder/.././..". This path is equivalent to "/". To make the print working directory function work I need to be able to follow the directory path string you give me and be able to reverse any changes I make to the working directory path string if I encounter and error. There are other issues too...
Basically, it just ends up being too much effort for too little.
An alternative easy way to figure out the path string would be to back track from wherever you could be in the file system. However, this approach has other issues. Mainly that the FATEngine would need to store a history of the cluster locations of all the folders it had entered... Which can get messy too and have a non-static memory footprint.
Anyway,
Thanks,
---
Again, doing current directory tracking is hard... but, possible. It's a substantial amount of code, however.
Thanks,
It seems to be better to track it in player (or anoher application) code, because this code knows exactly when it changes a directory and it can add/remove a piece of path from a "current dir" string when directory is changed.
It's just a lot of work to really do it correctly. People have already been complaining about the FATEngine being bloated. I don't want to make it bigger .
I don't do it. Make it possible to get info if desired and let the user do the rest. Once upon a time in the world of Unix the motto was do one thing at a time and do it well!