SD-FAT-Engine issues
Javalin
Posts: 892
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?
The object is being used in multiple cogs, using a lock.
the code :
Typical console output, but can lockup in different places:
Grateful for any help, Thanks. Hopefully something simple. Sometimes it works once.
James
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
- 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 and then check locked first before you consider timeout (which is kind of built into !locked AND loop exit).txDataBufferFileName[9] := 0
I haven't looked elsewhere at your code, so this might not be the problem.