Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT




Loading

How can make a new file in FAT file system

Posted by zealhero on 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.


How can make a new file in FAT file system

Posted by rtel on 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: prvCreateDemoFilesUsingfwrite() and prvCreateDemoFileUsingfputc().

Then, inside prvCreateDemoFilesUsingfwrite() 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/FreeRTOSPlusFATSL/API/fopen.shtml http://pubs.opengroup.org/onlinepubs/009695399/functions/fopen.html

Regards.


How can make a new file in FAT file system

Posted by zealhero on 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 "fsetfsname(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.


How can make a new file in FAT file system

Posted by rtel on 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 fsetfsname() function.

Inside that function the line "ch = ftoupper( *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.


How can make a new file in FAT file system

Posted by zealhero on June 19, 2014

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

That error occure when pass the 1st, 2nd line of fsetfsname 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.


How can make a new file in FAT file system

Posted by davedoors on 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?


How can make a new file in FAT file system

Posted by zealhero on 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 fsetfsname(const char * name, FNAME * fsname) 287 { 288 char s[FMAXPATH]; 289 unsigned char namepos = 0; 290 291 unsigned char pathpos = 0; . .

My program going well until this function(fsetfsname)) 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.


How can make a new file in FAT file system

Posted by davedoors on June 20, 2014

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


How can make a new file in FAT file system

Posted by zealhero on June 20, 2014

configCHECKFORSTACK_OVERFLOW is 2


How can make a new file in FAT file system

Posted by davedoors on 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?


How can make a new file in FAT file system

Posted by zealhero on June 20, 2014

you mean configCHECKFORSTACK_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..


How can make a new file in FAT file system

Posted by rtel on June 20, 2014

you mean configCHECKFORSTACK_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:

http://www.freertos.org/a00125.html

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.


How can make a new file in FAT file system

Posted by zealhero on 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.


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS