/** * @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"); } }
/** * @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"); }
bool SdioSecureDigitalCard::eraseBlocks(uint32_t blockIndex_,uint32_t numBlocks_) { uint32_t startAddr,endAddr; startAddr=blockIndex_ * getBlockSizeInBytes(); endAddr=startAddr + (getBlockSizeInBytes() * numBlocks_); return handleReturnCode(SD_Erase(startAddr,endAddr),E_FAILED_TO_ERASE_BLOCKS); }
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; }
/** * @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) {} }