sdcard_diskio.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file user_diskio.c
  5. * @brief This file includes a diskio driver skeleton to be completed by the user.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under Ultimate Liberty license
  13. * SLA0044, the "License"; You may not use this file except in compliance with
  14. * the License. You may obtain a copy of the License at:
  15. * www.st.com/SLA0044
  16. *
  17. ******************************************************************************
  18. */
  19. /* USER CODE END Header */
  20. #ifdef USE_OBSOLETE_USER_CODE_SECTION_0
  21. /*
  22. * Warning: the user section 0 is no more in use (starting from CubeMx version 4.16.0)
  23. * To be suppressed in the future.
  24. * Kept to ensure backward compatibility with previous CubeMx versions when
  25. * migrating projects.
  26. * User code previously added there should be copied in the new user sections before
  27. * the section contents can be deleted.
  28. */
  29. /* USER CODE BEGIN 0 */
  30. /* USER CODE END 0 */
  31. #endif
  32. /* USER CODE BEGIN DECL */
  33. /* Includes ------------------------------------------------------------------*/
  34. #include <string.h>
  35. #include "ff_gen_drv.h"
  36. #include "obj_spi_sd_stm32.h"
  37. /* Private typedef -----------------------------------------------------------*/
  38. /* Private define ------------------------------------------------------------*/
  39. /* Private variables ---------------------------------------------------------*/
  40. /* Disk status */
  41. static volatile DSTATUS Stat = STA_NOINIT;
  42. /* USER CODE END DECL */
  43. /* Private function prototypes -----------------------------------------------*/
  44. DSTATUS sdcard_initialize (BYTE pdrv);
  45. DSTATUS sdcard_status (BYTE pdrv);
  46. DRESULT sdcard_read (BYTE pdrv, BYTE *buff, DWORD sector, UINT count);
  47. #if _USE_WRITE == 1
  48. DRESULT sdcard_write (BYTE pdrv, const BYTE *buff, DWORD sector, UINT count);
  49. #endif /* _USE_WRITE == 1 */
  50. #if _USE_IOCTL == 1
  51. DRESULT sdcard_ioctl (BYTE pdrv, BYTE cmd, void *buff);
  52. #endif /* _USE_IOCTL == 1 */
  53. Diskio_drvTypeDef sdcard_Driver =
  54. {
  55. sdcard_initialize,
  56. sdcard_status,
  57. sdcard_read,
  58. #if _USE_WRITE
  59. sdcard_write,
  60. #endif /* _USE_WRITE == 1 */
  61. #if _USE_IOCTL == 1
  62. sdcard_ioctl,
  63. #endif /* _USE_IOCTL == 1 */
  64. };
  65. /* Private functions ---------------------------------------------------------*/
  66. /**
  67. * @brief Initializes a Drive
  68. * @param pdrv: Physical drive number (0..)
  69. * @retval DSTATUS: Operation status
  70. */
  71. DSTATUS sdcard_initialize (
  72. BYTE pdrv /* Physical drive nmuber to identify the drive */
  73. )
  74. {
  75. /* USER CODE BEGIN INIT */
  76. Stat = SD_disk_initialize(pdrv);
  77. return Stat;
  78. /* USER CODE END INIT */
  79. }
  80. /**
  81. * @brief Gets Disk Status
  82. * @param pdrv: Physical drive number (0..)
  83. * @retval DSTATUS: Operation status
  84. */
  85. DSTATUS sdcard_status (
  86. BYTE pdrv /* Physical drive number to identify the drive */
  87. )
  88. {
  89. /* USER CODE BEGIN STATUS */
  90. Stat = SD_disk_status(pdrv);
  91. return Stat;
  92. /* USER CODE END STATUS */
  93. }
  94. /**
  95. * @brief Reads Sector(s)
  96. * @param pdrv: Physical drive number (0..)
  97. * @param *buff: Data buffer to store read data
  98. * @param sector: Sector address (LBA)
  99. * @param count: Number of sectors to read (1..128)
  100. * @retval DRESULT: Operation result
  101. */
  102. DRESULT sdcard_read (
  103. BYTE pdrv, /* Physical drive nmuber to identify the drive */
  104. BYTE *buff, /* Data buffer to store read data */
  105. DWORD sector, /* Sector address in LBA */
  106. UINT count /* Number of sectors to read */
  107. )
  108. {
  109. /* USER CODE BEGIN READ */
  110. return SD_disk_read(pdrv, buff, sector, count);
  111. /* USER CODE END READ */
  112. }
  113. /**
  114. * @brief Writes Sector(s)
  115. * @param pdrv: Physical drive number (0..)
  116. * @param *buff: Data to be written
  117. * @param sector: Sector address (LBA)
  118. * @param count: Number of sectors to write (1..128)
  119. * @retval DRESULT: Operation result
  120. */
  121. #if _USE_WRITE == 1
  122. DRESULT sdcard_write (
  123. BYTE pdrv, /* Physical drive nmuber to identify the drive */
  124. const BYTE *buff, /* Data to be written */
  125. DWORD sector, /* Sector address in LBA */
  126. UINT count /* Number of sectors to write */
  127. )
  128. {
  129. /* USER CODE BEGIN WRITE */
  130. /* USER CODE HERE */
  131. return SD_disk_write(pdrv, buff, sector, count);
  132. /* USER CODE END WRITE */
  133. }
  134. #endif /* _USE_WRITE == 1 */
  135. /**
  136. * @brief I/O control operation
  137. * @param pdrv: Physical drive number (0..)
  138. * @param cmd: Control code
  139. * @param *buff: Buffer to send/receive control data
  140. * @retval DRESULT: Operation result
  141. */
  142. #if _USE_IOCTL == 1
  143. DRESULT sdcard_ioctl (
  144. BYTE pdrv, /* Physical drive nmuber (0..) */
  145. BYTE cmd, /* Control code */
  146. void *buff /* Buffer to send/receive control data */
  147. )
  148. {
  149. /* USER CODE BEGIN IOCTL */
  150. DRESULT res = SD_disk_ioctl(pdrv, cmd, buff);
  151. return res;
  152. /* USER CODE END IOCTL */
  153. }
  154. #endif /* _USE_IOCTL == 1 */
  155. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/