Just getting started using the tinkerer kit, and I’ve been playing around with the SD card.
I wrote some code based on the example code given in the FEZ Beginners Guide to the .NET Micro Framework…The code simply writes to a FileStream object in a loop, until we’ve written 1 MB.
The program takes a lot longer to complete than I expected (around a minute). Is there any information available about SD write performance, optimizing writes, etc, etc? I’m new to the whole FEZ world, so I’m not sure what to expect.
Patriot 2GB SD (no class specification) : ~ 54 seconds
SanDisk 2GB micro SD (no class specification): ~33 seconds
SanDisk 4GB micro SDHC Class 2: ~33 seconds
SanDisk 4GB micro SDHC Class 4: ~23 seconds
Patriot 4GB micro SDHC Class 10: ~41 seconds
All cards had been been formatted before testing using FAT32.
using System;
using System.Threading;
using System.Text;
using Microsoft.SPOT;
using System.IO;
using Microsoft.SPOT.IO;
using GHIElectronics.NETMF.IO;
namespace FEZ_Panda_Application1
{
public class Program
{
static void Main()
{
int i;
byte[] ba = new byte[1024];
DateTime start_time;
DateTime end_time;
TimeSpan ts;
// Generate some junk to write
for (i = 0; i < 1024; i++)
ba[i] = (byte)(i % 255);
PersistentStorage sdPS = new PersistentStorage("SD");
sdPS.MountFileSystem();
string rootDirectory = VolumeInfo.GetVolumes()[0].RootDirectory;
FileStream FileHandle = new FileStream(rootDirectory + @ "\hello.txt", FileMode.Create);
start_time = DateTime.Now;
for (i = 0; i < 1024; i++)
{
FileHandle.Write(ba, 0, 1024);
}
end_time = DateTime.Now;
FileHandle.Close();
sdPS.UnmountFileSystem();
ts = end_time - start_time;
Debug.Print(ts.ToString());
// ...
Thread.Sleep(Timeout.Infinite);
}
}
}
I just tried the same test, but ran it twice back to back (without restarting the application). I’m assuming (perhaps incorrectly??) that this should eliminate the issue of boot delays / file system ready, etc.
First test ran in 34 seconds
Second test ran in 33 seconds.
So, it seems to fall within the same margin of error I’ve noticed with my previous tests.
Procedure:
Mount file system
Open File
Start 1st loop to write 1024 * 1024 (~34 sec)
Start 2nd loop to write 1024 * 1024 (~33 sec)
Close File
Unmount file system
Have you tried running the program without debugging?
You could write the timing values back to the SD card and run the board from an external power supply.
using System;
using System.IO;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.IO;
using GHIElectronics.NETMF.IO;
using GHIElectronics.NETMF.FEZ;
using GHIElectronics.NETMF.Hardware;
using GHIElectronics.NETMF.USBHost;
namespace FEZ_Panda_Application1
{
public class Program
{
static byte[] ba = new byte[1024];
static DateTime start_time;
static TimeSpan ts;
public static void writeSD()
{
// ...
// SD Card is inserted
// Create a new storage device
PersistentStorage sdPS = new PersistentStorage("SD");
int i;
for (i = 0; i < 1024; i++)
{
ba[i] = (byte)(i % 255);
}
// Mount the file system
sdPS.MountFileSystem();
string rootDirectory = VolumeInfo.GetVolumes()[0].RootDirectory;
FileStream FileHandle = new FileStream(rootDirectory + @ "\hello.txt", FileMode.Create);
for (i = 0; i < 1024; i++)
{
FileHandle.Write(ba, 0, 1024);
}
FileHandle.Close();
sdPS.UnmountFileSystem();
}
public static void Main()
{
//Start measure
start_time = DateTime.Now;
writeSD();
ts = DateTime.Now - start_time;
Debug.Print("Write file to SD in: " + ts);
}
}
}
I tried copying/pasting the code provided by Sam, and ran it on my Tinkerer kit. Ran the test three times, and got results in the 40-45 second range.
And, as suggested by Geir in an earlier post, I did try running outside the debugger, and wrote the results to the SD card. The results were no different than running with the debugger.
I’m going to keep playing around with things. If anyone can think of anything else to try in meantime, please let me know.
I know, but just wanted to eliminate another variable in case there was something stupid about my code.
I watched the YouTube video you posted in your earlier response. Unless I’m not understanding something, the hardware connections should be same between what was shown in the video, and what I have on my Panda base board, correct?
I tried Peddy’s original code on a TwinMOS Ultra-X 1Gb 150x card and the write took 9.64 sec.
The card is formated as FAT16 (not FAT32).
It seems to be related to either the SD card type or the format. The code seems good.
One other variable is the hardware. It seems unlikely given the design, but more likely given the results, that maybe there is something about the specific build of the tinkerer board that is influencing the performance. I am really looking forward to hearing from GHI about what they are finding as they try to reproduce the results. I may have to buy one of the SD Expansion boards to hook straight up to a Panda and test.