This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320C5535: SDHC Card read/write speed

Part Number: TMS320C5535

Hello All.

 I use eZdsp USB Kit with TMS320C5535 MCU and CCS with CSL_MMCSD_SdCardExample_Out example.

 In my project I need periodicaly write a data to SDHC Card of 32GB with general speed of 250kB/s. As I know SDHC Card interface is possible to support more speedy write stream, but I cannot get speed more than 40kB/s (it was the best result) in my application and in the test application too.

I show here the source file of the test program with my little changes that were done for multiply writing only. I calculated the speed by measuring time between " >>>>  START WRITING  <<<<" and " >>>>  FINISH WRITING  <<<<" debug print. Other files did not change.

Where did I have an error? How can I increase the transfer data speed?

Thank you in advance.

/**
 *  \brief  Tests SD card operation in POLLED mode
 *
 *   This function configures the MMCSD module in POLLED mode and
 *   verifies the operation with SD Card. Function returns failure
 *   incase of no SD card is detected.
 *
 *  \param  none
 *
 *  \return Test result
 */
CSL_Status CSL_sdCardPollTest(void)
{
	CSL_Status	 mmcStatus;
	Uint16		 count;
	Uint16		 actCard;
	Uint32       sectCount;
	Uint32       cardAddr;
	Uint16       clockDiv;
	Uint16       rca;
	Uint32       cardStatus;
	Uint32    loop;
	sectCount = 0;

	/* Initialize data buffers */
	for(count = 0; count < (BUFFER_MAX_SIZE/2); count++)
	{
	    pReadBuff[count]   = 0x0;
		pWritedBuff[count] = count;
	}

	/* Get the clock divider value for the current CPU frequency */
	clockDiv = computeClkRate();

	/* Initialize the CSL MMCSD module */
	mmcStatus = MMC_init();
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_init Failed\n");
		return(mmcStatus);
	}

    mmcStatus = SYS_setEBSR(CSL_EBSR_FIELD_SP0MODE,
                            CSL_EBSR_SP0MODE_0);
    mmcStatus |= SYS_setEBSR(CSL_EBSR_FIELD_SP1MODE,
                             CSL_EBSR_SP1MODE_0);
    if(CSL_SOK != mmcStatus)
    {
        printf("SYS_setEBSR failed\n");
        return (mmcStatus);
    }

	/* Open the MMCSD module in POLLED mode */
#ifdef C5515_EZDSP
	mmcsdHandle = MMC_open(&pMmcsdContObj, CSL_MMCSD1_INST, CSL_MMCSD_OPMODE_POLLED, &mmcStatus);
#else
	mmcsdHandle = MMC_open(&pMmcsdContObj, CSL_MMCSD0_INST, CSL_MMCSD_OPMODE_POLLED, &mmcStatus);
