|
|
@ -54,7 +54,7 @@
|
|
|
|
multi-sector requests, and servicing these one sector at a time will
|
|
|
|
multi-sector requests, and servicing these one sector at a time will
|
|
|
|
significantly slow down the file system.
|
|
|
|
significantly slow down the file system.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
#define BDEV_F_DRIVER 0U
|
|
|
|
#define BDEV_F_DRIVER (0U)
|
|
|
|
|
|
|
|
|
|
|
|
/** @brief The FatFs example implementation.
|
|
|
|
/** @brief The FatFs example implementation.
|
|
|
|
|
|
|
|
|
|
|
@ -63,7 +63,7 @@
|
|
|
|
in and used immediately. The FatFs `diskio.h` header must be in the include
|
|
|
|
in and used immediately. The FatFs `diskio.h` header must be in the include
|
|
|
|
directory path.
|
|
|
|
directory path.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
#define BDEV_FATFS 1U
|
|
|
|
#define BDEV_FATFS (1U)
|
|
|
|
|
|
|
|
|
|
|
|
/** @brief The Atmel Studio Framework SD/MMC driver example implementation.
|
|
|
|
/** @brief The Atmel Studio Framework SD/MMC driver example implementation.
|
|
|
|
|
|
|
|
|
|
|
@ -83,7 +83,15 @@
|
|
|
|
advantages to issuing real multi-sector requests, so using the modified
|
|
|
|
advantages to issuing real multi-sector requests, so using the modified
|
|
|
|
driver is recommended.
|
|
|
|
driver is recommended.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
#define BDEV_ATMEL_SDMMC 2U
|
|
|
|
#define BDEV_ATMEL_SDMMC (2U)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @brief The ST Microelectronics STM32 SDIO driver example implementation.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
This implementation accesses the microSD card through the BSP utilities
|
|
|
|
|
|
|
|
provided as part of the STM32Cube package, used with the STM32 HAL drivers.
|
|
|
|
|
|
|
|
The STM3240G-EVAL and STM32F746NG-Discovery boards are currently supported.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define BDEV_STM32_SDIO (3U)
|
|
|
|
|
|
|
|
|
|
|
|
/** @brief The RAM disk example implementation.
|
|
|
|
/** @brief The RAM disk example implementation.
|
|
|
|
|
|
|
|
|
|
|
@ -92,7 +100,7 @@
|
|
|
|
target hardware, the amount of spare RAM will be limited so generally only
|
|
|
|
target hardware, the amount of spare RAM will be limited so generally only
|
|
|
|
very small disks will be available.
|
|
|
|
very small disks will be available.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
#define BDEV_RAM_DISK 3U
|
|
|
|
#define BDEV_RAM_DISK (4U)
|
|
|
|
|
|
|
|
|
|
|
|
/** @brief Pick which example implementation is compiled.
|
|
|
|
/** @brief Pick which example implementation is compiled.
|
|
|
|
|
|
|
|
|
|
|
@ -100,6 +108,7 @@
|
|
|
|
- #BDEV_F_DRIVER
|
|
|
|
- #BDEV_F_DRIVER
|
|
|
|
- #BDEV_FATFS
|
|
|
|
- #BDEV_FATFS
|
|
|
|
- #BDEV_ATMEL_SDMMC
|
|
|
|
- #BDEV_ATMEL_SDMMC
|
|
|
|
|
|
|
|
- #BDEV_STM32_SDIO
|
|
|
|
- #BDEV_RAM_DISK
|
|
|
|
- #BDEV_RAM_DISK
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
#define BDEV_EXAMPLE_IMPLEMENTATION BDEV_RAM_DISK
|
|
|
|
#define BDEV_EXAMPLE_IMPLEMENTATION BDEV_RAM_DISK
|
|
|
@ -468,7 +477,7 @@ static REDSTATUS DiskRead(
|
|
|
|
for(ulSectorIdx = 0U; ulSectorIdx < ulSectorCount; ulSectorIdx++)
|
|
|
|
for(ulSectorIdx = 0U; ulSectorIdx < ulSectorCount; ulSectorIdx++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
iErr = pDriver->readsector(pDriver, &pbBuffer[ulSectorIdx * ulSectorSize],
|
|
|
|
iErr = pDriver->readsector(pDriver, &pbBuffer[ulSectorIdx * ulSectorSize],
|
|
|
|
CAST_ULONG(ullSectorStart + ulSectorCount));
|
|
|
|
CAST_ULONG(ullSectorStart + ulSectorIdx));
|
|
|
|
if(iErr != 0)
|
|
|
|
if(iErr != 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ret = -RED_EIO;
|
|
|
|
ret = -RED_EIO;
|
|
|
@ -522,7 +531,7 @@ static REDSTATUS DiskWrite(
|
|
|
|
prototype is flawed, using a non-const pointer for the buffer.
|
|
|
|
prototype is flawed, using a non-const pointer for the buffer.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
iErr = pDriver->writesector(pDriver, CAST_AWAY_CONST(uint8_t, &pbBuffer[ulSectorIdx * ulSectorSize]),
|
|
|
|
iErr = pDriver->writesector(pDriver, CAST_AWAY_CONST(uint8_t, &pbBuffer[ulSectorIdx * ulSectorSize]),
|
|
|
|
CAST_ULONG(ullSectorStart + ulSectorCount));
|
|
|
|
CAST_ULONG(ullSectorStart + ulSectorIdx));
|
|
|
|
if(iErr != 0)
|
|
|
|
if(iErr != 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ret = -RED_EIO;
|
|
|
|
ret = -RED_EIO;
|
|
|
@ -868,7 +877,7 @@ static REDSTATUS DiskOpen(
|
|
|
|
{
|
|
|
|
{
|
|
|
|
uint32_t ulSectorLast;
|
|
|
|
uint32_t ulSectorLast;
|
|
|
|
|
|
|
|
|
|
|
|
(void)sd_mmc_read_capacity(bVolNum, &ulSectorLast);
|
|
|
|
IGNORE_ERRORS(sd_mmc_read_capacity(bVolNum, &ulSectorLast));
|
|
|
|
|
|
|
|
|
|
|
|
/* The ASF SD/MMC driver only supports 512-byte sectors.
|
|
|
|
/* The ASF SD/MMC driver only supports 512-byte sectors.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -1027,6 +1036,337 @@ static REDSTATUS DiskFlush(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* REDCONF_READ_ONLY == 0 */
|
|
|
|
#endif /* REDCONF_READ_ONLY == 0 */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#elif BDEV_EXAMPLE_IMPLEMENTATION == BDEV_STM32_SDIO
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef USE_STM324xG_EVAL
|
|
|
|
|
|
|
|
#include <stm324xg_eval.h>
|
|
|
|
|
|
|
|
#include <stm324xg_eval_sd.h>
|
|
|
|
|
|
|
|
#elif defined(USE_STM32746G_DISCO)
|
|
|
|
|
|
|
|
#include <stm32746g_discovery.h>
|
|
|
|
|
|
|
|
#include <stm32746g_discovery_sd.h>
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
/* If you are using a compatible STM32 device other than the two listed above
|
|
|
|
|
|
|
|
and you have SD card driver headers, you can try adding them to the above
|
|
|
|
|
|
|
|
list.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#error "Unsupported device."
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if REDCONF_VOLUME_COUNT > 1
|
|
|
|
|
|
|
|
#error "The STM32 SDIO block device implementation does not support multiple volumes."
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef USE_HAL_DRIVER
|
|
|
|
|
|
|
|
#error "The STM32 StdPeriph driver is not supported. Please use the HAL driver or modify the Reliance Edge block device interface."
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @brief Number of times to call BSP_SD_GetStatus() before timing out and
|
|
|
|
|
|
|
|
returning an error.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
See ::CheckStatus().
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NOTE: Datalight has not observed a scenario where BSP_SD_GetStatus()
|
|
|
|
|
|
|
|
returns SD_TRANSFER_BUSY after a transfer command returns successfully.
|
|
|
|
|
|
|
|
Set SD_STATUS_TIMEOUT to 0U to skip checking BSP_SD_GetStatus().
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define SD_STATUS_TIMEOUT (100000U)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @brief 4-byte aligned buffer to use for DMA transfers when passed in
|
|
|
|
|
|
|
|
an unaligned buffer.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
static uint32_t gaulAlignedBuffer[512U / sizeof(uint32_t)];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if SD_STATUS_TIMEOUT > 0U
|
|
|
|
|
|
|
|
static REDSTATUS CheckStatus(void);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @brief Initialize a disk.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@param bVolNum The volume number of the volume whose block device is being
|
|
|
|
|
|
|
|
initialized.
|
|
|
|
|
|
|
|
@param mode The open mode, indicating the type of access required.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@return A negated ::REDSTATUS code indicating the operation result.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@retval 0 Operation was successful.
|
|
|
|
|
|
|
|
@retval -RED_EIO No SD card was found; or BSP_SD_Init() failed.
|
|
|
|
|
|
|
|
@retval -RED_EINVAL The SD card's block size is not the same as the
|
|
|
|
|
|
|
|
configured sector size; or the SD card is not large
|
|
|
|
|
|
|
|
enough for the volume; or the volume size is above
|
|
|
|
|
|
|
|
4GiB, meaning that part of it cannot be accessed
|
|
|
|
|
|
|
|
through the STM32 SDIO driver.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
static REDSTATUS DiskOpen(
|
|
|
|
|
|
|
|
uint8_t bVolNum,
|
|
|
|
|
|
|
|
BDEVOPENMODE mode)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
REDSTATUS ret = 0;
|
|
|
|
|
|
|
|
static bool fSdInitted = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(void) mode;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!fSdInitted)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(BSP_SD_Init() == MSD_OK)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
fSdInitted = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!fSdInitted)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
/* Above initialization attempt failed.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
ret = -RED_EIO;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if(BSP_SD_IsDetected() == SD_NOT_PRESENT)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
ret = -RED_EIO;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
uint32_t ulSectorSize = gaRedVolConf[bVolNum].ulSectorSize;
|
|
|
|
|
|
|
|
HAL_SD_CardInfoTypedef sdCardInfo = {{0}};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BSP_SD_GetCardInfo(&sdCardInfo);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Note: the actual card block size is sdCardInfo.CardBlockSize,
|
|
|
|
|
|
|
|
but the interface only supports a 512 byte block size. Further,
|
|
|
|
|
|
|
|
one card has been observed to report a 1024-byte block size,
|
|
|
|
|
|
|
|
but it worked fine with a 512-byte Reliance Edge ulSectorSize.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
if( (ulSectorSize != 512U)
|
|
|
|
|
|
|
|
|| (sdCardInfo.CardCapacity < (gaRedVolConf[bVolNum].ullSectorCount * ulSectorSize)))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
ret = -RED_EINVAL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @brief Uninitialize a disk.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@param bVolNum The volume number of the volume whose block device is being
|
|
|
|
|
|
|
|
uninitialized.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@return A negated ::REDSTATUS code indicating the operation result.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@retval 0 Operation was successful.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
static REDSTATUS DiskClose(
|
|
|
|
|
|
|
|
uint8_t bVolNum)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
(void)bVolNum;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @brief Read sectors from a disk.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@param bVolNum The volume number of the volume whose block device
|
|
|
|
|
|
|
|
is being read from.
|
|
|
|
|
|
|
|
@param ullSectorStart The starting sector number.
|
|
|
|
|
|
|
|
@param ulSectorCount The number of sectors to read.
|
|
|
|
|
|
|
|
@param pBuffer The buffer into which to read the sector data.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@return A negated ::REDSTATUS code indicating the operation result.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@retval 0 Operation was successful.
|
|
|
|
|
|
|
|
@retval -RED_EIO A disk I/O error occurred.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
static REDSTATUS DiskRead(
|
|
|
|
|
|
|
|
uint8_t bVolNum,
|
|
|
|
|
|
|
|
uint64_t ullSectorStart,
|
|
|
|
|
|
|
|
uint32_t ulSectorCount,
|
|
|
|
|
|
|
|
void *pBuffer)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
REDSTATUS redStat = 0;
|
|
|
|
|
|
|
|
uint32_t ulSectorSize = gaRedVolConf[bVolNum].ulSectorSize;
|
|
|
|
|
|
|
|
uint8_t bSdError;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(IS_UINT32_ALIGNED_PTR(pBuffer))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
bSdError = BSP_SD_ReadBlocks_DMA(CAST_UINT32_PTR(pBuffer), ullSectorStart * ulSectorSize, ulSectorSize, ulSectorCount);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(bSdError != MSD_OK)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
redStat = -RED_EIO;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#if SD_STATUS_TIMEOUT > 0U
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
redStat = CheckStatus();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
uint32_t ulSectorIdx;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(ulSectorIdx = 0U; ulSectorIdx < ulSectorCount; ulSectorIdx++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
bSdError = BSP_SD_ReadBlocks_DMA(gaulAlignedBuffer, (ullSectorStart + ulSectorIdx) * ulSectorSize, ulSectorSize, 1U);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(bSdError != MSD_OK)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
redStat = -RED_EIO;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#if SD_STATUS_TIMEOUT > 0U
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
redStat = CheckStatus();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(redStat == 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
uint8_t *pbBuffer = CAST_VOID_PTR_TO_UINT8_PTR(pBuffer);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RedMemCpy(&pbBuffer[ulSectorIdx * ulSectorSize], gaulAlignedBuffer, ulSectorSize);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return redStat;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if REDCONF_READ_ONLY == 0
|
|
|
|
|
|
|
|
/** @brief Write sectors to a disk.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@param bVolNum The volume number of the volume whose block device
|
|
|
|
|
|
|
|
is being written to.
|
|
|
|
|
|
|
|
@param ullSectorStart The starting sector number.
|
|
|
|
|
|
|
|
@param ulSectorCount The number of sectors to write.
|
|
|
|
|
|
|
|
@param pBuffer The buffer from which to write the sector data.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@return A negated ::REDSTATUS code indicating the operation result.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@retval 0 Operation was successful.
|
|
|
|
|
|
|
|
@retval -RED_EIO A disk I/O error occurred.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
static REDSTATUS DiskWrite(
|
|
|
|
|
|
|
|
uint8_t bVolNum,
|
|
|
|
|
|
|
|
uint64_t ullSectorStart,
|
|
|
|
|
|
|
|
uint32_t ulSectorCount,
|
|
|
|
|
|
|
|
const void *pBuffer)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
REDSTATUS redStat = 0;
|
|
|
|
|
|
|
|
uint32_t ulSectorSize = gaRedVolConf[bVolNum].ulSectorSize;
|
|
|
|
|
|
|
|
uint8_t bSdError;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(IS_UINT32_ALIGNED_PTR(pBuffer))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
bSdError = BSP_SD_WriteBlocks_DMA(CAST_UINT32_PTR(CAST_AWAY_CONST(void, pBuffer)), ullSectorStart * ulSectorSize,
|
|
|
|
|
|
|
|
ulSectorSize, ulSectorCount);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(bSdError != MSD_OK)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
redStat = -RED_EIO;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#if SD_STATUS_TIMEOUT > 0U
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
redStat = CheckStatus();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
uint32_t ulSectorIdx;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(ulSectorIdx = 0U; ulSectorIdx < ulSectorCount; ulSectorIdx++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
const uint8_t *pbBuffer = CAST_VOID_PTR_TO_CONST_UINT8_PTR(pBuffer);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RedMemCpy(gaulAlignedBuffer, &pbBuffer[ulSectorIdx * ulSectorSize], ulSectorSize);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bSdError = BSP_SD_WriteBlocks_DMA(gaulAlignedBuffer, (ullSectorStart + ulSectorIdx) * ulSectorSize, ulSectorSize, 1U);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(bSdError != MSD_OK)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
redStat = -RED_EIO;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#if SD_STATUS_TIMEOUT > 0U
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
redStat = CheckStatus();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(redStat != 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return redStat;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @brief Flush any caches beneath the file system.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@param bVolNum The volume number of the volume whose block device is being
|
|
|
|
|
|
|
|
flushed.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@return A negated ::REDSTATUS code indicating the operation result.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@retval 0 Operation was successful.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
static REDSTATUS DiskFlush(
|
|
|
|
|
|
|
|
uint8_t bVolNum)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
/* Disk transfer is synchronous; nothing to flush.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
(void) bVolNum;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if SD_STATUS_TIMEOUT > 0U
|
|
|
|
|
|
|
|
/** @brief Wait until BSP_SD_GetStatus returns SD_TRANSFER_OK.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
This function calls BSP_SD_GetStatus repeatedly as long as it returns
|
|
|
|
|
|
|
|
SD_TRANSFER_BUSY up to SD_STATUS_TIMEOUT times.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@return A negated ::REDSTATUS code indicating the operation result.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@retval 0 SD_TRANSFER_OK was returned.
|
|
|
|
|
|
|
|
@retval -RED_EIO SD_TRANSFER_ERROR received, or timed out waiting for
|
|
|
|
|
|
|
|
SD_TRANSFER_OK.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
static REDSTATUS CheckStatus(void)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
REDSTATUS redStat = 0;
|
|
|
|
|
|
|
|
uint32_t ulTimeout = SD_STATUS_TIMEOUT;
|
|
|
|
|
|
|
|
HAL_SD_TransferStateTypedef transferState;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
do
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
transferState = BSP_SD_GetStatus();
|
|
|
|
|
|
|
|
ulTimeout--;
|
|
|
|
|
|
|
|
} while((transferState == SD_TRANSFER_BUSY) && (ulTimeout > 0U));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(transferState != SD_TRANSFER_OK)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
redStat = -RED_EIO;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return redStat;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* REDCONF_READ_ONLY == 0 */
|
|
|
|
|
|
|
|
|
|
|
|
#elif BDEV_EXAMPLE_IMPLEMENTATION == BDEV_RAM_DISK
|
|
|
|
#elif BDEV_EXAMPLE_IMPLEMENTATION == BDEV_RAM_DISK
|
|
|
|
|
|
|
|
|
|
|
@ -1204,7 +1544,6 @@ static REDSTATUS DiskFlush(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* REDCONF_READ_ONLY == 0 */
|
|
|
|
#endif /* REDCONF_READ_ONLY == 0 */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
|
|
#error "Invalid BDEV_EXAMPLE_IMPLEMENTATION value"
|
|
|
|
#error "Invalid BDEV_EXAMPLE_IMPLEMENTATION value"
|
|
|
|