Shop OBEX P1 Docs P2 Docs Learn Events
SD-FAT-Engine issues — Parallax Forums

SD-FAT-Engine issues

JavalinJavalin Posts: 892
edited 2013-03-29 14:13 in Propeller 1
Hello all,

Having some issues with Kye's version 2.0 SD-MMC_FATEngine driver. Generally works well, but I am trying to recieve some serial data and then write it to a file - the driver keeps locking up at random times. Attached demo function which illustrates the problem. Am I missing something?
    long        StackSpace[150], DataStackSpace[300]
    byte        txDataBuffer[1000], txDataBufferFileName[13]

The object is being used in multiple cogs, using a lock.
    ' lock
    if(debugSDCardLock := locknew) == -1
        pst.str(string("NoSDLocks", 13))
    else
        pst.str(string("SDLockID="))
        pst.dec(debugSDCardLock)
        pst.tx(13)

    ' started with
    coginit(COG_PAC,FileSystemTest,@dataStackSpace)

the code :
PRI FileSystemTest | waitcounter

    ' quick and dirty file name
    txDataBufferFileName[0] := "d"
    txDataBufferFileName[1] := "a"
    txDataBufferFileName[2] := "t"
    txDataBufferFileName[3] := "a"
    txDataBufferFileName[4] := "2"
    txDataBufferFileName[5] := "."
    txDataBufferFileName[6] := "x"
    txDataBufferFileName[7] := "m"
    txDataBufferFileName[8] := "l"                                

    ' make up some data (ABCD....)
    repeat waitcounter from 0 to 15
        txDataBuffer[waitcounter] := waitcounter+65

    ' debug
    pst.str(@txDataBufferFileName)
    pst.tx(13)
    pst.str(@txDataBuffer)
    pst.tx(13)    

    
    repeat

        pst.str(string("Start:",13))        
    
        ' lock - wait till lock == true
        waitcounter := 0
        repeat until not lockset(debugSDCardLock) OR waitcounter > 50
            waitcnt(clkfreq/10+cnt)
            waitcounter++
         
        if waitcounter => 50
            pst.str(string("lock failed",13))

        else

            pst.str(string(" -> Lock OK",13))        
             
            if(FileExists(@txDataBufferFileName))
                SDCard.DeleteEntry(@txDataBufferFileName)
                pst.str(string("->deleted",13))
            else
                pst.str(string("->No File",13))                                
             
            pst.str(string("->Create File",13))        
            SDCard.newFile(@txDataBufferFileName)
            pst.str(string("->Open File",13))        
            SDCard.openFile(@txDataBufferFileName,"W")
                              
            repeat 10                              
                SDCard.WriteString(@txDataBuffer)
                pst.str(string("->Write....",13))                     
            
            pst.str(string("Close!",13))        
            SDCard.CloseFile
             
            lockclr(debugSDCardLock)        
             
            pst.str(string("SDataDone",13))


            waitcnt(clkfreq*2+cnt)


Typical console output, but can lockup in different places:
data2.xml
ABCDEFGHIJKLMNOP
Start:
 -> Lock OK
->deleted
->Create File

Grateful for any help, Thanks. Hopefully something simple. Sometimes it works once.

James

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2013-03-28 17:12
    repeat until not lockset(debugSDCardLock) OR waitcounter > 50
    • if you never get the lock waitcounter will be 51 when the loop exits
    • if you get the lock waitcounter could be 0..49, 50 or 51
    You could try something along the lines of
    repeat until (locked := not lockset(debugSDCardLock)) OR waitcounter > 50
    
    and then check locked first before you consider timeout (which is kind of built into !locked AND loop exit).
  • Cluso99Cluso99 Posts: 18,069
    edited 2013-03-29 14:13
    IIRC the filename needs to be a string and therefore '0' terminated. It maybe that your byte allocation is zeroed, but you should not rely on this. Therefore, add the line
    txDataBufferFileName[9] := 0
    I haven't looked elsewhere at your code, so this might not be the problem.
Sign In or Register to comment.