Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: DISCO-F746NG_SDFileSystem uzairkhan DISCO-F746NG_Scope_copy
Fork of SDFileSystem by
Diff: SDFileSystem.cpp
- Revision:
- 24:698affe9560c
- Parent:
- 23:c03ef1abef0e
- Child:
- 25:391eade4ef85
diff -r c03ef1abef0e -r 698affe9560c SDFileSystem.cpp
--- a/SDFileSystem.cpp Thu Mar 31 17:39:48 2016 +0000
+++ b/SDFileSystem.cpp Tue Apr 12 13:47:47 2016 +0000
@@ -40,6 +40,7 @@
NVIC_SetVector(DMA2_Stream6_IRQn,(uint32_t)h);
h=(void*)&SDFileSystem::SDMMC1_IRQHandler;
NVIC_SetVector(SDMMC1_IRQn,(uint32_t)h);
+ BSP_SD_Clear_Busy();
initstat=BSP_SD_Init();
if (initstat!=MSD_OK)
{
@@ -196,19 +197,22 @@
//Make sure the card is initialized before proceeding
if (m_Status & STA_NOINIT)
return RES_NOTRDY;
-
+ while(BSP_SD_Get_Busy()==1){;}
+ BSP_SD_Set_Busy();
//Read a single block, or multiple blocks
if (count > 1) {
BSP_SD_Set_RX_Busy();
retval=BSP_SD_ReadBlocks_DMA((uint32_t *)buffer, (uint64_t) (sector * 512),512, count);
- while(BSP_SD_Get_RX_busy()==1){;}
+ while((BSP_SD_Get_RX_Busy()==1)&&(retval==MSD_OK)){;}
CPU_CACHE_Flush((uint32_t *)buffer,(512*count));
+ BSP_SD_Clear_Busy();
return (retval ? RES_ERROR : RES_OK);
} else {
BSP_SD_Set_RX_Busy();
retval= BSP_SD_ReadBlocks_DMA((uint32_t *)buffer, (uint64_t) (sector * 512), 512, 1);
- while(BSP_SD_Get_RX_busy()==1){;}
+ while((BSP_SD_Get_RX_Busy()==1)&&(retval==MSD_OK)){;}
CPU_CACHE_Flush((uint32_t *)buffer,(512));
+ BSP_SD_Clear_Busy();
return (retval ? RES_ERROR : RES_OK);
}
}
@@ -219,23 +223,28 @@
//Make sure the card is initialized before proceeding
if (m_Status & STA_NOINIT)
return RES_NOTRDY;
-
+ while(BSP_SD_Get_Busy()==1){;}
+ BSP_SD_Set_Busy();
//Make sure the card isn't write protected before proceeding
if (m_Status & STA_PROTECT)
- return RES_WRPRT;
-
+ {
+ BSP_SD_Clear_Busy();
+ return RES_WRPRT;
+ }
//Write a single block, or multiple blocks
if (count > 1) {
CPU_CACHE_Flush((uint32_t *)buffer,(512*count));
BSP_SD_Set_TX_Busy();
retval= BSP_SD_WriteBlocks_DMA((uint32_t *)buffer, (uint64_t) (sector * 512), 512, count);
- while(BSP_SD_Get_TX_busy()==1){;}
+ while((BSP_SD_Get_TX_Busy()==1)&&(retval==MSD_OK)){;}
+ BSP_SD_Clear_Busy();
return (retval? RES_ERROR : RES_OK);
} else {
CPU_CACHE_Flush((uint32_t *)buffer,(512));
BSP_SD_Set_TX_Busy();
retval= BSP_SD_WriteBlocks_DMA((uint32_t *)buffer, (uint64_t) (sector * 512), 512, 1);
- while(BSP_SD_Get_TX_busy()==1){;}
+ while((BSP_SD_Get_TX_Busy()==1)&&(retval==MSD_OK)){;}
+ BSP_SD_Clear_Busy();
return (retval? RES_ERROR : RES_OK);
}
@@ -244,11 +253,15 @@
int SDFileSystem::disk_sync()
{
//Select the card so we're forced to wait for the end of any internal write processes
+ while(BSP_SD_Get_Busy()==1){;}
+ BSP_SD_Set_Busy();
while(BSP_SD_GetStatus()==SD_TRANSFER_BUSY){;}
if(BSP_SD_GetStatus()==SD_TRANSFER_OK)
{
+ BSP_SD_Clear_Busy();
return RES_OK;
} else {
+ BSP_SD_Clear_Busy();
return RES_ERROR;
}
}
@@ -259,8 +272,11 @@
//Make sure the card is initialized before proceeding
if (m_Status & STA_NOINIT)
return 0;
- BSP_SD_GetCardInfo(&m_CardInfo);
- sectors=m_CardInfo.CardCapacity>>9;
+ while(BSP_SD_Get_Busy()==1){;}
+ BSP_SD_Set_Busy();
+ BSP_SD_GetCardInfo(&m_CardInfo);
+ sectors=m_CardInfo.CardCapacity>>9;
+ BSP_SD_Clear_Busy();
return sectors;
}
@@ -323,6 +339,3 @@
{
BSP_SD_IRQHandler();
}
-
-
-
