You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

user_diskio.c 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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) 2020 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. /* Private typedef -----------------------------------------------------------*/
  37. /* Private define ------------------------------------------------------------*/
  38. /* Private variables ---------------------------------------------------------*/
  39. /* Disk status */
  40. static volatile DSTATUS Stat = STA_NOINIT;
  41. /* USER CODE END DECL */
  42. /* Private function prototypes -----------------------------------------------*/
  43. DSTATUS USER_initialize (BYTE pdrv);
  44. DSTATUS USER_status (BYTE pdrv);
  45. DRESULT USER_read (BYTE pdrv, BYTE *buff, DWORD sector, UINT count);
  46. #if _USE_WRITE == 1
  47. DRESULT USER_write (BYTE pdrv, const BYTE *buff, DWORD sector, UINT count);
  48. #endif /* _USE_WRITE == 1 */
  49. #if _USE_IOCTL == 1
  50. DRESULT USER_ioctl (BYTE pdrv, BYTE cmd, void *buff);
  51. #endif /* _USE_IOCTL == 1 */
  52. Diskio_drvTypeDef USER_Driver =
  53. {
  54. USER_initialize,
  55. USER_status,
  56. USER_read,
  57. #if _USE_WRITE
  58. USER_write,
  59. #endif /* _USE_WRITE == 1 */
  60. #if _USE_IOCTL == 1
  61. USER_ioctl,
  62. #endif /* _USE_IOCTL == 1 */
  63. };
  64. /* Private functions ---------------------------------------------------------*/
  65. /**
  66. * @brief Initializes a Drive
  67. * @param pdrv: Physical drive number (0..)
  68. * @retval DSTATUS: Operation status
  69. */
  70. DSTATUS USER_initialize (
  71. BYTE pdrv /* Physical drive nmuber to identify the drive */
  72. )
  73. {
  74. /* USER CODE BEGIN INIT */
  75. //Stat = STA_NOINIT;
  76. //return Stat;
  77. SD_disk_initialize (pdrv);
  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 USER_status (
  86. BYTE pdrv /* Physical drive number to identify the drive */
  87. )
  88. {
  89. /* USER CODE BEGIN STATUS */
  90. //Stat = STA_NOINIT;
  91. //return Stat;
  92. SD_disk_status (pdrv);
  93. /* USER CODE END STATUS */
  94. }
  95. /**
  96. * @brief Reads Sector(s)
  97. * @param pdrv: Physical drive number (0..)
  98. * @param *buff: Data buffer to store read data
  99. * @param sector: Sector address (LBA)
  100. * @param count: Number of sectors to read (1..128)
  101. * @retval DRESULT: Operation result
  102. */
  103. DRESULT USER_read (
  104. BYTE pdrv, /* Physical drive nmuber to identify the drive */
  105. BYTE *buff, /* Data buffer to store read data */
  106. DWORD sector, /* Sector address in LBA */
  107. UINT count /* Number of sectors to read */
  108. )
  109. {
  110. /* USER CODE BEGIN READ */
  111. //return RES_OK;
  112. SD_disk_read (pdrv, buff, sector, count);
  113. /* USER CODE END READ */
  114. }
  115. /**
  116. * @brief Writes Sector(s)
  117. * @param pdrv: Physical drive number (0..)
  118. * @param *buff: Data to be written
  119. * @param sector: Sector address (LBA)
  120. * @param count: Number of sectors to write (1..128)
  121. * @retval DRESULT: Operation result
  122. */
  123. #if _USE_WRITE == 1
  124. DRESULT USER_write (
  125. BYTE pdrv, /* Physical drive nmuber to identify the drive */
  126. const BYTE *buff, /* Data to be written */
  127. DWORD sector, /* Sector address in LBA */
  128. UINT count /* Number of sectors to write */
  129. )
  130. {
  131. /* USER CODE BEGIN WRITE */
  132. /* USER CODE HERE */
  133. //return RES_OK;
  134. SD_disk_write (pdrv, buff, sector, count);
  135. /* USER CODE END WRITE */
  136. }
  137. #endif /* _USE_WRITE == 1 */
  138. /**
  139. * @brief I/O control operation
  140. * @param pdrv: Physical drive number (0..)
  141. * @param cmd: Control code
  142. * @param *buff: Buffer to send/receive control data
  143. * @retval DRESULT: Operation result
  144. */
  145. #if _USE_IOCTL == 1
  146. DRESULT USER_ioctl (
  147. BYTE pdrv, /* Physical drive nmuber (0..) */
  148. BYTE cmd, /* Control code */
  149. void *buff /* Buffer to send/receive control data */
  150. )
  151. {
  152. /* USER CODE BEGIN IOCTL */
  153. //DRESULT res = RES_ERROR;
  154. //return res;
  155. SD_disk_ioctl (pdrv, cmd, buff);
  156. /* USER CODE END IOCTL */
  157. }
  158. #endif /* _USE_IOCTL == 1 */
  159. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/