#endif
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_open Failed\n");
		return(mmcStatus);
	}
	else
	{
		printf("API: MMC_open Successful\n");
	}

	/* Send CMD0 to the card */
	mmcStatus = MMC_sendGoIdle(mmcsdHandle);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_sendGoIdle Failed\n");
		return(mmcStatus);
	}

	/* Check for the card */
    mmcStatus = MMC_selectCard(mmcsdHandle, &mmcCardObj);
	if((mmcStatus == CSL_ESYS_BADHANDLE) ||
	   (mmcStatus == CSL_ESYS_INVPARAMS))
	{
		printf("API: MMC_selectCard Failed\n");
		return(mmcStatus);
	}

	/* Verify whether the SD card is detected or not */
	if(mmcCardObj.cardType == CSL_SD_CARD)
	{
		printf("SD card Detected!\n");

		/* Check if the card is high capacity card */
		if(mmcsdHandle->cardObj->sdHcDetected == TRUE)
		{
			printf("SD card is High Capacity Card\n");
			printf("Memory Access will use Block Addressing\n\n");

			/* For the SDHC card Block addressing will be used.
			   Sector address will be same as sector number */
			cardAddr = sectCount;
		}
		else
		{
			printf("SD card is Standard Capacity Card\n");
			printf("Memory Access will use Byte Addressing\n\n");

			/* For the SD card Byte addressing will be used.
			   Sector address will be product of  sector number
			   and sector size */
			cardAddr = (sectCount)*(CSL_MMCSD_BLOCK_LENGTH);
		}
	}
	else
	{
		/* Check if No card is inserted */
		if(mmcCardObj.cardType == CSL_CARD_NONE)
		{
			printf("No Card Detected!\n");
		}
		else
		{
			printf("SD card is not Detected!\n");
		}

		printf("Please Insert SD card!!\n");
		return(CSL_ESYS_FAIL);
	}

	/* Set the init clock */
    mmcStatus = MMC_sendOpCond(mmcsdHandle, 70);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_sendOpCond Failed\n");
		return(mmcStatus);
	}

	/* Send the card identification Data */
	mmcStatus = SD_sendAllCID(mmcsdHandle, &sdCardIdObj);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: SD_sendAllCID Failed\n");
		return(mmcStatus);
	}

	/* Set the Relative Card Address */
	mmcStatus = SD_sendRca(mmcsdHandle, &mmcCardObj, &rca);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: SD_sendRca Failed\n");
		return(mmcStatus);
	}

	/* Read the SD Card Specific Data */
	mmcStatus = SD_getCardCsd(mmcsdHandle, &sdCardCsdObj);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: SD_getCardCsd Failed\n");
		return(mmcStatus);
	}

	/* Set bus width - Optional */
	mmcStatus = SD_setBusWidth(mmcsdHandle, 1);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: SD_setBusWidth Failed\n");
		return(mmcStatus);
	}

	/* Disable SD card pull-up resistors - Optional */
	mmcStatus = SD_configurePullup(mmcsdHandle, 0);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: SD_configurePullup Failed\n");
		return(mmcStatus);
	}

	/* Set the card type in internal data structures */
	mmcStatus = MMC_setCardType(&mmcCardObj, mmcCardObj.cardType);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_setCardType Failed\n");
		return(mmcStatus);
	}

	/* Set the card pointer in internal data structures */
	mmcStatus = MMC_setCardPtr(mmcsdHandle, &mmcCardObj);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_setCardPtr Failed\n");
		return(mmcStatus);
	}

	/* Get the number of cards */
	mmcStatus = MMC_getNumberOfCards(mmcsdHandle, &actCard);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_getNumberOfCards Failed\n");
		return(mmcStatus);
	}

	/* Set clock for read-write access */
    mmcStatus = MMC_sendOpCond(mmcsdHandle, clockDiv);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_sendOpCond Failed\n");
		return(mmcStatus);
	}

	/* Set Endian mode for read and write operations */
  	mmcStatus = MMC_setEndianMode(mmcsdHandle, CSL_MMCSD_ENDIAN_LITTLE,
  	                              CSL_MMCSD_ENDIAN_LITTLE);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_setEndianMode Failed\n");
		return(mmcStatus);
	}

	/* Set block length for the memory card
	 * For high capacity cards setting the block length will have
	 * no effect
	 */
	mmcStatus = MMC_setBlockLength(mmcsdHandle, CSL_MMCSD_BLOCK_LENGTH);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_setBlockLength Failed\n");
		return(mmcStatus);
	}
	printf(" >>>>  START WRITING   <<<<\n");

	for(loop = 0; loop < 5000; loop++)
	{
		if (mmcCardObj.sdHcDetected)
		{
		   cardAddr = loop*(BUFFER_MAX_SIZE/512) + (0x20000/512);
		}else{
		   cardAddr = loop*BUFFER_MAX_SIZE + 0x20000;
		}

		/* Write data to the SD card */
		mmcStatus = MMC_write(mmcsdHandle, cardAddr, BUFFER_MAX_SIZE, pWritedBuff);
		if(mmcStatus != CSL_SOK)
		{
			printf("API: MMC_write Failed\n");
			return(mmcStatus);
		}
		//else
		//{
			//printf("API: MMC_write Successful\n");
		//}
	}
	printf(" >>>>  FINISH WRITING  <<<<\n");

	/* Read data from the SD card */
	for(loop = 0; loop < 5000; loop++)
	{
		if (mmcCardObj.sdHcDetected)
		{
		   cardAddr = loop*(BUFFER_MAX_SIZE/512) + (0x20000/512);
		}else{
		   cardAddr = loop*BUFFER_MAX_SIZE + 0x20000;
		}
		mmcStatus = MMC_read(mmcsdHandle, cardAddr, BUFFER_MAX_SIZE, pReadBuff);
		if(mmcStatus != CSL_SOK)
		{
			printf("API: MMC_read Failed\n");
			return(mmcStatus);
		}
		//else
		//{
		//	printf("API: MMC_read Successful\n");
		//}

		/* Compare the MMC read and write buffers */
			for(count = 0; count < (BUFFER_MAX_SIZE / 2); count++)
			{
				if(pReadBuff[count] != pWritedBuff[count])
				{
					printf("\nBuffer miss matched at position %d\n",count);
					return(CSL_ESYS_FAIL);
				}
			}
	}

	/* Get card stataus */
	mmcStatus = MMC_getCardStatus(mmcsdHandle, &cardStatus);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_getCardStatus Failed\n");
		return(mmcStatus);
	}

	/* Deselect the SD card */
	mmcStatus = MMC_deselectCard(mmcsdHandle, &mmcCardObj);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_deselectCard Failed\n");
		return(mmcStatus);
	}

	/* Clear the MMCSD card response registers */
	mmcStatus = MMC_clearResponse(mmcsdHandle);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_clearResponse Failed\n");
		return(mmcStatus);
	}

	/* Send CMD0 to the SD card */
	mmcStatus = MMC_sendCmd(mmcsdHandle, 0x00, 0x00, CSL_MMCSD_EVENT_EOFCMD);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_sendCmd Failed\n");
		return(mmcStatus);
	}

	/* Close the MMCSD module */
	mmcStatus = MMC_close(mmcsdHandle);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_close Failed\n");
		return(mmcStatus);
	}
	else
	{
		printf("API: MMC_close Successful\n");
	}



	printf("\nSD Card Read & Write Buffer Matched\n");

	return(CSL_SOK);
}