Beispiel #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;  
    }
}
Beispiel #2
0
/**
  * @brief  Tests the SD card erase operation.
  * @param  None
  * @retval None
  */
void SD_EraseTest(void)
{
  /*------------------- Block Erase ------------------------------------------*/
  if (Status == SD_OK)
  {
    /* Erase NumberOfBlocks Blocks of WRITE_BL_LEN(512 Bytes) */
    Status = SD_Erase(0x00, (BLOCK_SIZE * NUMBER_OF_BLOCKS));
  }

  if (Status == SD_OK)
  {
    Status = SD_ReadMultiBlocks(Buffer_MultiBlock_Rx, 0x00, BLOCK_SIZE, NUMBER_OF_BLOCKS);

    /* Check if the Transfer is finished */
    Status = SD_WaitReadOperation();

    /* Wait until end of DMA transfer */
    while(SD_GetStatus() != SD_TRANSFER_OK);
  }

  /* Check the correctness of erased blocks */
  if (Status == SD_OK)
  {
    EraseStatus = eBuffercmp(Buffer_MultiBlock_Rx, MULTI_BUFFER_SIZE);
  }
  
  if(EraseStatus == PASSED)
  {
	  xprintf("Erase test passed\n");
  }
  else
  {
	  xprintf("Erase test failed\n");
  }
}
Beispiel #3
0
/**
   * @brief  Read Sector(s) 
   * @param   drv : driver index
   * @retval DSTATUS : operation status
  */
DRESULT disk_read (
                   BYTE drv,			  /* Physical drive number (0) */
                   BYTE *buff,			/* Pointer to the data buffer to store read data */
                   DWORD sector,		/* Start sector number (LBA) */
                   BYTE count			  /* Sector count (1..255) */
                     )
{
  
  SD_Error sdstatus = SD_OK;
 
  if (drv == 0)
  {
    SD_ReadMultiBlocks(buff, sector << 9, 512, count);
    
    /* Check if the Transfer is finished */
    sdstatus =  SD_WaitReadOperation();
    while(SD_GetStatus() != SD_TRANSFER_OK);
    
    if (sdstatus == SD_OK)
    {
      return RES_OK;
    }
  }
  return RES_ERROR;
}
Beispiel #4
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;
}
DRESULT disk_read (
                   BYTE drv,			/* Physical drive number (0) */
                   BYTE *buff,			/* Pointer to the data buffer to store read data */
                   DWORD sector,		/* Start sector number (LBA) */
                   BYTE count			/* Sector count (1..255) */
                     )
{
  uint32_t timeout = 100000;
  SD_Error sdstatus = SD_OK;

        SD_ReadMultiBlocks((BYTE *)buff, (uint32_t )(sector * 512), 512, count);
        /* Check if the Transfer is finished */
        sdstatus = SD_WaitReadOperation();

        while(SD_GetStatus() != SD_TRANSFER_OK)
        {

          if (timeout-- == 0)
          {
            return RES_ERROR;
          }
        }

        if (sdstatus == SD_OK)
        {
          return RES_OK;
        }
      

    return RES_NOTRDY;
}
Beispiel #6
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:

      SD_ReadMultiBlocks((uint8_t*)Readbuff, Memory_Offset, Transfer_Length, 1);
#if defined(USE_STM3210E_EVAL) || defined(USE_STM32L152D_EVAL)
      Status = SD_WaitReadOperation();
      while(SD_GetStatus() != SD_TRANSFER_OK)
      {
      }
      
      if ( Status != SD_OK )
      {
        return MAL_FAIL;
      }
#endif /* USE_STM3210E_EVAL */      
      break;
#ifdef USE_STM3210E_EVAL
    case 1:
      NAND_Read(Memory_Offset, Readbuff, Transfer_Length);
      ;
      break;
#endif
    default:
      return MAL_FAIL;
  }
  return MAL_OK;
}
Beispiel #7
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;	
}
/*-----------------------------------------------------------------------*/
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;
}
Beispiel #9
0
/**
 * @brief Tests the SD card erase operation.
 * @param None
 * @retval None
 */
