Shop OBEX P1 Docs P2 Docs Learn Events
SD Card Engine Errors — Parallax Forums

SD Card Engine Errors

n_ermoshn_ermosh Posts: 294
edited 2012-07-23 20:09 in Propeller 1
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

  • pik33pik33 Posts: 2,397
    edited 2012-07-21 08:15
    This is symptom of a bug you have somewhere. Uninitialized variable, missed "@", indentation error, etc.

    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.
  • KyeKye Posts: 2,200
    edited 2012-07-21 08:27
    You have a bug in your code. Please try to narrow down the code that seems to crash your application and post it for review.

    Thanks,
  • n_ermoshn_ermosh Posts: 294
    edited 2012-07-21 19:10
    I changed the code to using DAT symbols for my strings. The monitor doesn't crash now, but it will still freeze up if there is an error thrown by the FATEngine. attached is my code. Thanks for your help. Also, whenever the FATEngine writes data, it always puts it in the root directory, regardless of the one it says it's in.
  • KyeKye Posts: 2,200
    edited 2012-07-21 19:45
    Can you post a zip? I can't open rar archives.

    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.
    Also, whenever the FATEngine writes data, it always puts it in the root directory, regardless of the one it says it's in.

    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,
  • n_ermoshn_ermosh Posts: 294
    edited 2012-07-21 19:49
    ok, i think that might be my issue, the AN006 documentation doesn't describe exactly how to do that, so how is it done exactly? I am not at the computer that the project is on, so i can't re upload it write now.
  • n_ermoshn_ermosh Posts: 294
    edited 2012-07-21 20:19
    Kye wrote: »

    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.
  • KyeKye Posts: 2,200
    edited 2012-07-22 08:07
    So, the change directory function may have failed somehow.

    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,
  • n_ermoshn_ermosh Posts: 294
    edited 2012-07-22 09:54
    Here it is. When I created another program that ran just the engine, everything worked fine. Also, how do you "trap" the abort errors returned by the FATEngine? From the debugging I did, it seemed like if i gave it, say, a directory to change to that didn't exist, it wouldn't return an error, it would just freeze. Attached is the code
  • KyeKye Posts: 2,200
    edited 2012-07-22 16:15
    Please read the Propeller Manual about Abort statements. You need to understand what they are. The behavior you are experiencing is a direct result of not understanding what abort statements do.

    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:
    PUB main
      result := \a
    
    PUB a
      b
    
    PUB b
      c
    
    PUB c
      d
    
    PUB d
      e
    
    PUB e
      abort 1337
    
    

    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,
  • n_ermoshn_ermosh Posts: 294
    edited 2012-07-22 16:40
    Thank you so much, as soon as i get the code updated, I'll let you know if everything works. Also, I didn't see a function that returns the current directory, How do i figure that out?
  • KyeKye Posts: 2,200
    edited 2012-07-22 18:00
    I didn't implement that function in the FATEngine because the propeller chip is a microcontroller.

    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,
  • n_ermoshn_ermosh Posts: 294
    edited 2012-07-22 18:04
    Ok, well you have done more than enough already, thanks a lot. I am still working on fixing a few other issues i just noticed in my code, as soon as it's done i'll post an update.
  • n_ermoshn_ermosh Posts: 294
    edited 2012-07-22 19:35
    ok, everything works, thanks so much for your help! Now to write the code for the current directory tracker
  • KyeKye Posts: 2,200
    edited 2012-07-22 20:42
    Please change the thread status to closed :).

    ---

    Again, doing current directory tracking is hard... but, possible. It's a substantial amount of code, however.

    Thanks,
  • pik33pik33 Posts: 2,397
    edited 2012-07-22 21:41
    Current directory display is something I want to have in my player;

    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.
  • KyeKye Posts: 2,200
    edited 2012-07-22 22:39
    The FATEngine could do this internally too.

    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 ;).
  • 4x5n4x5n Posts: 745
    edited 2012-07-23 20:09
    Kye wrote: »
    The FATEngine could do this internally too.

    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!
Sign In or Register to comment.