freeRTOS-plus-fat FF_Close() function hangs / does not return

Sometimes the FAT FS function FF_Close() does not return or returns the error code 0x82030034.

Any ideas as to why?

Thanks,
Stephen

I presume this is a low level error code rather than an errno. In which case the last 16-bits show this is an FF_ERR_DIR_END_OF_DIR error - and the other bits will give you more information as to where the error occurred.

When the function doesn’t return, if you pause on the debugger what is the function executing?

Dear Richard,

Thanks for your response and help.

Tracing through the code shows in function FF_FetchEntryWithContext() (called from FF_GetEntry() which is called from FF_Close()), the buffer pEntryBuffer is populated with zeros.

The call from FF_FetchEntryWithContext() returns no error.

All of the files are saved at the root level. I’m using an SD card with an SPI driver (I’ve written). Files are being successfully saved, but close fails.

Thanks,
Stephen.

Not an answer to your problem, but as a bit of general advice from someone who’s been there, if you haven’t already done so, I highly recommend testing your driver at low level with something like ChaN’s “Low level disk I/O module function checker” (http://elm-chan.org/fsw/ff/res/app4.c). (See freeRTOS-Plus-FAT file library - corrupted files.)

EDIT:
You can find a version adapted to my FreeRTOS+FAT driver here: app4-IO_module_function_checker.c

Make sure that passes cleanly before trying to debug at the filesystem level.

Richard wrote:

I presume this is a low level error code rather than an errno 1

That is true for the high-level access functions defined in ff_stdio.c. Those function may return a negative errno value.

The FAT driver itself puts more information in the return code, which is helpful for debugging. It tells the module, the function and the type of error that has occurred.

Make sure that ffconfigDEBUG is defined, andthen you can analyse the return code with :

const char *FF_GetErrDescription( FF_Error_t iErrorCode, char *pcBuffer, int iMaxLength );

This function is defined in ff_error.h.

Sometimes the FAT FS function FF_Close() does not return

When it hangs, can you halt the CPU and see what it is doing? Do you know how far it has got?

Are you sure that the file handle is not in use by another task, and that the handle has not been closed before?