完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
之前换个几个卡了。不是读写成功擦除失败就是擦除成功读写失败。刚有买了个32G的闪迪卡,又出现了读写失败。擦除成功。不可能是真的是卡的问题。还是程序的问题。我把真个工程附件都添加进去了。大神帮看看啊。
用的是下面的代码。可以说就是官方的例程。 /* Initialize LEDs available on STM322xG-EVAL board *************************/ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); /* Interrupt Config */ NVIC_Configuration(); /*------------------------------ SD Init ---------------------------------- */ if((Status = SD_Init()) != SD_OK) { STM_EVAL_LEDOn(LED4); } while((Status == SD_OK) && (SDCardOperation != SD_OPERATION_END) && (SD_Detect()== SD_PRESENT)) { switch(SDCardOperation) { /*-------------------------- SD Erase Test ---------------------------- */ case (SD_OPERATION_ERASE): { SD_EraseTest(); SDCardOperation = SD_OPERATION_BLOCK; break; } /*-------------------------- SD Single Block Test --------------------- */ case (SD_OPERATION_BLOCK): { SD_SingleBlockTest(); SDCardOperation = SD_OPERATION_MULTI_BLOCK; break; } /*-------------------------- SD Multi Blocks Test --------------------- */ case (SD_OPERATION_MULTI_BLOCK): { SD_MultiBlockTest(); SDCardOperation = SD_OPERATION_END; break; } } } /* Infinite loop */ while (1) {} } /** * @brief Configures SDIO IRQ channel. * @param None * @retval None */ void NVIC_Configuration(void) { NVIC_InitTypeDef NVIC_InitStructure; /* Configure the NVIC Preemption Priority Bits */ NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); NVIC_InitStructure.NVIC_IRQChannel = SDIO_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); } /** * @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); } } /** * @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); } else { STM_EVAL_LEDOff(LED2); STM_EVAL_LEDOn(LED4); } } /** * @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); } else { STM_EVAL_LEDOff(LED3); STM_EVAL_LEDOn(LED4); } } /** * @brief Compares two buffers. * @param pBuffer1, pBuffer2: buffers to be compared. * @param BufferLength: buffer's length * @retval PASSED: pBuffer1 identical to pBuffer2 * FAILED: pBuffer1 differs from pBuffer2 */ TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint32_t BufferLength) { while (BufferLength--) { if (*pBuffer1 != *pBuffer2) { return FAILED; } pBuffer1++; pBuffer2++; } return PASSED; }
|
|
相关推荐
2个回答
|
|
我就是来帮顶的……
|
|
|
|
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
238 浏览 0 评论
如何解决MPU-9250与STM32通讯时,出现HAL_ERROR = 0x01U
734 浏览 1 评论
hal库中i2c卡死在HAL_I2C_Master_Transmit
1128 浏览 1 评论
LL库F030进行3个串口收发,2个串口为232,一个为485,长时间后,会出现串口1停止运行,另外两个正常,只有重启复原
1600 浏览 1 评论
538 浏览 0 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-9 09:35 , Processed in 0.473172 second(s), Total 49, Slave 39 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号