How can make a new file in FAT file system

zealhero wrote on Wednesday, June 18, 2014:

Hi.
I’m making a project with FreeRTOS+FAT SL.
I refered window simulator demo and tested it.
FAT was imported on my CCS project and make some codes for init volume, format, read, and etc…
But it was not worked. I’m using RM48 MCU.

I don’t know how can make a new file like a ‘test.txt’.

I think there is not making a new file API.

rtel wrote on Wednesday, June 18, 2014:

The file system has a fairly standard API, so files are created in the same way they would be with any other standard file system. Also, if you have the Win32 simulator demo running, and step through the code, you will see the files being created - as it uses a RAM disk when the disk is initialised there are no files on it, then there is a loop that creates the files, then loops that read back from the files to ensure they are correct, plus CLI commands to copy files (which involves creating a new file), etc.

In the Win32 simulator demo, find the file File-system-demo.c, then in that file find the function vCreateAndVerifySampleFiles(). That function calls two further functions: prvCreateDemoFilesUsing_f_write() and prvCreateDemoFileUsing_f_putc().

Then, inside prvCreateDemoFilesUsing_f_write() you will see lines such as:


/* Open the file, creating the file if it does not already exist. */
pxFile = f_open( cFileName, "w" );

…so you can see that files are automatically created if an attempt is made to open a file that does not exist.

http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_FAT_SL/API/f_open.shtml
http://pubs.opengroup.org/onlinepubs/009695399/functions/fopen.html

Regards.

zealhero wrote on Thursday, June 19, 2014:

Thanks.
I’m trying it.

Another problem occured…

It is occure when I use this.

pxFile = f_open( cFileName, “w”);

Everything going well… but “_f_setfsname(filename, &fsname)” makes error.
There is 430 line in file.c

I use ‘step into’ when I debugging, and I found strange phenomenon…

There is value at ‘name’ that input argument, until line 287 in util_sfn.c
But it is disappear suddenly. Then I see “Error: Memory map prevented reading 0x07FFFFF8” ‘Value’ in ‘Variables window’ when it goes line 289.

Please tell me, if you need more information

Thanks
Regards.

rtel wrote on Thursday, June 19, 2014:

If you are going to use line numbers please also specify which version of the file you are using. In my version line 430 is in the middle of a large comment, outside of a function.

I’m afraid I don’t fully understand what you are saying in your post, but I think you are saying that the parameter ‘name’ is getting corrupted inside the _f_setfsname() function.

Inside that function the line “ch = _f_toupper( *name++ );” is incrementing through the character string pointed to by name, so when viewed in the debugger the string will appear to get shorter and shorter until it does not exist (just the terminating null).

Regards.

zealhero wrote on Thursday, June 19, 2014:

I’m sorry. I’m not skilled with English.
The problem happen at start of ‘_f_setfsname’ function. So it cannot reach ‘toupper’.

That error occure when pass the 1st, 2nd line of _f_setfsname function.
it is just declare variables… So I don’t know what is problem…

char s[F_MAXPATH];
unsigned char namepos = 0;

Why parameter ‘name’ and ‘fsname’ are disappear when it pass that declaration…

Regards.

davedoors wrote on Thursday, June 19, 2014:

It is declaring a char array on the stack. How big is F_MAXPATH? Do you have stack overflow checking turned on in FreeRTOSConfig.h?

zealhero wrote on Thursday, June 19, 2014:

F_MAXPATH is 64… my file name is about 10 words.

I cannot copy and paste my code because security program in my pc. I type it…

This is util_sfn.c line 286~.

.
.
286 unsigned char _f_setfsname(const char * name, F_NAME * fsname)
287 {
288 char s[F_MAXPATH];
289 unsigned char namepos = 0;
290
291 unsigned char pathpos = 0;
.
.

My program going well until this function(_f_setfsname))
There are values in input parameter ‘name’ and ‘fsname’ when it stop line 287 in debugging mode.

When I click the ‘Step into’ and move to line 289, problem is occured I described in previous post.
‘name’ and ‘fsname’ disappear.

Regards.

davedoors wrote on Friday, June 20, 2014:

Again, “Do you have stack overflow checking turned on in FreeRTOSConfig.h?”

zealhero wrote on Friday, June 20, 2014:

configCHECK_FOR_STACK_OVERFLOW is 2

davedoors wrote on Friday, June 20, 2014:

All the same I would try increasing the stack size of the task calling f_open(). What is the size? Does the problem still exist if you multiply the size by 4?

zealhero wrote on Friday, June 20, 2014:

you mean configCHECK_FOR_STACK_OVERFLOW 4?

I cannot test it now. I will do it next monday.

Is that size meaning file size?

There is empty. I’m making a new file. so ‘filename’ name of new file…

rtel wrote on Friday, June 20, 2014:

you mean configCHECK_FOR_STACK_OVERFLOW 4?

No, leave that at 2. Dave is suggesting that, because an array is being allocated on the task stack, you may need to increase the size of the stack used by the task to accommodate it.

The size of the stack allocated to a task is set when the task is created. See the usStackDepth parameter on the following page:

Go to the line of code that creates the task that uses the file system, and increase the size of the usStackDepth parameter by a factor of 4.

Regards.

zealhero wrote on Monday, June 23, 2014:

I analyze my project again and I found another mistake…

Thank you for your help.
Those are really helpful to me.

Regards.