/** * @brief Tests the SD card Single Blocks operations. * @param None * @retval None */ static void SD_SingleBlockTest (void) { /*------------------- Block Read/Write --------------------------*/ /* Fill the buffer to send */ Fill_Buffer (aBuffer_Block_Tx, BLOCK_SIZE, 0x1234F); if (Status == SD_OK) { /* Write block of 512 bytes on address 0 */ Status = SD_WriteBlock (aBuffer_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 (aBuffer_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 (aBuffer_Block_Tx, aBuffer_Block_Rx, BLOCK_SIZE); } if (TransferStatus1 == PASSED) { logf ("Single block test passed\r\n"); } else { logf ("Single block test failed\r\n"); } }
/** * @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) { STM_EVAL_LEDOn(LED1); } else { STM_EVAL_LEDOff(LED1); STM_EVAL_LEDOn(LED4); } }
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; }