示例#1
0
/* Read Sector(s)                                                        */
DRESULT disk_read (
	BYTE drv,		/* Physical drive nmuber (0..) */
	BYTE *buff,		/* Data buffer to store read data */
	DWORD sector,	/* Sector address (LBA) */
	BYTE count		/* Number of sectors to read (1..255) */
)
{
	SD_Error Status; 

	if (!count) return RES_PARERR;  //count不能等于0,否则返回参数错误

	if(drv==0)
	{		
 		switch(SD_Mode)
	  	{
	   		case 0:  //dma方式
	      		if(count==1)// 1个sector的读操作      
	      		{      
	    			Status = SD_ReadBlock(sector << 9,(u32 *)(&buff[0]),BlockSize);//sector<<9 扇区地址转为字节地址 一个扇区512字节                                    
	      		}                                                
	      		else                    //多个sector的读操作     
	      		{    
	       			Status = SD_ReadMultiBlocks(sector << 9,(u32 *)(&buff[0]),BlockSize,count);                                      
	      		}
	     		break;
	     		
	  		case 1:  //中断方式
	      		if(count==1)            // 1个sector的读操作      
	      		{      
	    			Status = SD_ReadBlock(sector<<9,(u32 *)(&buff[0]),BlockSize);                                              
	      		}                                                
	      		else                    //多个sector的读操作     
	      		{    
	       			Status = SD_ReadMultiBlocks(sector<<9 ,(u32 *)(&buff[0]),BlockSize,count);                                     
	      		}  	  
	      		break;
	      		
	    	default:
	    		Status=SD_ERROR;
		}
		
	    //处理返回值,将sdcard.c的返回值转成ff.c的返回值
	    if(Status == SD_OK)
	        return RES_OK;
	    else
	        return RES_ERROR;
	}
	else//仅支持磁盘0的操作
    {
		return RES_ERROR;  
    }
}
示例#2
0
/*******************************************************************************
* Function Name  : MAL_Read
* Description    : Read sectors
* Input          : None
* Output         : None
* Return         : Buffer pointer
*******************************************************************************/
uint16_t MAL_Read(uint8_t lun, uint32_t Memory_Offset, uint32_t *Readbuff, uint16_t Transfer_Length)
{

  switch (lun)
  {
    case 0:
#ifdef USE_STM3210E_EVAL
      Status = SD_ReadBlock(Memory_Offset, Readbuff, Transfer_Length);
      if ( Status != SD_OK )
      {
        return MAL_FAIL;
      }
#else
      MSD_ReadBlock((uint8_t*)Readbuff, Memory_Offset, Transfer_Length);
#endif
      break;
#ifdef USE_FSMC_NAND
    case 1:
      NAND_Read(Memory_Offset, Readbuff, Transfer_Length);
      break;
#endif
    default:
      return MAL_FAIL;
  }
  return MAL_OK;
}
示例#3
0
/**
 * @brief Tests the SD card Single Blocks operations.
 * @param None
 * @retval None
 */
