Problems with EFFS

Discussion to talk about software related topics only.
shockwave77598
Posts: 22
Joined: Sat May 27, 2017 10:38 am

Problems with EFFS

Post by shockwave77598 »

I'm having a bizzare issue with reading from an SDCARD and a NANO54415

The objective: Two routines. One picks a random file from the SDCard and opens it. The other reads 1200bytes from the file everytime you execute it. If you reach the end of file, you rewind the file to the beginning. RandomTree is called every couple of minutes and closes any open file while picking a new one. The routine OutputTree reads 1200bytes and puts them in corrected order into an output buffer.

filesel is a global. Any open is kept open across routines ; we don't want to close anything for the minutes that the file is being read. and the enterfs takes place in the usermain.c program at the initialization.

What's happening:

The code reads 1200 bytes once or twice. But every other read afterwords is 0 bytes long, even though the files are a couple Megabytes in length. This 0 byte read doesn't cause EOF though ; that still happens later on. And the Rewind doesn't do anything -- reading more simply causes more EOFs.

The point of all this is to use the SDCard as a massive memory holding patterns of 400 pixels in many files. This data would not fit in any memory of the device. So putting the patterns on an SDCard and just reading it, a) makes a vast memory device b) that can be changed on any pc with a card reader. It sees the directory fine. It even opens and reads a file... one or two times. Then it all goes wonky.

***

/*
* sdcard.cpp
*
* Created on: Dec 23, 2022
* Author: ALLEN
*
* Create an internal directory of all files on an SDCard, and pull ROWS*COLS pixels to the
*/

#include <predef.h>
#include <stdio.h>
#include <stdlib.h>
#include <basictypes.h>
#include <ctype.h>
#include <startnet.h>
//#include <autoupdate.h>
#include <dhcpclient.h>
#include <taskmon.h>
#include <smarttrap.h>
#include <serial.h>
// SDCard
#include <effs_fat/effs_utils.h>
#include <effs_fat/fat.h>
#include "FileSystemUtils.h"
#include <ftpd.h>
#include <networkdebug.h>
#include <nbtime.h>
#include "xmas2011.h"
#include "sdcard.h"

#define SIZEDIR 16

char * filenameRead;
char * fileSelected;
F_FILE * filesel;
char filenames[DIRSSIZE];
int numpatterns; // how many treexx.out patterns are there?

unsigned char Tree[TREECHARS];
unsigned char * ptrTree;
unsigned char * OutTreechar;
unsigned char tempr, tempg, tempb;
int myTreeIndex;
int myTreeStart;
int ii, jj;
unsigned char SDFlag;

int randomFile(int maxout)
{
return rand()%maxout;
}

void InitMYSD()
{
//f_enterFS();
numpatterns=0;
filesel = 0;
SDFlag = 0;
InitExtFlash(); // Initialize the CFC or SD/MMC external flash drive
memset(filenames, 0x00, DIRSSIZE);// clear the directory
}

int GetSDDir(int debug)
{
F_FIND finder; // location to store the information retrieved

/* Find first file or subdirectory in specified directory. First call the
f_findfirst function, and if file was found get the next file with
f_findnext function. Files with the system attribute set will be ignored.
Note: If f_findfirst() is called with "*.*" and the current directory is
not the root directory, the first entry found will be "." - the current
directory.
*/

filenameRead = &filenames[0];
volatile int rc = f_findfirst("*.*", &finder);
if (rc == F_NO_ERROR) // found a file or directory
{
do
{
if (!(finder.attr & F_ATTR_DIR))
{
strcpy(filenameRead, finder.filename);
numpatterns++; // remember this is a global
filenameRead+=SIZEDIR;
if (debug != 0)
iprintf("File [%s] : %lu Bytes\r\n", finder.filename, finder.filesize);
}
} while (!f_findnext(&finder));
}
else
{
numpatterns = 0;
SDFlag = 1;
}

return numpatterns;
}

void SmellFilenames()
{
int i;

if (numpatterns != 0)
{
for(i=0; i<numpatterns; i++)
{
filenameRead = &filenames[i*SIZEDIR];
iprintf("FileMem [%s]\r\n", filenameRead);
}
}
}
int RandomTree(int override)
{
// close current file
if(filesel != 0)
{
f_close(filesel);
filesel = 0;
}
// picks a random tree file unless override is set
if (SDFlag == 0) // no SD fault
{
ii = randomFile(numpatterns);
if ((override != 0) && (override<numpatterns))
ii = override;
ii*=SIZEDIR;
fileSelected = &filenames[ii];
// open new file
filesel = f_open(fileSelected, "r");
if (!filesel)
{
iprintf("%s OPEN ERROR %d \r\n", fileSelected, SDFlag);
return 1; // error opening
}
iprintf("%s reading\r\n", fileSelected);
return 0;
}
iprintf("No SDCard Files\r\n");
return 2;
}

