cancel
Showing results for 
Search instead for 
Did you mean: 

Can I write data to multiple files using FileX?

Hey0256
Associate II

Hello, everyone on the forum.
I am using an STM32H735IG, ThreadX, and FileX to create files on an SD card and write data to them.

 

In each iteration, I open the file using `fx_file_open`, seek to the end of the file using `fx_file_relative_seek`, write data using `fx_file_write`, close the file using `fx_file_close`, and finally flush the media using `fx_media_flush`.

When performing this operation, each file write takes about 10 milliseconds.

 

If I want to write multiple files in a short amount of time, should I use multithreading and have each thread write a file?

 

Also, when writing data to a file on a regular basis, is it okay to keep the file open and write the data without calling `Open` and `Close`?

How often should I run fx_media_flush?

 

I’d appreciate any advice you can offer.

1 ACCEPTED SOLUTION

Accepted Solutions
AScha.3
Super User

Hi,

>each file write takes about 10 milliseconds.

Depending on the amount you write (you didnt give any number) this is already a "good" time.

If I want to write multiple files in a short amount of time

Just try this on a PC , with a SD-card as target, and check the time. ( = fastest possible on SD...)

Because every command to a card needs about 1ms (0.5...100ms possible), you cannot get much more speed , no matter what you try, the card will not be faster. Fastest way is to write a big block to one file, because after command phase its just the time for data transfer and storing on the card in one block access.

The more different commands you use, the more time it will need to respond to every command, added to the time, needed to transfer data and store it. Depends a lot on type of card and the connection mode (1bit, 4bit, >Both interfaces support the SD memory card specifications version 4.1. and the SDIO card specification version 4.0. in two different databus modes: 1 bit (default) and 4 bits. < from H755 ds)

 

Here a speed check , on PC /Linx , on USB3 (5Gbit possible), to see, what cards doing...

Intenso_16GB_USB3_neu_SDXC_usb3.png

red: write, from 4...60MB/s ; green access time : 0.5 ...10ms . card: Intenso, 16GB , SDHC, class 10 .

The up and down on writing 10MB blocks come from....whatever the card doing internally.

And this is a new card....you dont wanna see, what a 2 y old doing, if all day used for logging data.

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

3 REPLIES 3
Andrew Neil
Super User

@Hey0256 wrote:

If I want to write multiple files in a short amount of time, should I use multithreading and have each thread write a file?


You will still have only 1 physical storage medium; if the bottleneck is writing to the medium, this can't help.

 

Are you using blocking calls for your writes?

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.
AScha.3
Super User

Hi,

>each file write takes about 10 milliseconds.

Depending on the amount you write (you didnt give any number) this is already a "good" time.

If I want to write multiple files in a short amount of time

Just try this on a PC , with a SD-card as target, and check the time. ( = fastest possible on SD...)

Because every command to a card needs about 1ms (0.5...100ms possible), you cannot get much more speed , no matter what you try, the card will not be faster. Fastest way is to write a big block to one file, because after command phase its just the time for data transfer and storing on the card in one block access.

The more different commands you use, the more time it will need to respond to every command, added to the time, needed to transfer data and store it. Depends a lot on type of card and the connection mode (1bit, 4bit, >Both interfaces support the SD memory card specifications version 4.1. and the SDIO card specification version 4.0. in two different databus modes: 1 bit (default) and 4 bits. < from H755 ds)

 

Here a speed check , on PC /Linx , on USB3 (5Gbit possible), to see, what cards doing...

Intenso_16GB_USB3_neu_SDXC_usb3.png

red: write, from 4...60MB/s ; green access time : 0.5 ...10ms . card: Intenso, 16GB , SDHC, class 10 .

The up and down on writing 10MB blocks come from....whatever the card doing internally.

And this is a new card....you dont wanna see, what a 2 y old doing, if all day used for logging data.

If you feel a post has answered your question, please click "Accept as Solution".

Thank you for your advice.

I now understand that there is an upper limit to the file write speed.
I will make sure to write data in block-sized units.

Thank you very much.