static void SD_SingleBlockTest(void)
{
    SD_Error status;
    /*---------------Block Read/Write----------------*/
    /* Fill the buffer to send */
    Fill_Buffer(aBuffer_Block_Tx, BLOCK_SIZE, 0x320F);

    /* Write Block of 512 bytes on address 0 */
    status = SD_WriteBlock(aBuffer_Block_Tx, 0x00, BLOCK_SIZE);
    /* check if the Transfer finished */
    status = SD_WaitWriteOperation();
    while(SD_GetStatus() != SD_TRANSFER_OK);

    if(status == SD_OK)
    {
	/* Read Block of 512 bytes on address 0 */
	status = SD_ReadBlock(aBuffer_Block_Rx, 0x00, BLOCK_SIZE);
	/* check if the Transfer finished */
	status = SD_WaitReadOperation();
	while(SD_GetStatus() != SD_TRANSFER_OK);
    }

    /* Check the correctness of written data */
    if(status == SD_OK)
    {
	TransferStatus1 = Buffercmp(aBuffer_Block_Tx, aBuffer_Block_Rx,BLOCK_SIZE);
    }

    if(TransferStatus1 == PASSED) printf("SD single block test passed!\n\r");
}
示例#4
0
/*-----------------------------------------------------------------------*/
DRESULT disk_read (
	BYTE pdrv,		/* Physical drive nmuber (0..) */
	BYTE *buff,		/* Data buffer to store read data */
	DWORD sector,	/* Sector address (LBA) */
	UINT count		/* Number of sectors to read (1..128) */
)
{
	SD_Error Status;

  if(pdrv || !count)
    return RES_PARERR;

	if(count==1)
		Status = SD_ReadBlock(buff ,sector<< 9 , SDCardInfo.CardBlockSize );                                                              
	else
		Status = SD_ReadMultiBlocks(buff ,sector<< 9 ,SDCardInfo.CardBlockSize,count);

  /* Check if the Transfer is finished */
  Status = SD_WaitReadOperation();
  while(SD_GetStatus() != SD_TRANSFER_OK);

	if(Status == SD_OK)
		return RES_OK;
	else
		return RES_ERROR;
}
示例#5
0
DRESULT disk_read (
	BYTE drv,		/* Physical drive nmuber (0..) */
	BYTE *buff,		/* Data buffer to store read data */
	DWORD sector,	/* Sector address (LBA) */
	BYTE count		/* Number of sectors to read (1..255) */
)
{
	
	

	if(count==1)
  {
         err1 = SD_ReadBlock( &buff[0], sector , SECTOR_SIZE );
		
				 SD_WaitReadOperation();
		
         while(SD_GetStatus() != SD_TRANSFER_OK);
		
	}
	else
  {
         err1 = SD_ReadMultiBlocks( &buff[0] , sector ,SECTOR_SIZE , count );
		
		      SD_WaitReadOperation();
		
          while(SD_GetStatus() != SD_TRANSFER_OK);
 
       
	}
  if( err1 == SD_OK)
     return RES_OK;
	else
		return RES_ERROR;
}
示例#6
0
/*******************************************************************************
* Function Name  : MAL_Init
* Description    : Initializes the Media on the STM32
* 功能           : 储存介质初始化
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
uint16_t MAL_Init(uint8_t lun)
{
    uint16_t status = MAL_OK;
    switch (lun)
    {
    case 0:

        Status = SD_Init();
        Status = SD_GetCardInfo(&SDCardInfo);
        Status = SD_SelectDeselect((uint32_t) (SDCardInfo.RCA << 16));
        Status = SD_EnableWideBusOperation(SDIO_BusWide_4b);
        Status = SD_SetDeviceMode(SD_DMA_MODE);
        if (Status == SD_OK)
        {
            // 从地址0开始读取512字节
            Status = SD_ReadBlock(Buffer_Block_Rx, 0x00,  BlockSize);
        }
        if (Status == SD_OK)
        {
            // 返回成功的话,串口输出SD卡测试成功信息
						DbgPrintf(" \n SD SDIO-4bit模式 TF OK");
        }
        break;
    default:
        return MAL_FAIL;
    }
    return status;
}
/*******************************************************************************
* Function Name  : MAL_Read
* Description    : Read sectors
* Input          : None
* Output         : None
* Return         : Buffer pointer
*******************************************************************************/
uint16_t MAL_Read(uint8_t lun, uint32_t Memory_Offset, uint32_t *Readbuff, uint16_t Transfer_Length)
{

  switch (lun)
  {
    case 0:

     // SD_ReadMultiBlocks((uint8_t*)Readbuff, Memory_Offset, Transfer_Length, 1);
      SD_ReadBlock((uint8_t*)Readbuff, Memory_Offset, Transfer_Length);
	  Status = SD_WaitReadOperation();
      while(SD_GetStatus() != SD_TRANSFER_OK)
      {
      }
//    Status = SD_WaitWriteOperation();
//    while(SD_GetStatus() != SD_TRANSFER_OK);
      
      if ( Status != SD_OK )
      {
        return MAL_FAIL;
      }
      break;
//    case 1:
//      NAND_Read(Memory_Offset, Readbuff, Transfer_Length);
//      ;
//      break;
    default:
      return MAL_FAIL;
  }
  return MAL_OK;
}
示例#8
0
文件: diskio.c 项目: qq5013/DLMR-PDA
DRESULT disk_read (
	BYTE pdrv,		/* Physical drive nmuber to identify the drive */
	BYTE *buff,		/* Data buffer to store read data */
	DWORD sector,	/* Sector address in LBA */
	BYTE count		/* Number of sectors to read */
)
{
	DRESULT res;
	int result;


    pdrv = pdrv;

    if(!count)
    {
        res = RES_PARERR;

        return (res);
    }

    result = SD_ReadBlock(buff, sector, count);

    if(0 == result)
    {
        res = RES_OK;
    }
    else
    {
        res = RES_ERROR;
    }
    
	return (res);
}
示例#9
0
DRESULT disk_readp (
	BYTE* dest,			/* Pointer to the destination object */
	DWORD sector,		/* Sector number (LBA) */
	WORD sofs,			/* Offset in the sector */
	WORD count			/* Byte count (bit15:destination) */
)
{
	DRESULT res;

	// Put your code here
	if( g_BufLBA == sector )
	{
		memcpy( dest, g_Buf + sofs, count );
	}
	else
	{
		SD_ReadBlock( &sdDrv, sector, 1, g_Buf );
		memcpy( dest, g_Buf + sofs, count );
		
		g_BufLBA = sector;
	}
	
	
	res = RES_OK;

	return res;
}
示例#10
0
DRESULT disk_read (
	BYTE pdrv,		/* Physical drive nmuber to identify the drive */
	BYTE *buff,		/* Data buffer to store read data */
	DWORD sector,	/* Sector address in LBA */
	UINT count		/* Number of sectors to read */
)
{
	if(count>1)
	{
		SD_ReadMultiBlocks(buff, sector*BLOCK_SIZE, BLOCK_SIZE, count);
		// check transfer finished
		SD_WaitReadOperation();
		// wait the DMA transfer finished
		while(SD_GetStatus() != SD_TRANSFER_OK);
	}
	else
	{
		SD_ReadBlock(buff, sector*BLOCK_SIZE, BLOCK_SIZE);
		// check transfer finished
		SD_WaitReadOperation();
		// wait the DMA transfer finished
		while(SD_GetStatus() != SD_TRANSFER_OK);

	}
	return RES_OK;	
}
示例#11
0
文件: mass_mal.c 项目: prid77/Demos
/*******************************************************************************
* Function Name  : MAL_Init
* Description    : Initializes the Media on the STM32
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
uint16_t MAL_Init(uint8_t lun)
{
  uint16_t status = MAL_OK;

  switch (lun)
  {
    case 0:
#ifdef USE_STM3210E_EVAL
      Status = SD_Init();
      Status = SD_GetCardInfo(&SDCardInfo);
      Status = SD_SelectDeselect((uint32_t) (SDCardInfo.RCA << 16));
      Status = SD_EnableWideBusOperation(SDIO_BusWide_4b);
      Status = SD_SetDeviceMode(SD_DMA_MODE);
	  if (Status == SD_OK)
  {	 
     
	  
      //Status = SD_ReadMultiBlocks(0x00, Buffer_MultiBlock_Rx, BlockSize, NumberOfBlocks1);	
	 // printf("\r\nSD SDIO-4bit模式 测试TF卡读写成功! \n ");
	 
  }
  
 
  if (Status == SD_OK)
  {	
    // Read block of 512 bytes from address 0 
    Status = SD_ReadBlock(0x00, Buffer_Block_Rx, BlockSize);   

  }

 
  
  

  if (Status == SD_OK)
  {	 
    // Check the corectness of written dada 
    

	printf("\r\nSD SDIO-4bit模式 测试TF卡读写成功! \n ");
  }  
  
  

#else
      MSD_Init();
#endif
      break;
#ifdef USE_STM3210E_EVAL
    case 1:
	
      status = NAND_Init();
      break;
#endif
    default:
      return MAL_FAIL;
  }
  return status;
}
DRESULT disk_read (
	BYTE pdrv,		/* Physical drive nmuber (0..) */
	BYTE *buff,		/* Data buffer to store read data */
	DWORD sector,	/* Sector address (LBA) */
	UINT count		/* Number of sectors to read (1..128) */
)
{
	/*DRESULT res;
	int result;

	switch (pdrv) {
	case ATA :
		// translate the arguments here

		result = ATA_disk_read(buff, sector, count);

		// translate the reslut code here

		return res;

	case MMC :
		// translate the arguments here

		result = MMC_disk_read(buff, sector, count);

		// translate the reslut code here

		return res;

	case USB :
		// translate the arguments here

		result = USB_disk_read(buff, sector, count);

		// translate the reslut code here

		return res;
	}
	return RES_PARERR;*/

	DRESULT res = RES_ERROR;
	SD_Error error = SD_OK;

	sector *= 512;

	if (pdrv == MMC) {
		while (count > 0 && error == SD_OK) {
			error = SD_ReadBlock((uint8_t*)buff, sector, 512);
			sector += 512;
			buff += 512;
			--count;
		}
		if (error == SD_OK) {
			res = RES_OK;
		}
	}

	return res;
}
示例#13
0
DRESULT disk_read (
	BYTE drv,		/* Physical drive nmuber (0..) */
	BYTE *buff,		/* Data buffer to store read data */
	DWORD sector,	/* Sector address (LBA) */
	BYTE count		/* Number of sectors to read (1..255) */
)
{

	u8 res=0; 
    if (!count)return RES_PARERR;//count不能等于0,否则返回参数错误		 	 
	switch(drv)
	{
		case SD_CARD://SD卡
			if (count > 1)
			{
				SD_ReadMultiBlocks(buff, sector*BLOCK_SIZE, BLOCK_SIZE, count);
			
					  /* Check if the Transfer is finished */
			     SD_WaitReadOperation();  //循环查询dma传输是否结束
			
			    /* Wait until end of DMA transfer */
			    while(SD_GetStatus() != SD_TRANSFER_OK);
		
			}
			else
			{
				
				SD_ReadBlock(buff, sector*BLOCK_SIZE, BLOCK_SIZE);
		
					  /* Check if the Transfer is finished */
			     SD_WaitReadOperation();  //循环查询dma传输是否结束
			
			    /* Wait until end of DMA transfer */
			    while(SD_GetStatus() != SD_TRANSFER_OK);
		
			}
			break;
		case EX_FLASH://外部flash
			for(;count>0;count--)
			{
				SPI_Flash_Read(buff,sector*BLOCK_SIZE,BLOCK_SIZE);
				sector++;
				buff+=BLOCK_SIZE;
			}
			res=0;
			break;
		default:
			res=1; 
	}
   //处理返回值,将SPI_SD_driver.c的返回值转成ff.c的返回值
    if(res==0x00)return RES_OK;	 
    else return RES_ERROR;

}
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured, 
  this is done through SystemInit() function which is called from startup
  file (startup_stm32f0xx.s) before to branch to application main.
  To reconfigure the default setting of SystemInit() function, refer to
  system_stm32f0xx.c file
  */
  
  /* Initialize Leds mounted on STM320518-EVAL board */
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  
  /* Initializes the SD/SPI communication */
  Status = SD_Init();	
  
  /* If SD is responding */
  if (Status == SD_RESPONSE_NO_ERROR)
  {
    /* Fill the buffer to send */
    Fill_Buffer(Buffer_Block_Tx, BUFFERSIZE, 0x0);
    
    /* Write block of 512 bytes on address 0 */
    Status = SD_WriteBlock(Buffer_Block_Tx, 0, BUFFERSIZE);
    
    /* Read block of 512 bytes from address 0 */
    Status = SD_ReadBlock(Buffer_Block_Rx, 0, BUFFERSIZE);
    
    /* Check the corectness of written dada */
    TransferStatus = Buffercmp(Buffer_Block_Tx, Buffer_Block_Rx, BUFFERSIZE);
    
    if (TransferStatus == PASSED)
    {
      /* OK: Turn on LD1 */
      STM_EVAL_LEDOn(LED1);
    }
    else
    {
      /* Error: Turn on LD2 */
      STM_EVAL_LEDOn(LED2);
    }
  }
  else
  {
    /* Error: Turn on LD2 */
    STM_EVAL_LEDOn(LED2);
  }
  
  while (1)
  {
  }
  
}
示例#15
0
DRESULT disk_read (
	BYTE drv,		/* Physical drive nmuber (0..) */
	BYTE *buff,		/* Data buffer to store read data */
	DWORD sector,	/* Sector address (LBA) */
	BYTE count		/* Number of sectors to read (1..255) */
)
{
	SD_Error Status = SD_OK;


	switch(drv)
	{
		case SD_CARD://SD卡
	//SD卡开始----------------------------------------
			if (count == 1) 
			{
				Status = SD_ReadBlock(buff, sector << 9 , SECTOR_SIZE);
			} 
			else 
			{
				Status = SD_ReadMultiBlocks(buff, sector << 9 , SECTOR_SIZE, count);
			}
		

	//SD卡结束----------------------------------------
			break;
	case EX_FLASH://外部flash
			for(;count>0;count--)
			{
				SPI_Flash_Read(buff,sector*SECTOR_SIZE,SECTOR_SIZE);
				sector++;
				buff+=SECTOR_SIZE;
			}
			Status=SD_OK;
			break;
	default:
			Status=SD_ERROR;
	}

			
			
			if (Status == SD_OK) 
			{
				return RES_OK;
			} 
			else
			{
				printf("Err: SD_ReadMultiBlocks(,%d,%d)\r\n",sector,count);
				return RES_ERROR;
			}
			
}
示例#16
0
DRESULT disk_read (
	BYTE drv,		/* Physical drive nmuber (0..) */
	BYTE *buff,		/* Data buffer to store read data */
	DWORD sector,	/* Sector address (LBA) */
	BYTE count		/* Number of sectors to read (1..255) */
)
{	 
	if(count==1)
    {
          SD_ReadBlock((u32 *)(&buff[0]),sector << 9 ,SECTOR_SIZE);
         
	}
	return RES_OK;
}
示例#17
0
DRESULT disk_read (
	BYTE pdrv,		/* Physical drive nmuber (0..) */
	BYTE *buff,		/* Data buffer to store read data */
	DWORD sector,	/* Sector address (LBA) */
	BYTE count		/* Number of sectors to read (1..128) */
)
{
	DRESULT res;
	int result;
        //result = MMC_disk_read(buff, sector, count);
        SD_ReadBlock(buff, sector*512, count*512);
	return 0;

}
示例#18
0
//===================================================================
// User-supplied functions
uint32_t DFS_ReadSector(uint8_t unit, uint8_t *buffer, uint32_t sector, uint32_t count)
{
    SD_Error Status = SD_OK;
    u32 *buffer32;
    buffer32 = (u32*)buffer; 
    
    Status = SD_ReadBlock(sector << 9 , buffer32, SECTOR_SIZE);
      
    if (Status == SD_OK)
      return 0;
    else
      return 1;
   
}
BOOL SD_BS_Driver::ReadSector(SectorAddress Address, UINT32 Offset, UINT32 NumBytes, BYTE *pSectorBuff, UINT32 BytesPerSector)
{
	__IO SD_Error errorstatus = SD_OK;

	errorstatus = SD_ReadBlock(pSectorBuff, ((Address * BytesPerSector) + Offset), BytesPerSector);

	while(SD_GetStatus() != SD_TRANSFER_OK);

	//CPU_FlushCaches();

	if(errorstatus == SD_OK)
		return TRUE;
	else
		return FALSE;
}
示例#20
0
文件: main.c 项目: edosedgar/stm8s
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{
    /* Clock configuration -----------------------------------------*/
    CLK_Config();
    
    /* GPIO Configuration ------------------------------------------*/
    GPIO_Config();

		
   /***********************SPI and MSD Card initialization******************/

    while (SD_Detect() == SD_NOT_PRESENT);
    {
      /* Wait MicroSD card insertion */
    }

    Delay(0xFFFF);
    /* Init the flash micro SD*/
    Status = SD_Init();

  /***************************Block Read/Write******************************/
  /* Write block of 512 bytes on address 0 */
  SD_WriteBlock(TxBuffer, 0, BUFFER_SIZE);

  /* Read block of 512 bytes from address 0 */
  SD_ReadBlock(RxBuffer, 0, BUFFER_SIZE);

  /* Check data */
  TransferStatus = Buffercmp(TxBuffer, RxBuffer, BUFFER_SIZE);
  if (TransferStatus != SUCCESS)
  {
    while (1) /* Go to infinite loop when there is mismatch in data programming*/
    {
      STM_EVAL_LEDToggle(LED1);
      Delay((uint16_t)0xFFFF);
      Delay((uint16_t)0xFFFF);
    }
  }
  while (1)
  {
    STM_EVAL_LEDToggle(LED1);
    STM_EVAL_LEDToggle(LED2);
    STM_EVAL_LEDToggle(LED3);
    STM_EVAL_LEDToggle(LED4);
    Delay((uint16_t)0xFFFF);
    Delay((uint16_t)0xFFFF);
  }
}
示例#21
0
文件: main.c 项目: HorseMa/contiki
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{
  /* High speed internal clock prescaler: 1*/
  CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_1);

  /* Initialize I/Os in Output Mode for LEDs */
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  STM_EVAL_LEDInit(LED3);
  STM_EVAL_LEDInit(LED4);

  /***********************SPI and MSD Card initialization******************/

  while (SD_Detect() == SD_NOT_PRESENT);
  {
    /* Wait MicroSD card insertion */
  }

  Delay(0xFFFF);
  /* Init the flash micro SD*/
  Status = SD_Init();

  /***************************Block Read/Write******************************/
  /* Write block of 512 bytes on address 0 */
  SD_WriteBlock(TxBuffer, 0, BUFFER_SIZE);

  /* Read block of 512 bytes from address 0 */
  SD_ReadBlock(RxBuffer, 0, BUFFER_SIZE);

  /* Check data */
  TransferStatus = Buffercmp(TxBuffer, RxBuffer, BUFFER_SIZE);
  if (TransferStatus != SUCCESS)
  {
    while (1) /* Go to infinite loop when there is mismatch in data programming*/
    {
      STM_EVAL_LEDToggle(LED1);
      Delay((uint16_t)0xFFFF);
    }
  }
  while (1)
  {
    STM_EVAL_LEDToggle(LED1);
    STM_EVAL_LEDToggle(LED2);
    STM_EVAL_LEDToggle(LED3);
    STM_EVAL_LEDToggle(LED4);
    Delay((uint16_t)0xFFFF);
  }
}
示例#22
0
DRESULT disk_read (
	BYTE drv,		/* Physical drive nmuber (0..) */
	BYTE *buff,		/* Data buffer to store read data */
	DWORD sector,	/* Sector address (LBA) */
	BYTE count		/* Number of sectors to read (1..255) */
)
{
  	SD_Error Status;

  	if(count==1)Status =  SD_ReadBlock( buff ,sector<< 9 , SDCardInfo.CardBlockSize );                                                              
  	else Status = SD_ReadMultiBlocks( buff ,sector<< 9 ,SDCardInfo.CardBlockSize,count);
  	//Status = SD_WaitReadOperation();
  	//while(SD_GetStatus() != SD_TRANSFER_OK);
  	if(Status == SD_OK)return RES_OK;
  	else return RES_ERROR;  
}
示例#23
0
/*******************************************************************************
* Function Name  : MAL_Read
* Description    : Read sectors
* Input          : None
* Output         : None
* Return         : Buffer pointer
*******************************************************************************/
uint16_t MAL_Read(uint8_t lun, uint32_t Memory_Offset, uint32_t *Readbuff, uint16_t Transfer_Length) {
  switch (lun) {
    case 0:
      Status = SD_ReadBlock(Memory_Offset, Readbuff, Transfer_Length);
      if ( Status != SD_OK )  return MAL_FAIL;
      break;
    case 1:
      NAND_Read(Memory_Offset, Readbuff, Transfer_Length);
      printf("\r\nTransfer_Length_r = %d",Transfer_Length);
      break;
    default:
      return MAL_FAIL;
  }
  
  return MAL_OK;
}
示例#24
0
/* Read Sector(s)                                                        */
DRESULT disk_read (
	BYTE drv,		/* Physical drive nmuber (0..) */
	BYTE *buff,		/* Data buffer to store read data */
	DWORD sector,	/* Sector address (LBA) */
	BYTE count		/* Number of sectors to read (1..255) */
)
{
	//printf("Disk read: Drive %x, Sector: %x, Count: %x\r\n", drv, sector, count);
	SD_Error Status;
	//uint32_t timeout = 1000000;

	if (!count) return RES_PARERR;

	if(drv==0)
	{
		//DMA
		// Status = SD_ReadMultiBlocks(buff, (uint32_t)(sector*512), BlockSize, count);
		// Status = SD_WaitReadOperation();

		// while(SD_GetStatus() != SD_TRANSFER_OK)
		// {
		// 	if(timeout-- == 0)
		// 	{
		// 		printf("SDIO Timeout\r\n");
		// 		return RES_ERROR;
		// 	}
		// }

		//Polling
		for(int i = 0; i < count; i++)
		{
			Status = SD_ReadBlock((BYTE*)(((uintptr_t)buff)+BlockSize*i), (uint32_t)(sector*BlockSize), BlockSize);
			
			while(SD_GetStatus() != SD_TRANSFER_OK);
			
			if(Status != SD_OK)
				return RES_ERROR;
		}

		if(Status == SD_OK)
			return RES_OK;
		else
			return RES_ERROR;
	}
	else
		return RES_ERROR;  
}
示例#25
0
DRESULT disk_read (
    BYTE drv,		/* Physical drive nmuber (0..) */
    BYTE *buff,		/* Data buffer to store read data */
    DWORD sector,	/* Sector address (LBA) */
    BYTE count		/* Number of sectors to read (1..255) */
)
{
    SD_Error Status;
    if( !count )
    {
        return RES_PARERR;  /* count不能等于0,否则返回参数错误 */
    }

    switch (drv)
    {

    case 0:
        if(count==1)            /* 1个sector的读操作 */
        {
            Status =  SD_ReadBlock( buff ,sector << 9 , SDCardInfo.CardBlockSize );
        }
        else                    /* 多个sector的读操作 */
        {
            Status = SD_ReadMultiBlocks( buff ,sector << 9 ,SDCardInfo.CardBlockSize,count);
        }
        if(Status == SD_OK)
        {
            return RES_OK;
        }
        else
        {
            return RES_ERROR;
        }

    case 1:
        break;

    case 2:
        break;

    default:
        break;

    }

    return RES_ERROR;
}
示例#26
0
DRESULT disk_read (
	BYTE drv,		/* Physical drive nmuber (0..) */
	BYTE *buff,		/* Data buffer to store read data */
	DWORD sector,	/* Sector address (LBA) */
	BYTE count		/* Number of sectors to read (1..255) */
)
{
  SD_Error Status;
  if( !count )
  {    
    return RES_PARERR;  /* count不能等于0,否则返回参数错误 */
  }
  switch (drv)
  {
    case 0:
    if(count==1)            /* 1个sector的读操作 */      
    {       
	  //Status =  SD_ReadBlock( buff ,sector<< 9 , SDCardInfo.CardBlockSize );
      Status =  SD_ReadBlock( buff ,sector<< 9 , 512);
    }                                                
    else                    /* 多个sector的读操作 */     
    {   
      //Status = SD_ReadMultiBlocks( buff ,sector<< 9 ,SDCardInfo.CardBlockSize,count);
      Status = SD_ReadMultiBlocks( buff ,sector<< 9 , 512 ,count);
    }                                                
    /* Check if the Transfer is finished */
    //Status = SD_WaitReadOperation();
    while(SD_GetStatus() != SD_TRANSFER_OK);
    if(Status == SD_OK)
    {
      return RES_OK;
    }
    else
    {
      return RES_ERROR;
    }   
	case 1:	
	  break;

    case 2:	
	  break;

    default:
      break;
  } 
  return RES_ERROR;
}
示例#27
0
/****************************************************************************
* 名    称:void SD_TEST(void)
* 功    能:SD卡测试函数
* 入口参数:无
* 出口参数:无
* 说    明:
* 调用方法:无 
****************************************************************************/ 
void SD_TEST(void){
	Status = SD_Init();
    Status = SD_GetCardInfo(&SDCardInfo);
    Status = SD_SelectDeselect((uint32_t) (SDCardInfo.RCA << 16));
    Status = SD_EnableWideBusOperation(SDIO_BusWide_4b);
    Status = SD_SetDeviceMode(SD_DMA_MODE);  
 	if (Status == SD_OK)
  	{
        // 从地址0开始读取512字节  
    	Status = SD_ReadBlock(Buffer_Block_Rx, 0x00,  512); 
  	}
  	if (Status == SD_OK)
    {	 
       // 返回成功的话,串口输出SD卡测试成功信息 
	    USART_OUT(USART1,"\r\nSD SDIO-4bit模式 测试TF卡成功! \n ");
    } 
}
uint16_t MAL_Read(uint8_t lun, uint64_t Memory_Offset, uint32_t *Readbuff, uint16_t Transfer_Length)
{

  switch (lun)
  {
    case 0:
	
      Status = SD_ReadBlock((uint8_t*)Readbuff, Memory_Offset, Transfer_Length);
      if ( Status != SD_OK )
      {
        return MAL_FAIL;
      }
      break;
	
    default:
      return MAL_FAIL;
  }
  return MAL_OK;
}
/**
  * @brief  Tests the SD card Single Blocks operations.
  * @param  None
  * @retval None
  */