int OutputTree(int startindex) // returns how many pixels were written
{
int numPixels = 0;
int numRead;

if (SDFlag)
{
iprintf("SDFLAG %d\r\n", SDFlag);
return 0;
}
myTreeStart = startindex;
ptrTree = &Tree[0];
// are we at eof, reset if so
if (f_eof(filesel))
{
f_rewind(filesel);
iprintf("rewind\r\n"); // rewinding indication
}
// reads one block of pixels and displays them.
// grab 400*3 chars
numRead = f_read(ptrTree, 1, TREECHARS, filesel);
iprintf(" %d", numRead);
// put them into the outbuffer a pixel at a time
OutTreechar = &Tree[0];
for (ii=TREEROWS-1; ii>=0; ii--)
{
for (jj=0; jj<TREECOLS; jj++)
{
tempr = *OutTreechar++;
tempg = *OutTreechar++;
tempb = *OutTreechar++;
myTreeIndex = (jj*TREEROWS) + ii + myTreeStart;
setlightchar(myTreeIndex, tempr, tempg, tempb);
numPixels +=1;
}
}
return numPixels;
}
User avatar
TomNB
Posts: 538
Joined: Tue May 10, 2016 8:22 am

Re: Problems with EFFS

Post by TomNB »

Hi,

Hardware and software versions?

Do the examples work?
shockwave77598
Posts: 22
Joined: Sat May 27, 2017 10:38 am

Re: Problems with EFFS

Post by shockwave77598 »

I created a new project and imported the file system effs/fat/basic

What happens, is it says it Fat mounts to sd successful, drive change is successful, but gives an error on retrieving external flash usage. F_ERR_READ
Then it announces another error after creating TestFile.txt Error in f_open(TestFile.txt) during task (Main).
F_ERR_INVALIDDRIVE
User avatar
TomNB
Posts: 538
Joined: Tue May 10, 2016 8:22 am

Re: Problems with EFFS

Post by TomNB »

Hello,

Is this an app that can be run on a development board so we can try to re-create it here? If possible, the simplest code set that demonstrates the issue. Also, it would still help to know your h/w and s/w tools version.
shockwave77598
Posts: 22
Joined: Sat May 27, 2017 10:38 am

Re: Problems with EFFS

Post by shockwave77598 »

Nano54415 dev board 1.3
NNDK ver 3.3.9
Attachments
NANOXMAS2_004.zip
Ethernet output of christmas lights patterns
(40.63 MiB) Downloaded 116 times
shockwave77598
Posts: 22
Joined: Sat May 27, 2017 10:38 am

Re: Problems with EFFS

Post by shockwave77598 »

I'm guessing nobody has any idea why reading multiple times one after the other would cause the EFFS to hork?

Is there a shorting pin or other pins I should look at? Maybe something isn't connected and is floating?
*edit*
You can see where it reads 1200 bytes from the card two times, then 672 bytes, then 0 bytes forever more. The data came out and displayed fine, till the sdcard reading quit for whatever reason.
Attachments
20230225_164936.jpg
20230225_164936.jpg (3.08 MiB) Viewed 1615 times
20230225_164914.jpg
20230225_164914.jpg (3.65 MiB) Viewed 1615 times
sulliwk06
Posts: 118
Joined: Tue Sep 17, 2013 7:14 am

Re: Problems with EFFS

Post by sulliwk06 »

It seems suspicious that it stops after reading exactly 3kb. I would wonder if there is a limit on some buffer somewhere.
User avatar
TomNB
Posts: 538
Joined: Tue May 10, 2016 8:22 am

Re: Problems with EFFS

Post by TomNB »

Hello,

Thanks for posting your app, but there is a bit more going on there than I can sort through. I have not seen this behavior before. As a hardware test, how about the simplest possible program that only reads from the file system? That would be a good hardware reliability test. Put a 1M file on there and read the entire thing, displaying on the serial port of checking some other way. Would that be sufficient to ensure you can read more than 3k? If it does not work on your h/w, try it on a dev board. At least that way if there is an issue, others can try and reproduce it.
shockwave77598
Posts: 22
Joined: Sat May 27, 2017 10:38 am

Re: Problems with EFFS

Post by shockwave77598 »

Test.zip
(22.19 MiB) Downloaded 94 times
Well, I stripped out everything but teh reading. I still have the same issues: It'll read 3K then nothing more.
***
Getting time from NTP
Time set
Starting NanoXmas2023
Seed = 1677975905
Entering SDcard
Mounting drive USE_MMC mode
FAT mount to SD/MMC successful
SD/MMC drive change successful
Entering Endless Loop
LED031.OUT reading
1200 1200 672 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
User avatar
TomNB
Posts: 538
Joined: Tue May 10, 2016 8:22 am

Re: Problems with EFFS

Post by TomNB »

Hello,

Looking at trying something simple on this end to reproduce the issue. Do you think this would cause the same behavior on your design:
- Have four 1MB files on the sdcard
- Open each one at at time,read and print some number of bytes larger than 3k, lets say 10k, close the file
- Repeat

At one point in the thread you mentioned you were getting F_ERR_INVALIDDRIVE, which would mean you can't open/read anything. Has that error gone away?
Post Reply