Hi Lukas
First a question about the file you wish to save.
Are you sure that you need to save it to FLASH (file) and not just keep a copy of the data in RAM?
The actual details involved are a bit HW specific (for example you could be saving to internal FLASH or external FLASH). The rules are different depending on the size of the FLASH granularity (eg. the STR91 will have a granularity of 64k or the SAM7X will have a granularity of 256 bytes). I will assume you are using maybe the LPC23XX since you are setting the ucSubFile parameter when using uFileWrite(), in which case life becomes (unfortunately) even more complicated.
Taking your example: you are opening a file with name "Ulog.TXT", which is basically returning a pointer to its location in memory.
Then you write 6 bytes of data to it.
Then you close the file, meaning that its length is written and its mime type (TXT) set as reference to its content type. This file is now visible in the file system as "U.TXT" and its length can be requested - which will return 6.
The first time this works fine since the FLASH was empty. Unfortunately it is not so easy to add data to the existing contents - to change the file's length it needs to delete the present content (at least 32k on the LPC23XX!). The LPC23XX also doesn't allow a second write to a single line of FLASH (16 bytes) so even a change of the length is impossible without first deleting the entire content first. [see the following for some background on the FLASH in the NXP devices -
http://www.utasker.com/forum/index.php?topic=136.0].
Therefore due to physical restrictions, to add more data to existing data requires the following procedure:
- First write as performed
- Open, read and backup present file data (copy to RAM)
- Add new data to its image in RAM
- Save the new complete data (this will automatically delete the old file and rewrite to same location with new length).
As you see, the uFileSystem is intended mainly for storing files used by the web server where overwrites is the norm and not additions to existing files. This is however possible by using the lower level FLASH interface, where the uFileSystem doesn't actually need to be respected - you can decide to use a physical address range and control it as you wish (but of couse still respecting the physical limitations of the FLASH technology).
Therefore your application may be more suited to first building up the data contents in a simple RAM buffer (declare it on heap using uMalloc() and keep one length variable so that you know where to copy the next data block to (simply using uMemcpy()). If you do want to save this at the end to FLASH as reference the uFileSystem interface will be fine. If you have however in the meantime transferred the data via TCP to a PC then perhaps there is no need to ever store it locally in FLASH...
Good luck
Regards
Mark