stm32_sdio.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * File : stm32_sdio.h
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2018-6-22 tyx first
  23. */
  24. #ifndef __STM32_SDIO_H__
  25. #define __STM32_SDIO_H__
  26. #include <rtthread.h>
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. #ifndef SDIO_BASE_ADDRESS
  31. #define SDIO_BASE_ADDRESS (0x40012800U)
  32. #endif
  33. #ifndef SDIO_CLOCK_FREQ
  34. #define SDIO_CLOCK_FREQ (48U * 1000 * 1000)
  35. #endif
  36. #ifndef SDIO_BUFF_SIZE
  37. #define SDIO_BUFF_SIZE (4096)
  38. #endif
  39. #ifndef SDIO_ALIGN
  40. #define SDIO_ALIGN (32)
  41. #endif
  42. #ifndef SDIO_MAX_FREQ
  43. #define SDIO_MAX_FREQ (24 * 1000 * 1000)
  44. #endif
  45. #define HW_SDIO_IT_CCRCFAIL (0x01U << 0)
  46. #define HW_SDIO_IT_DCRCFAIL (0x01U << 1)
  47. #define HW_SDIO_IT_CTIMEOUT (0x01U << 2)
  48. #define HW_SDIO_IT_DTIMEOUT (0x01U << 3)
  49. #define HW_SDIO_IT_TXUNDERR (0x01U << 4)
  50. #define HW_SDIO_IT_RXOVERR (0x01U << 5)
  51. #define HW_SDIO_IT_CMDREND (0x01U << 6)
  52. #define HW_SDIO_IT_CMDSENT (0x01U << 7)
  53. #define HW_SDIO_IT_DATAEND (0x01U << 8)
  54. #define HW_SDIO_IT_STBITERR (0x01U << 9)
  55. #define HW_SDIO_IT_DBCKEND (0x01U << 10)
  56. #define HW_SDIO_IT_CMDACT (0x01U << 11)
  57. #define HW_SDIO_IT_TXACT (0x01U << 12)
  58. #define HW_SDIO_IT_RXACT (0x01U << 13)
  59. #define HW_SDIO_IT_TXFIFOHE (0x01U << 14)
  60. #define HW_SDIO_IT_RXFIFOHF (0x01U << 15)
  61. #define HW_SDIO_IT_TXFIFOF (0x01U << 16)
  62. #define HW_SDIO_IT_RXFIFOF (0x01U << 17)
  63. #define HW_SDIO_IT_TXFIFOE (0x01U << 18)
  64. #define HW_SDIO_IT_RXFIFOE (0x01U << 19)
  65. #define HW_SDIO_IT_TXDAVL (0x01U << 20)
  66. #define HW_SDIO_IT_RXDAVL (0x01U << 21)
  67. #define HW_SDIO_IT_SDIOIT (0x01U << 22)
  68. #define HW_SDIO_ERRORS \
  69. (HW_SDIO_IT_CCRCFAIL | HW_SDIO_IT_CTIMEOUT | \
  70. HW_SDIO_IT_DCRCFAIL | HW_SDIO_IT_DTIMEOUT | \
  71. HW_SDIO_IT_RXOVERR | HW_SDIO_IT_TXUNDERR)
  72. #define HW_SDIO_POWER_OFF (0x00U)
  73. #define HW_SDIO_POWER_UP (0x02U)
  74. #define HW_SDIO_POWER_ON (0x03U)
  75. #define HW_SDIO_FLOW_ENABLE (0x01U << 14)
  76. #define HW_SDIO_BUSWIDE_1B (0x00U << 11)
  77. #define HW_SDIO_BUSWIDE_4B (0x01U << 11)
  78. #define HW_SDIO_BUSWIDE_8B (0x02U << 11)
  79. #define HW_SDIO_BYPASS_ENABLE (0x01U << 10)
  80. #define HW_SDIO_IDLE_ENABLE (0x01U << 9)
  81. #define HW_SDIO_CLK_ENABLE (0x01U << 8)
  82. #define HW_SDIO_SUSPEND_CMD (0x01U << 11)
  83. #define HW_SDIO_CPSM_ENABLE (0x01U << 10)
  84. #define HW_SDIO_WAIT_END (0x01U << 9)
  85. #define HW_SDIO_WAIT_INT (0x01U << 8)
  86. #define HW_SDIO_RESPONSE_NO (0x00U << 6)
  87. #define HW_SDIO_RESPONSE_SHORT (0x01U << 6)
  88. #define HW_SDIO_RESPONSE_LONG (0x03U << 6)
  89. #define HW_SDIO_DATA_LEN_MASK (0x01FFFFFFU)
  90. #define HW_SDIO_IO_ENABLE (0x01U << 11)
  91. #define HW_SDIO_RWMOD_CK (0x01U << 10)
  92. #define HW_SDIO_RWSTOP_ENABLE (0x01U << 9)
  93. #define HW_SDIO_RWSTART_ENABLE (0x01U << 8)
  94. #define HW_SDIO_DBLOCKSIZE_1 (0x00U << 4)
  95. #define HW_SDIO_DBLOCKSIZE_2 (0x01U << 4)
  96. #define HW_SDIO_DBLOCKSIZE_4 (0x02U << 4)
  97. #define HW_SDIO_DBLOCKSIZE_8 (0x03U << 4)
  98. #define HW_SDIO_DBLOCKSIZE_16 (0x04U << 4)
  99. #define HW_SDIO_DBLOCKSIZE_32 (0x05U << 4)
  100. #define HW_SDIO_DBLOCKSIZE_64 (0x06U << 4)
  101. #define HW_SDIO_DBLOCKSIZE_128 (0x07U << 4)
  102. #define HW_SDIO_DBLOCKSIZE_256 (0x08U << 4)
  103. #define HW_SDIO_DBLOCKSIZE_512 (0x09U << 4)
  104. #define HW_SDIO_DBLOCKSIZE_1024 (0x0AU << 4)
  105. #define HW_SDIO_DBLOCKSIZE_2048 (0x0BU << 4)
  106. #define HW_SDIO_DBLOCKSIZE_4096 (0x0CU << 4)
  107. #define HW_SDIO_DBLOCKSIZE_8192 (0x0DU << 4)
  108. #define HW_SDIO_DBLOCKSIZE_16384 (0x0EU << 4)
  109. #define HW_SDIO_DMA_ENABLE (0x01U << 3)
  110. #define HW_SDIO_STREAM_ENABLE (0x01U << 2)
  111. #define HW_SDIO_TO_HOST (0x01U << 1)
  112. #define HW_SDIO_DPSM_ENABLE (0x01U << 0)
  113. #define HW_SDIO_DATATIMEOUT (0xF0000000U)
  114. struct stm32_sdio
  115. {
  116. volatile rt_uint32_t power;
  117. volatile rt_uint32_t clkcr;
  118. volatile rt_uint32_t arg;
  119. volatile rt_uint32_t cmd;
  120. volatile rt_uint32_t respcmd;
  121. volatile rt_uint32_t resp1;
  122. volatile rt_uint32_t resp2;
  123. volatile rt_uint32_t resp3;
  124. volatile rt_uint32_t resp4;
  125. volatile rt_uint32_t dtimer;
  126. volatile rt_uint32_t dlen;
  127. volatile rt_uint32_t dctrl;
  128. volatile rt_uint32_t dcount;
  129. volatile rt_uint32_t sta;
  130. volatile rt_uint32_t icr;
  131. volatile rt_uint32_t mask;
  132. volatile rt_uint32_t reserved0[2];
  133. volatile rt_uint32_t fifocnt;
  134. volatile rt_uint32_t reserved1[13];
  135. volatile rt_uint32_t fifo;
  136. };
  137. typedef rt_err_t (*dma_txconfig)(rt_uint32_t *src, rt_uint32_t *dst, int size);
  138. typedef rt_err_t (*dma_rxconfig)(rt_uint32_t *src, rt_uint32_t *dst, int size);
  139. typedef rt_uint32_t (*sdio_clk_get)(struct stm32_sdio *hw_sdio);
  140. struct stm32_sdio_des
  141. {
  142. struct stm32_sdio *hw_sdio;
  143. dma_txconfig txconfig;
  144. dma_rxconfig rxconfig;
  145. sdio_clk_get clk_get;
  146. };
  147. struct rt_mmcsd_host *sdio_host_create(struct stm32_sdio_des *sdio_des);
  148. void rthw_sdio_irq_process(struct rt_mmcsd_host *host);
  149. #ifdef __cplusplus
  150. }
  151. #endif
  152. #endif