/** * @brief Tests the SD card Multiple Blocks operations. * @param None * @retval None */ static void SD_MultiBlockTest(void) { SD_Error status; /* Fill the buffer to send */ Fill_Buffer(aBuffer_MultiBlock_Tx, MULTI_BUFFER_SIZE, 0x0); /* Write Multiple Block of many bytes on address 0 */ status = SD_WriteMultiBlocksFIXED(aBuffer_MultiBlock_Tx, 0, BLOCK_SIZE, NUMBER_OF_BLOCKS); /* check if the Transfer finished */ status = SD_WaitWriteOperation(); while(SD_GetStatus() != SD_TRANSFER_OK); if(status == SD_OK) { /* Read Block of many bytes from address 0 */ status = SD_ReadMultiBlocksFIXED(aBuffer_MultiBlock_Rx, 0, BLOCK_SIZE, NUMBER_OF_BLOCKS); /* check if the Transfer 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) printf("SD Multiple block test passed!\n\r"); }
DRESULT disk_write ( BYTE drv, /* Physical drive nmuber (0..) */ const BYTE *buff, /* Data to be written */ DWORD sector, /* Sector address (LBA) */ BYTE count /* Number of sectors to write (1..255) */ ) { SD_Error Status; #ifdef DBGIO printf("disk_write %d %p %10d %d\n",drv,buff,sector,count); #endif if (SD_Detect() != SD_PRESENT) return(RES_NOTRDY); if ((DWORD)buff & 3) // DMA Alignment failure, do single up to aligned buffer { DRESULT res = RES_OK; DWORD scratch[BLOCK_SIZE / 4]; // Alignment assured, you'll need a sufficiently big stack while(count--) { memcpy(scratch, buff, BLOCK_SIZE); res = disk_write(drv, (void *)scratch, sector++, 1); if (res != RES_OK) break; buff += BLOCK_SIZE; } return(res); } Status = SD_WriteMultiBlocksFIXED((uint8_t *)buff, sector, BLOCK_SIZE, count); // 4GB Compliant if (Status == SD_OK) { SDTransferState State; Status = SD_WaitWriteOperation(); // Check if the Transfer is finished while((State = SD_GetStatus()) == SD_TRANSFER_BUSY); // BUSY, OK (DONE), ERROR (FAIL) if ((State == SD_TRANSFER_ERROR) || (Status != SD_OK)) return(RES_ERROR); else return(RES_OK); } else return(RES_ERROR); }