void SD_SingleBlockTest(void)
{
  /*------------------- Block Read/Write --------------------------*/
  /* Fill the buffer to send */
  Fill_Buffer(Buffer_Block_Tx, BLOCK_SIZE, 0x320F);

  if (Status == SD_OK)
  {
    /* Write block of 512 bytes on address 0 */
    Status = SD_WriteBlock(Buffer_Block_Tx, 0x00, BLOCK_SIZE);
    /* Check if the Transfer is finished */
    Status = SD_WaitWriteOperation();
    while(SD_GetStatus() != SD_TRANSFER_OK);
  }

  if (Status == SD_OK)
  {
    /* Read block of 512 bytes from address 0 */
    Status = SD_ReadBlock(Buffer_Block_Rx, 0x00, BLOCK_SIZE);
    /* Check if the Transfer is finished */
    Status = SD_WaitReadOperation();
    while(SD_GetStatus() != SD_TRANSFER_OK);
  }

  /* Check the correctness of written data */
  if (Status == SD_OK)
  {
    TransferStatus1 = Buffercmp(Buffer_Block_Tx, Buffer_Block_Rx, BLOCK_SIZE);
  }
  
  if(TransferStatus1 == PASSED)
  {
    STM_EVAL_LEDOn(LED2);
	LCD_DisplayStringLine(LCD_LINE_2, "Passed");
  }
  else
  {
    STM_EVAL_LEDOff(LED2);
    STM_EVAL_LEDOn(LED4);    
	LCD_DisplayStringLine(LCD_LINE_2, "failed");
  }
}
示例#30
0
DRESULT disk_read (
	BYTE drv,		/* Physical drive nmuber (0..) */
	BYTE *buff,		/* Data buffer to store read data */
	DWORD sector,	/* Sector address (LBA) */
	BYTE count		/* Number of sectors to read (1..255) */
)
{
  //memset(buff2, 0, sizeof(buff2));
	if(count==1)
        {
          SD_ReadBlock(sector << 9 ,(u32 *)(&buff[0]),BlockSize);
          //memcpy(buff,buff2,SECTOR_SIZE);
	}
	else
        {
          SD_ReadMultiBlocks(sector << 9 ,(u32 *)(&buff[0]),BlockSize,count);
          //memcpy(buff,buff2,SECTOR_SIZE * count);
	}
	return RES_OK;
}