static void SD_EraseTest(void)
{
    SD_Error status = SD_OK;
    /*---------------Block Erase----------------*/
    /* Erase NumberOfBlocks Blocks of WRITE_BL_LEN(512 Bytes) */
    status = SD_Erase(0x00, (BLOCK_SIZE * NUMBER_OF_BLOCKS));
    if(status != SD_OK) printf("SD_Erase failed: %d.\n\r",status);

    if(status == SD_OK)
    {
	printf("SD_Erase ok, performing SD_ReadMultiBlocks.\n\r");
	status = SD_ReadMultiBlocks(aBuffer_MultiBlock_Rx, 0x0, BLOCK_SIZE, NUMBER_OF_BLOCKS);
	if(status != SD_OK){printf("SD_ReadMultiBlocks Failed\n\r");}

	/* Check if the Transfer is finished */
	status = SD_WaitReadOperation();
	if(status != SD_OK){printf("SD_WaitReadOperation Failed\n\r");}

	/* Wait until end of the DMA transfer */
	while(SD_GetStatus() != SD_TRANSFER_OK);

	printf("SD_TRANSFER OK\n\r");
    }

    /* Check the correctness of erased blocks */
    if(status == SD_OK)
    {
	EraseStatus = eBuffercmp(aBuffer_MultiBlock_Rx, MULTI_BUFFER_SIZE);
    }

    if(EraseStatus == PASSED) printf("SD erase test passed!\n\r");
}
Beispiel #10
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;

}
Beispiel #11
0
int8_t STORAGE_Read(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len) {
    if (filerGetMSCState() != FILER_STATE_MSC_ACTIVE || !SD_Initialized() || !SD_TransferComplete())
	return (-1);

    sdioSetCallback(SCSI_ProcessReadComplete, blk_len * 512);

    while (SD_ReadMultiBlocks(buf, blk_addr, 512, blk_len) != SD_OK)
	;

    return 0;
}
Beispiel #12
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;
			}
			
}
Beispiel #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) */
)
{
  	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;  
}
Beispiel #14
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;
}
Beispiel #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;
    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;
}
/**
  * @brief  Read data from the medium
  * @param  lun : logical unit number
  * @param  buf : Pointer to the buffer to save data
  * @param  blk_addr :  address of 1st block to be read
  * @param  blk_len : nmber of blocks to be read
  * @retval Status
  */
int8_t STORAGE_Read (uint8_t lun, 
                 uint8_t *buf, 
                 uint32_t blk_addr,                       
                 uint16_t blk_len)
{
  
  if( SD_ReadMultiBlocks (buf, 
                          blk_addr * 512, 
                          512,
                          blk_len) != 0)
  {
    return -1;
  }
#ifndef USE_STM3210C_EVAL 
  SD_WaitReadOperation();
  while (SD_GetStatus() != SD_TRANSFER_OK);
#endif    
  return 0;
}
/**
  * @brief  Tests the SD card Multiple Blocks operations.
  * @param  None
  * @retval None
  */
