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 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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) 2021 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. SD_disk_initialize (pdrv);
  76. /* USER CODE END INIT */
  77. }
  78. /**
  79. * @brief Gets Disk Status
  80. * @param pdrv: Physical drive number (0..)
  81. * @retval DSTATUS: Operation status
  82. */
  83. DSTATUS USER_status (
  84. BYTE pdrv /* Physical drive number to identify the drive */
  85. )
  86. {
  87. /* USER CODE BEGIN STATUS */
  88. SD_disk_status (pdrv);
  89. /* USER CODE END STATUS */
  90. }
  91. /**
  92. * @brief Reads Sector(s)
  93. * @param pdrv: Physical drive number (0..)
  94. * @param *buff: Data buffer to store read data
  95. * @param sector: Sector address (LBA)
  96. * @param count: Number of sectors to read (1..128)
  97. * @retval DRESULT: Operation result
  98. */
  99. DRESULT USER_read (
  100. BYTE pdrv, /* Physical drive nmuber to identify the drive */
  101. BYTE *buff, /* Data buffer to store read data */
  102. DWORD sector, /* Sector address in LBA */
  103. UINT count /* Number of sectors to read */
  104. )
  105. {
  106. /* USER CODE BEGIN READ */
  107. SD_disk_read (pdrv, buff, sector, count);
  108. /* USER CODE END READ */
  109. }
  110. /**
  111. * @brief Writes Sector(s)
  112. * @param pdrv: Physical drive number (0..)
  113. * @param *buff: Data to be written
  114. * @param sector: Sector address (LBA)
  115. * @param count: Number of sectors to write (1..128)
  116. * @retval DRESULT: Operation result
  117. */
  118. #if _USE_WRITE == 1
  119. DRESULT USER_write (
  120. BYTE pdrv, /* Physical drive nmuber to identify the drive */
  121. const BYTE *buff, /* Data to be written */
  122. DWORD sector, /* Sector address in LBA */
  123. UINT count /* Number of sectors to write */
  124. )
  125. {
  126. /* USER CODE BEGIN WRITE */
  127. /* USER CODE HERE */
  128. SD_disk_write (pdrv, buff, sector, count);
  129. /* USER CODE END WRITE */
  130. }
  131. #endif /* _USE_WRITE == 1 */
  132. /**
  133. * @brief I/O control operation
  134. * @param pdrv: Physical drive number (0..)
  135. * @param cmd: Control code
  136. * @param *buff: Buffer to send/receive control data
  137. * @retval DRESULT: Operation result
  138. */
  139. #if _USE_IOCTL == 1
  140. DRESULT USER_ioctl (
  141. BYTE pdrv, /* Physical drive nmuber (0..) */
  142. BYTE cmd, /* Control code */
  143. void *buff /* Buffer to send/receive control data */
  144. )
  145. {
  146. /* USER CODE BEGIN IOCTL */
  147. SD_disk_ioctl (pdrv, cmd, buff);
  148. /* USER CODE END IOCTL */
  149. }
  150. #endif /* _USE_IOCTL == 1 */
  151. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/