SD Card Emulator

Is there a way to emulate the SD card in the emulator before running on the Fez?

I have a data file that will be on the SD card and I want to first put it on emulated storage and debug the code.

Is that possible?

Yes you can use file system on emulator. There is no “PresitantStorage” class but everything else is the same. See examples that ship with NETMF in “my documents” on your PC

HI Gus,

I Looked at this example you suggested (a good one btw), but under emulation it starts by creating a formatted blank SD card image.

I think what’s being asked is how can the image be “pre-loaded” with files (eg. config.xml, …). In case you’re trying to emulate particular support issue, and replicate their problem with live data.

Is there a way to pre-load data from existing Host System [MS-Windows or similar] files?

Can you force the emulator to pre-load a specific *.dat file from a range of files.?

I am at the same point. And have’t got past this.

I personally never bothered much with emulator as hardware is cheap and makes more sense for embedded devices.

Hi Gus,

My XML Loader takes around 60 seconds to load each time I debug, so emulation would be something to aid in speeding up development.

So if there are any suggestions on how to do it would be appreciated.

In mean time I am trying to load the structure to extended weak reference flash, so I don’t need to load every time. But not there yet.

Regards
Ian

8 months - long time for a thread to come back to life :slight_smile:

Anyway, here’s how I solved this.

Enable WINFS in Emulator.config: (only the bits related to WINFS is shown)

<?xml version="1.0" encoding="utf-8"?> Microsoft.SPOT.Emulator.Gpio.GpioPort Microsoft.SPOT.Emulator.Lcd.LcdDisplay Microsoft.SPOT.Emulator.FS.WindowsFileSystem Microsoft.SPOT.Emulator.FS.AsyncWindowsFileSystem Microsoft.SPOT.Emulator.BlockStorage.Region Microsoft.SPOT.Emulator.BlockStorage.BlockRange Microsoft.SPOT.Emulator.BlockStorage.EmulatorBlockStorageDevice Microsoft.SPOT.Emulator.BlockStorage.EmulatorRemovableBlockStorageDevice Microsoft.SPOT.Emulator.FS.NativeFileSystem Microsoft.SPOT.Emulator.Memory.RamManager 8388608
<BSDevice id="OnBoardFlash">
  <MaxSectorWriteTime>500</MaxSectorWriteTime>
  <MaxBlockEraseTime>2000</MaxBlockEraseTime>
  <PersistanceFilename>OnBoardFlash.dat</PersistanceFilename>
  <BytesPerSector>2048</BytesPerSector>
  <Regions>
    <BSRegion>
      <BytesPerBlock>131072</BytesPerBlock>
      <BlockRanges>
        <BSBlockRange>
          <RangeType>Usage_Config</RangeType>
          <StartBlock>0</StartBlock>
          <BlockCount>1</BlockCount>
        </BSBlockRange>
        <BSBlockRange>
          <RangeType>Usage_Deployment</RangeType>
          <StartBlock>1</StartBlock>
          <BlockCount>10</BlockCount>
        </BSBlockRange>
        <BSBlockRange>
          <RangeType>Usage_Deployment</RangeType>
          <StartBlock>11</StartBlock>
          <BlockCount>10</BlockCount>
        </BSBlockRange>
        <BSBlockRange>
          <RangeType>Usage_Deployment</RangeType>
          <StartBlock>21</StartBlock>
          <BlockCount>10</BlockCount>
        </BSBlockRange>
        <BSBlockRange>
          <RangeType>Usage_Deployment</RangeType>
          <StartBlock>31</StartBlock>
          <BlockCount>10</BlockCount>
        </BSBlockRange>
        <BSBlockRange>
          <RangeType>Usage_Deployment</RangeType>
          <StartBlock>41</StartBlock>
          <BlockCount>10</BlockCount>
        </BSBlockRange>
        <BSBlockRange>
          <RangeType>Usage_FileSystem</RangeType>
          <StartBlock>51</StartBlock>
          <BlockCount>510</BlockCount>
        </BSBlockRange>
        <BSBlockRange>
          <RangeType>Usage_Storage_A</RangeType>
          <StartBlock>562</StartBlock>
          <BlockCount>1</BlockCount>
        </BSBlockRange>
        <BSBlockRange>
          <RangeType>Usage_Storage_B</RangeType>
          <StartBlock>563</StartBlock>
          <BlockCount>1</BlockCount>
        </BSBlockRange>
      </BlockRanges>
    </BSRegion>
  </Regions>
</BSDevice>

<NativeFS id="FATFS">
  <Namespace>ROOT</Namespace>
  <FileSystemName>FAT</FileSystemName>
  <BlockStorageDeviceComponentId>OnBoardFlash</BlockStorageDeviceComponentId>
  <VolumeId>0</VolumeId>
  <Label>FATFS</Label>
  <SerialNumber>100005</SerialNumber>
</NativeFS>

<RemovableBSD id="SD1">
  <Namespace>SD1</Namespace>
  <MaxSectorWriteTime>500</MaxSectorWriteTime>
  <MaxBlockEraseTime>2000</MaxBlockEraseTime>
</RemovableBSD>

<RemovableBSD id="SD2">
  <Namespace>SD2</Namespace>
  <MaxSectorWriteTime>500</MaxSectorWriteTime>
  <MaxBlockEraseTime>2000</MaxBlockEraseTime>
  
  
</RemovableBSD>

<WinFS id="WinFS">
  <Namespace>WINFS</Namespace>
  <BufferingStrategy>SyncIO</BufferingStrategy>
  <CanRead>true</CanRead>
  <CanWrite>true</CanWrite>
  <CanSeek>true</CanSeek>
  <Label>WinFS0</Label>
  <SerialNumber>100000</SerialNumber>
  <TotalSize>20000000</TotalSize>
</WinFS>

When you run the app in the emulator, you’ll see a folder created in the same place as your project file:
DOTNETMF_FS_EMULATION\WINFS

Copy your files here and they will appear on the “SD card” when it is mounted.

It is a real time saver if you have a lot of file I/O development to do. Debugging straight on the hardware is painful - especially over the Serial port - so the emulator does make a difference here.

I see. In this case, I would write part of my program that is “hardware independent” on the standard Microsoft emulator to debug it before I move it to the device.

Thanks Realiser - will give this a go tomorow

Works a treat: Thanks a lot I owe you a beer.

FYI: for others:

a) This WINFS volume automatically loads on start of emulator.

b) Need to re-jig your code to use different name:


 #if MICROSOFT_EMULATION
        public static string SD_VOLUME = @ "\WINFS\";
 #else
        public static string SD_VOLUME = @ "\SD\";
 #endif

PS: MICROSOFT_EMULATION is my own custom #define

Would love to know how you found out about this as both reference books don’t mention SD card emulation or WINFS! as far as I can see (which is disappointing).

As far as I remember I looked at the code in the Custom Emulator example that comes with the SDK.

If there is someone out there interested in the emulator, I have some serious problems to solve and I’d like some help… For example how to emulate a 16x2 character LCD.