void SD_MultiBlockTest(void)
{
  /*--------------- Multiple Block Read/Write ---------------------*/
  /* Fill the buffer to send */
  Fill_Buffer(Buffer_MultiBlock_Tx, MULTI_BUFFER_SIZE, 0x0);

  if (Status == SD_OK)
  {
    /* Write multiple block of many bytes on address 0 */
    Status = SD_WriteMultiBlocks(Buffer_MultiBlock_Tx, 0x00, BLOCK_SIZE, NUMBER_OF_BLOCKS);
    /* Check if the Transfer is finished */
    Status = SD_WaitWriteOperation();
    while(SD_GetStatus() != SD_TRANSFER_OK);
  }

  if (Status == SD_OK)
  {
    /* Read block of many bytes from address 0 */
    Status = SD_ReadMultiBlocks(Buffer_MultiBlock_Rx, 0x00, BLOCK_SIZE, NUMBER_OF_BLOCKS);
    /* 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)
  {
    TransferStatus2 = Buffercmp(Buffer_MultiBlock_Tx, Buffer_MultiBlock_Rx, MULTI_BUFFER_SIZE);
  }
  
  if(TransferStatus2 == PASSED)
  {
    STM_EVAL_LEDOn(LED3);
	LCD_DisplayStringLine(LCD_LINE_2, "Passed");
  }
  else
  {
    STM_EVAL_LEDOff(LED3);
    STM_EVAL_LEDOn(LED4);    
	LCD_DisplayStringLine(LCD_LINE_2, "failed");
  }
}
Beispiel #18
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;
}
Beispiel #19
0
void print_all_SD( uint32_t size )
{
	uint32_t ReadAddr = 0;
	SD_Error SDError;
	uint8_t Buff[PRINT_BUF_SIZE];
	
	while(size--)
	{
		//printf("k = %i\n",k);
		//SDError = SD_ReadMultiBlocksFIXED(Buff, ReadAddr, PRINT_BUF_SIZE, 1);
		SDError = SD_ReadMultiBlocks(Buff, ReadAddr, PRINT_BUF_SIZE, 1);
		if(SDError != SD_OK )
			SD_print_error( SDError );
		
		#ifdef SD_DMA_MODE
		while(SD_GetStatus() != SD_TRANSFER_OK);
		#endif
		
		print_adr_HEX_str( ReadAddr*PRINT_BUF_SIZE, Buff );
		printf(" ReadAddr = %i",ReadAddr++);
	}
}
Beispiel #20
0
/**
 * @brief  Tests the SD card Multiple Blocks operations.
 * @param  None
 * @retval None
 */
static void SD_MultiBlockTest (void)
{
        /* Fill the buffer to send */
        Fill_Buffer (aBuffer_MultiBlock_Tx, MULTI_BUFFER_SIZE, 0x0);

        if (Status == SD_OK) {
                /* Write multiple block of many bytes on address 0 */
                Status = SD_WriteMultiBlocks (aBuffer_MultiBlock_Tx, 0, BLOCK_SIZE, NUMBER_OF_BLOCKS);

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

        if (Status == SD_OK) {
                /* Read block of many bytes from address 0 */
                Status = SD_ReadMultiBlocks (aBuffer_MultiBlock_Rx, 0, BLOCK_SIZE, NUMBER_OF_BLOCKS);

                /* 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) {
                TransferStatus2 = Buffercmp (aBuffer_MultiBlock_Tx, aBuffer_MultiBlock_Rx, MULTI_BUFFER_SIZE);
        }

        if (TransferStatus2 == PASSED) {
                logf ("Multiple block test passed\r\n");
        }
        else {
                logf ("Multiple block test failed\r\n");
        }
}
Beispiel #21
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 )		/* 1个sector的读操作 */
  {	
  	SD_ReadBlock( (u8 *)(&buff[0]),sector <<9,  SECTOR_SIZE );
		//SD_ReadBlock( sector << 9, (u32 *)(&buff[0]), SDCardInfo.CardBlockSize );
		
	}
	else        			 /* 多个sector的读操作 */
	{
		SD_ReadMultiBlocks( (u8 *)(&buff[0]),sector <<9 ,  SECTOR_SIZE, count );
		
	}
	
	SD_WaitReadOperation();
    while(SD_GetStatus() != SD_TRANSFER_OK);
	return RES_OK;		 

}
Beispiel #22
0
uint8_t BSP_TEST_SDIO(void)
{
	uint8_t t_status = 0;

	/*-------------------------- SD Init ----------------------------- */
	BSP_SDCARD_ENABLE();

	Status = SD_Init();

	if (Status == SD_OK)
	{
	/*----------------- Read CSD/CID MSD registers ------------------*/
		Status = SD_GetCardInfo(&SDCardInfo);
	}

	if (Status == SD_OK)
	{
	  /*----------------- Select Card --------------------------------*/
	  Status = SD_SelectDeselect((uint32_t) (SDCardInfo.RCA << 16));
	}

	if (Status == SD_OK)
	{
	  Status = SD_EnableWideBusOperation(SDIO_BusWide_4b);
	}

	/*------------------- Block Erase -------------------------------*/
	if (Status == SD_OK)
	{
	    /* Erase NumberOfBlocks Blocks of WRITE_BL_LEN(512 Bytes) */
	  Status = SD_Erase(0x00, (SDIO_BLOCK_SIZE * SDIO_NB_BLOCK));
	}

	/* Set Device Transfer Mode to DMA */
	if (Status == SD_OK)
	{
	  Status = SD_SetDeviceMode(SD_DMA_MODE);
	}

	if (Status == SD_OK)
	{
	  Status = SD_ReadMultiBlocks(0x00, Buffer_MultiBlock_Rx, SDIO_BLOCK_SIZE, SDIO_NB_BLOCK);
	}

	if (Status == SD_OK)
	{
		t_status = eBuffercmp(Buffer_MultiBlock_Rx, SDIO_MULTIWSIZE);
	}

	/*------------------- Block Read/Write --------------------------*/
	/* Fill the buffer to send */
	Fill_Buffer(Buffer_Block_Tx, SDIO_BUFFERW_SIZE, 0xFFFF);

	if (Status == SD_OK)
	{
	  /* Write block of 512 bytes on address 0 */
	  Status = SD_WriteBlock(0x00, Buffer_Block_Tx, SDIO_BLOCK_SIZE);
	}

	if (Status == SD_OK)
	{
	  /* Read block of 512 bytes from address 0 */
	  Status = SD_ReadBlock(0x00, Buffer_Block_Rx, SDIO_BLOCK_SIZE);
	}

	if (Status == SD_OK)
	{
	  /* Check the corectness of written dada */
		t_status &= Buffercmp(Buffer_Block_Tx, Buffer_Block_Rx, SDIO_BUFFERW_SIZE);
	}

	BSP_SDCARD_DISABLE();

	return t_status;
}
 bool SdioSecureDigitalCard::readBlocks(void *pDest_,uint32_t blockIndex_,uint32_t numBlocks_) {
     return handleReadReturn(SD_ReadMultiBlocks(static_cast<uint8_t *> (pDest_),blockIndex_,getBlockSizeInBytes(),numBlocks_),E_FAILED_TO_READ_MULTIBLOCK);
 }
Beispiel #24
0
/**
  * @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_stm32f10x_xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f10x.c file
     */     

  /* Interrupt Config */
  NVIC_Configuration();

  /*-------------------------- SD Init ----------------------------- */
  Status = SD_Init();

  /*------------------- Block Erase -------------------------------*/
  if (Status == SD_OK)
  {
    /* Erase NumberOfBlocks Blocks of WRITE_BL_LEN(512 Bytes) */
    Status = SD_Erase(0x00, (BLOCK_SIZE * NUMBER_OF_BLOCKS));
  }

  if (Status == SD_OK)
  {
    Status = SD_ReadMultiBlocks(Buffer_MultiBlock_Rx, 0x00, BLOCK_SIZE, NUMBER_OF_BLOCKS);
  }

  if (Status == SD_OK)
  {
    EraseStatus = eBuffercmp(Buffer_MultiBlock_Rx, MULTI_BUFFER_SIZE);
  }
  
  /*------------------- Block Read/Write --------------------------*/
  /* Fill the buffer to send */
  Fill_Buffer(Buffer_Block_Tx, BLOCK_SIZE, 0xFFFF);


  if (Status == SD_OK)
  {
    /* Write block of 512 bytes on address 0 */
    Status = SD_WriteBlock(Buffer_Block_Tx, 0x00, BLOCK_SIZE);
  }

  if (Status == SD_OK)
  {
    /* Read block of 512 bytes from address 0 */
    Status = SD_ReadBlock(Buffer_Block_Rx, 0x00, BLOCK_SIZE);
  }

  if (Status == SD_OK)
  {
    /* Check the corectness of written dada */
    TransferStatus1 = Buffercmp(Buffer_Block_Tx, Buffer_Block_Rx, BLOCK_SIZE);
  }

  /*--------------- Multiple Block Read/Write ---------------------*/
  /* Fill the buffer to send */
  Fill_Buffer(Buffer_MultiBlock_Tx, MULTI_BUFFER_SIZE, 0x0);

  if (Status == SD_OK)
  {
    /* Write multiple block of many bytes on address 0 */
    Status = SD_WriteMultiBlocks(Buffer_MultiBlock_Tx, 0x00, BLOCK_SIZE, NUMBER_OF_BLOCKS);
  }

  if (Status == SD_OK)
  {
    /* Read block of many bytes from address 0 */
    Status = SD_ReadMultiBlocks(Buffer_MultiBlock_Rx, 0x00, BLOCK_SIZE, NUMBER_OF_BLOCKS);
  }

  if (Status == SD_OK)
  {
    /* Check the corectness of written dada */
    TransferStatus2 = Buffercmp(Buffer_MultiBlock_Tx, Buffer_MultiBlock_Rx, MULTI_BUFFER_SIZE);
  }

  /* Infinite loop */
  while (1)
  {}
}
Beispiel #25
0
/*******************************************************************************
* Function Name  : main.
* Description    : main routine.
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
int main(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;
#ifdef DEBUG
  debug();
#endif

  Set_System();
  
  
  Serial_Init();
  
  /////////////////////////////////////////////////////////////////////
  //////// SDCARD Initialisation //////////////////////////////////////
  /////////////////Section adapted from ST example/////////////////////
  
  /*-------------------------- SD Init ----------------------------- */
  Status = SD_Init();

  
  if (Status == SD_OK)
  {	
     
	 Status = SD_GetCardInfo(&SDCardInfo);	   
  }
 
  if (Status == SD_OK)
  {	
    /*----------------- Select Card --------------------------------*/
    Status = SD_SelectDeselect((uint32_t) (SDCardInfo.RCA << 16));  
  }

 
  if (Status == SD_OK)
  {  
    Status = SD_SetDeviceMode(SD_DMA_MODE);	 
	//Status = SD_SetDeviceMode(SD_INTERRUPT_MODE);	
	//Status = SD_SetDeviceMode(SD_POLLING_MODE);  
  }
  
  if (Status == SD_OK)
  {	 
     
	  //Status = SD_ReadBlock(0x00, Buffer_Block_Rx, BlockSize);  
	  //Status = SD_WriteBlock(0x00, Buffer_Block_Tx, BlockSize);   
      Status = SD_ReadMultiBlocks(0x00, Buffer_MultiBlock_Rx, BlockSize, NumberOfBlocks);	
	 
  }
  
 
  if (Status == SD_OK)
  {	
    /* Read block of 512 bytes from address 0 */
    Status = SD_ReadBlock(0x00, Buffer_Block_Rx, BlockSize);  
  }

 
  
  if (Status == SD_OK)
  {
    /* Read block of many bytes from address 0 */
    Status = SD_ReadMultiBlocks(0x00, Buffer_MultiBlock_Rx, BlockSize, NumberOfBlocks);	 
  }

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

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


   
  Get_Medium_Characteristics();
  Set_USBClock();
  USB_Interrupts_Config(); 
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
  GPIO_Init(GPIOC, &GPIO_InitStructure);
  USB_Init();

  
  
  while (1)
  {	
    //printf("\nTEST OK!\n");
    //if (JoyState() != 0)
    //{
    //  Joystick_Send(JoyState());
    //}
  }
}
Beispiel #26
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( !count )
	{    
		return RES_PARERR; 
	}
	switch (pdrv) {	
	case SD_CARD:
    if(count==1)              
    {       
		Status =  SD_ReadBlock( buff ,sector<< 9 , 512 );
    }                                                
    else                    
    {   
		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 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;
}