Problem slow write speed on sd card

Go To Last Post
10 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I use the EVK 1104 Kit and sd card interface in 4 bit mode Studio 5.1 and ASF2.11.1 USB mass storage example as base project.

I want to write large files max 2Gb on Sandisk ULTRA II cards.
In USB mass storage mode I can write files on SD at 5Mb/s.

Using the fat library and 4K buffer the top speed is 278Kb/s.

What's the difference?

I tried to use a preserve shown in AVR114 application note it took 44s for 40Mb it's to slow for me.
I need to write >1Mb/s

Any Ideas whats the difference between the two access modes?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I offer 500$ for a solution!
I need to save 1Mb/s on SD Card on one big file up to 2Gb.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I suspect that you mean 1MB/s rather than 1Mb/s.
This implies at least 8MHz SPI clock for regular SPI mode. This is regardless of any processing overhead or filesystem housekeeping

8MHz SCK speed is easy to achieve. Your AVR32 should be able to manage the housekeeping.

If you want faster speeds, then you have to use the proprietary interface, and pay the license fees.

Pure guesswork on my part. I have never used AVR32.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

David it is 1M byte/s it is possible to write from pc to sd card in mass storage mode at 5M byte/s.
We use the SDIO controller in 4 Bit parallel mode! look at the mass storage example on EVK1104 board

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I did confess that I have not used the AVR32.

If you have really configured a SDIO controller properly, you should achieve far better throughput.

Regarding housekeeping, just profile your code and see what improvements you can get.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Looks like a problem in HC mode!
I found the HC sdcard is busy after every block transfer for 1,8ms!
In my test the 256MB Toshiba card is the fastest card using 512byte blocks.

[SD type][mode][FAT type][speedgrade][Filesize KB][time][KB / s meas]

Sandisk 1Gb Ultra II, ,FAT16, na, 20000, 52s, 384,6153846
Sandisk 4Gb HC, SD V2 HC, FAT32, 2, 20000, 84s, 238,0952381
TOSHIBA SD- M256, , FAT16, na, 20000, 39s, 512,8205128

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
void sd_performance(void)
{
	static unsigned int uiBlockcnt=80*500;
	unsigned int uiIdx;
	unsigned char ucDat=0;
	unsigned char * pucBuf=aucPicture;
	unsigned int uiErr=0;
	_MEM_TYPE_SLOW_ Fs_file_segment g_rec_seg;
	
	for(uiIdx=0;uiIdx < BLSIZE;uiIdx++)
	{
		*pucBuf = ucDat;
		ucDat++;
		pucBuf++;
	}
	uiRuntime=0;
	uiBlocksize = BLSIZE;				// set block size to default

	// open / create file for write access
	if((uiUsbactive==0)&&(uiBlockcnt>0))
	{	
		if(!nav_drive_set(0))
		{
			uiErr = 1;			
		}		
		if(!nav_partition_mount())
		{
			uiErr |= 2;			
		}		

		if(!nav_file_create((const FS_STRING)"video.avi"))
		{
			uiErr |= 4;			
		}		

		if(!file_open(FOPEN_MODE_W))
		{
			uiErr |= 8;			
		}		

		g_rec_seg.u16_size = ((80*500*BLSIZE+512L)/512L);
		
		if(!file_write(&g_rec_seg))
		{
			file_close();
			uiErr |= 0x10;
		}

		if(g_rec_seg.u16_size  < ((80*500*BLSIZE+512L)/512L))
		{
			file_close();
			uiErr |= 0x20;
		}

		file_close();
		uiRuntime=0;
		if(file_open(FOPEN_MODE_W))
		{
			while (uiBlockcnt)
			{

				file_write_buf(aucPicture,uiBlocksize);	
				uiBlockcnt--;
			}		
			file_close();
		}	
				
	}		
}
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is it possible that HC mode needs a specific command sequence to run at full speed?

Are there bugs in the software framework 2.11 concerning HC SD mode?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've got a project using a EVK1104 (and now a custom board) that reads at 13-15 MB/s, and writes at about 5 MB/s. I think the speeds might go higher if I used better (faster) SD cards, but these were sufficient for my needs, and cheap.

I suggest looking at how some of the ASF example projects read/write the SD Card. I suspect your problem is in the buffering. If you're not using DMA to transfer from USB to SD (or reverse) then you're going to get super bogged down by having the MCU handle every block transfer manually.

Do you need the MCU to write FAT files? The USB Mass Storage Demo just presents a raw block device to the computer, so your computer gets to deal with the filesystem. This is much faster. Also, check out FatFS. It won't play nicely without some heavy modification, but I've modified it to use DMA and get my "fast" speeds.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok I did the modification found in
https://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&p=714305
thank's to jiangzhiyong for the given information.

After that transfer to SD speeds up to 570KB/s at 4KB block size.
The first improvement was writing multiple blocks at a time.

My main problem is the 4GB Sandisk HC (2) card is slower than a 1Gb Sandisk ULTRA II.

I need to double the speed on HC card!