fsl_qspi.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  1. /*
  2. * The Clear BSD License
  3. * Copyright (c) 2015, Freescale Semiconductor, Inc.
  4. * Copyright 2016-2017 NXP
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without modification,
  8. * are permitted (subject to the limitations in the disclaimer below) provided
  9. * that the following conditions are met:
  10. *
  11. * o Redistributions of source code must retain the above copyright notice, this list
  12. * of conditions and the following disclaimer.
  13. *
  14. * o Redistributions in binary form must reproduce the above copyright notice, this
  15. * list of conditions and the following disclaimer in the documentation and/or
  16. * other materials provided with the distribution.
  17. *
  18. * o Neither the name of the copyright holder nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  24. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  25. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  26. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  27. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  28. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  29. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  30. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  31. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  32. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #ifndef _FSL_QSPI_H_
  35. #define _FSL_QSPI_H_
  36. #include "fsl_common.h"
  37. /*!
  38. * @addtogroup qspi
  39. * @{
  40. */
  41. /*******************************************************************************
  42. * Definitions
  43. ******************************************************************************/
  44. /*! @name Driver version */
  45. /*@{*/
  46. /*! @brief QSPI driver version 2.0.2. */
  47. #define FSL_QSPI_DRIVER_VERSION (MAKE_VERSION(2, 0, 2))
  48. /*@}*/
  49. /*! @brief Macro functions for LUT table */
  50. #define QSPI_LUT_SEQ(cmd0, pad0, op0, cmd1, pad1, op1) \
  51. (QuadSPI_LUT_INSTR0(cmd0) | QuadSPI_LUT_PAD0(pad0) | QuadSPI_LUT_OPRND0(op0) | QuadSPI_LUT_INSTR1(cmd1) | \
  52. QuadSPI_LUT_PAD1(pad1) | QuadSPI_LUT_OPRND1(op1))
  53. /*! @brief Macro for QSPI LUT command */
  54. #define QSPI_CMD (0x1U)
  55. #define QSPI_ADDR (0x2U)
  56. #define QSPI_DUMMY (0x3U)
  57. #define QSPI_MODE (0x4U)
  58. #define QSPI_MODE2 (0x5U)
  59. #define QSPI_MODE4 (0x6U)
  60. #define QSPI_READ (0x7U)
  61. #define QSPI_WRITE (0x8U)
  62. #define QSPI_JMP_ON_CS (0x9U)
  63. #define QSPI_ADDR_DDR (0xAU)
  64. #define QSPI_MODE_DDR (0xBU)
  65. #define QSPI_MODE2_DDR (0xCU)
  66. #define QSPI_MODE4_DDR (0xDU)
  67. #define QSPI_READ_DDR (0xEU)
  68. #define QSPI_WRITE_DDR (0xFU)
  69. #define QSPI_DATA_LEARN (0x10U)
  70. #define QSPI_CMD_DDR (0x11U)
  71. #define QSPI_CADDR (0x12U)
  72. #define QSPI_CADDR_DDR (0x13U)
  73. #define QSPI_STOP (0x0U)
  74. /*! @brief Macro for QSPI PAD */
  75. #define QSPI_PAD_1 (0x0U)
  76. #define QSPI_PAD_2 (0x1U)
  77. #define QSPI_PAD_4 (0x2U)
  78. #define QSPI_PAD_8 (0x3U)
  79. /*! @brief Status structure of QSPI.*/
  80. enum _status_t
  81. {
  82. kStatus_QSPI_Idle = MAKE_STATUS(kStatusGroup_QSPI, 0), /*!< QSPI is in idle state */
  83. kStatus_QSPI_Busy = MAKE_STATUS(kStatusGroup_QSPI, 1), /*!< QSPI is busy */
  84. kStatus_QSPI_Error = MAKE_STATUS(kStatusGroup_QSPI, 2), /*!< Error occurred during QSPI transfer */
  85. };
  86. /*! @brief QSPI read data area, from IP FIFO or AHB buffer.*/
  87. typedef enum _qspi_read_area
  88. {
  89. kQSPI_ReadAHB = 0x0U, /*!< QSPI read from AHB buffer. */
  90. kQSPI_ReadIP /*!< QSPI read from IP FIFO. */
  91. } qspi_read_area_t;
  92. /*! @brief QSPI command sequence type */
  93. typedef enum _qspi_command_seq
  94. {
  95. kQSPI_IPSeq = QuadSPI_SPTRCLR_IPPTRC_MASK, /*!< IP command sequence */
  96. kQSPI_BufferSeq = QuadSPI_SPTRCLR_BFPTRC_MASK, /*!< Buffer command sequence */
  97. kQSPI_AllSeq = QuadSPI_SPTRCLR_IPPTRC_MASK | QuadSPI_SPTRCLR_BFPTRC_MASK /* All command sequence */
  98. } qspi_command_seq_t;
  99. /*! @brief QSPI buffer type */
  100. typedef enum _qspi_fifo
  101. {
  102. kQSPI_TxFifo = QuadSPI_MCR_CLR_TXF_MASK, /*!< QSPI Tx FIFO */
  103. kQSPI_RxFifo = QuadSPI_MCR_CLR_RXF_MASK, /*!< QSPI Rx FIFO */
  104. kQSPI_AllFifo = QuadSPI_MCR_CLR_TXF_MASK | QuadSPI_MCR_CLR_RXF_MASK /*!< QSPI all FIFO, including Tx and Rx */
  105. } qspi_fifo_t;
  106. /*! @brief QSPI transfer endianess*/
  107. typedef enum _qspi_endianness
  108. {
  109. kQSPI_64BigEndian = 0x0U, /*!< 64 bits big endian */
  110. kQSPI_32LittleEndian, /*!< 32 bit little endian */
  111. kQSPI_32BigEndian, /*!< 32 bit big endian */
  112. kQSPI_64LittleEndian /*!< 64 bit little endian */
  113. } qspi_endianness_t;
  114. /*! @brief QSPI error flags */
  115. enum _qspi_error_flags
  116. {
  117. kQSPI_DataLearningFail = QuadSPI_FR_DLPFF_MASK, /*!< Data learning pattern failure flag */
  118. kQSPI_TxBufferFill = QuadSPI_FR_TBFF_MASK, /*!< Tx buffer fill flag */
  119. kQSPI_TxBufferUnderrun = QuadSPI_FR_TBUF_MASK, /*!< Tx buffer underrun flag */
  120. kQSPI_IllegalInstruction = QuadSPI_FR_ILLINE_MASK, /*!< Illegal instruction error flag */
  121. kQSPI_RxBufferOverflow = QuadSPI_FR_RBOF_MASK, /*!< Rx buffer overflow flag */
  122. kQSPI_RxBufferDrain = QuadSPI_FR_RBDF_MASK, /*!< Rx buffer drain flag */
  123. kQSPI_AHBSequenceError = QuadSPI_FR_ABSEF_MASK, /*!< AHB sequence error flag */
  124. #if !defined(FSL_FEATURE_QSPI_HAS_NO_AITEF) || (!FSL_FEATURE_QSPI_HAS_NO_AITEF)
  125. kQSPI_AHBIllegalTransaction = QuadSPI_FR_AITEF_MASK, /*!< AHB illegal transaction error flag */
  126. #endif /* FSL_FEATURE_QSPI_HAS_NO_AITEF */
  127. #if !defined(FSL_FEATURE_QSPI_HAS_NO_AIBSEF) || (!FSL_FEATURE_QSPI_HAS_NO_AIBSEF)
  128. kQSPI_AHBIllegalBurstSize = QuadSPI_FR_AIBSEF_MASK, /*!< AHB illegal burst error flag */
  129. #endif /* FSL_FEATURE_QSPI_HAS_NO_AIBSEF */
  130. kQSPI_AHBBufferOverflow = QuadSPI_FR_ABOF_MASK, /*!< AHB buffer overflow flag */
  131. #if defined(FSL_FEATURE_QSPI_HAS_IP_COMMAND_USAGE_ERROR) && (FSL_FEATURE_QSPI_HAS_IP_COMMAND_USAGE_ERROR)
  132. kQSPI_IPCommandUsageError = QuadSPI_FR_IUEF_MASK, /*!< IP command usage error flag */
  133. #endif /* FSL_FEATURE_QSPI_HAS_IP_COMMAND_USAGE_ERROR */
  134. kQSPI_IPCommandTriggerDuringAHBAccess = QuadSPI_FR_IPAEF_MASK, /*!< IP command trigger during AHB access error */
  135. kQSPI_IPCommandTriggerDuringIPAccess = QuadSPI_FR_IPIEF_MASK, /*!< IP command trigger cannot be executed */
  136. kQSPI_IPCommandTriggerDuringAHBGrant = QuadSPI_FR_IPGEF_MASK, /*!< IP command trigger during AHB grant error */
  137. kQSPI_IPCommandTransactionFinished = QuadSPI_FR_TFF_MASK, /*!< IP command transaction finished flag */
  138. kQSPI_FlagAll = 0x8C83F8D1U /*!< All error flag */
  139. };
  140. /*! @brief QSPI state bit */
  141. enum _qspi_flags
  142. {
  143. kQSPI_DataLearningSamplePoint = QuadSPI_SR_DLPSMP_MASK, /*!< Data learning sample point */
  144. kQSPI_TxBufferFull = QuadSPI_SR_TXFULL_MASK, /*!< Tx buffer full flag */
  145. #if !defined(FSL_FEATURE_QSPI_HAS_NO_TXDMA) || (!FSL_FEATURE_QSPI_HAS_NO_TXDMA)
  146. kQSPI_TxDMA = QuadSPI_SR_TXDMA_MASK, /*!< Tx DMA is requested or running */
  147. kQSPI_TxWatermark = QuadSPI_SR_TXWA_MASK, /*!< Tx buffer watermark available */
  148. #endif /* FSL_FEATURE_QSPI_HAS_NO_TXDMA */
  149. kQSPI_TxBufferEnoughData = QuadSPI_SR_TXEDA_MASK, /*!< Tx buffer enough data available */
  150. kQSPI_RxDMA = QuadSPI_SR_RXDMA_MASK, /*!< Rx DMA is requesting or running */
  151. kQSPI_RxBufferFull = QuadSPI_SR_RXFULL_MASK, /*!< Rx buffer full */
  152. kQSPI_RxWatermark = QuadSPI_SR_RXWE_MASK, /*!< Rx buffer watermark exceeded */
  153. kQSPI_AHB3BufferFull = QuadSPI_SR_AHB3FUL_MASK, /*!< AHB buffer 3 full*/
  154. kQSPI_AHB2BufferFull = QuadSPI_SR_AHB2FUL_MASK, /*!< AHB buffer 2 full */
  155. kQSPI_AHB1BufferFull = QuadSPI_SR_AHB1FUL_MASK, /*!< AHB buffer 1 full */
  156. kQSPI_AHB0BufferFull = QuadSPI_SR_AHB0FUL_MASK, /*!< AHB buffer 0 full */
  157. kQSPI_AHB3BufferNotEmpty = QuadSPI_SR_AHB3NE_MASK, /*!< AHB buffer 3 not empty */
  158. kQSPI_AHB2BufferNotEmpty = QuadSPI_SR_AHB2NE_MASK, /*!< AHB buffer 2 not empty */
  159. kQSPI_AHB1BufferNotEmpty = QuadSPI_SR_AHB1NE_MASK, /*!< AHB buffer 1 not empty */
  160. kQSPI_AHB0BufferNotEmpty = QuadSPI_SR_AHB0NE_MASK, /*!< AHB buffer 0 not empty */
  161. kQSPI_AHBTransactionPending = QuadSPI_SR_AHBTRN_MASK, /*!< AHB access transaction pending */
  162. kQSPI_AHBCommandPriorityGranted = QuadSPI_SR_AHBGNT_MASK, /*!< AHB command priority granted */
  163. kQSPI_AHBAccess = QuadSPI_SR_AHB_ACC_MASK, /*!< AHB access */
  164. kQSPI_IPAccess = QuadSPI_SR_IP_ACC_MASK, /*!< IP access */
  165. kQSPI_Busy = QuadSPI_SR_BUSY_MASK, /*!< Module busy */
  166. kQSPI_StateAll = 0xEF897FE7U /*!< All flags */
  167. };
  168. /*! @brief QSPI interrupt enable */
  169. enum _qspi_interrupt_enable
  170. {
  171. kQSPI_DataLearningFailInterruptEnable =
  172. QuadSPI_RSER_DLPFIE_MASK, /*!< Data learning pattern failure interrupt enable */
  173. kQSPI_TxBufferFillInterruptEnable = QuadSPI_RSER_TBFIE_MASK, /*!< Tx buffer fill interrupt enable */
  174. kQSPI_TxBufferUnderrunInterruptEnable = QuadSPI_RSER_TBUIE_MASK, /*!< Tx buffer underrun interrupt enable */
  175. kQSPI_IllegalInstructionInterruptEnable =
  176. QuadSPI_RSER_ILLINIE_MASK, /*!< Illegal instruction error interrupt enable */
  177. kQSPI_RxBufferOverflowInterruptEnable = QuadSPI_RSER_RBOIE_MASK, /*!< Rx buffer overflow interrupt enable */
  178. kQSPI_RxBufferDrainInterruptEnable = QuadSPI_RSER_RBDIE_MASK, /*!< Rx buffer drain interrupt enable */
  179. kQSPI_AHBSequenceErrorInterruptEnable = QuadSPI_RSER_ABSEIE_MASK, /*!< AHB sequence error interrupt enable */
  180. #if !defined(FSL_FEATURE_QSPI_HAS_NO_AITEF) || (!FSL_FEATURE_QSPI_HAS_NO_AITEF)
  181. kQSPI_AHBIllegalTransactionInterruptEnable =
  182. QuadSPI_RSER_AITIE_MASK, /*!< AHB illegal transaction error interrupt enable */
  183. #endif /* FSL_FEATURE_QSPI_HAS_NO_AITEF */
  184. #if !defined(FSL_FEATURE_QSPI_HAS_NO_AIBSEF) || (!FSL_FEATURE_QSPI_HAS_NO_AIBSEF)
  185. kQSPI_AHBIllegalBurstSizeInterruptEnable =
  186. QuadSPI_RSER_AIBSIE_MASK, /*!< AHB illegal burst error interrupt enable */
  187. #endif /* FSL_FEATURE_QSPI_HAS_NO_AIBSEF */
  188. kQSPI_AHBBufferOverflowInterruptEnable = QuadSPI_RSER_ABOIE_MASK, /*!< AHB buffer overflow interrupt enable */
  189. #if defined(FSL_FEATURE_QSPI_HAS_IP_COMMAND_USAGE_ERROR) && (FSL_FEATURE_QSPI_HAS_IP_COMMAND_USAGE_ERROR)
  190. kQSPI_IPCommandUsageErrorInterruptEnable = QuadSPI_RSER_IUEIE_MASK, /*!< IP command usage error interrupt enable */
  191. #endif /* FSL_FEATURE_QSPI_HAS_IP_COMMAND_USAGE_ERROR */
  192. kQSPI_IPCommandTriggerDuringAHBAccessInterruptEnable =
  193. QuadSPI_RSER_IPAEIE_MASK, /*!< IP command trigger during AHB access error */
  194. kQSPI_IPCommandTriggerDuringIPAccessInterruptEnable =
  195. QuadSPI_RSER_IPIEIE_MASK, /*!< IP command trigger cannot be executed */
  196. kQSPI_IPCommandTriggerDuringAHBGrantInterruptEnable =
  197. QuadSPI_RSER_IPGEIE_MASK, /*!< IP command trigger during AHB grant error */
  198. kQSPI_IPCommandTransactionFinishedInterruptEnable =
  199. QuadSPI_RSER_TFIE_MASK, /*!< IP command transaction finished interrupt enable */
  200. kQSPI_AllInterruptEnable = 0x8C83F8D1U /*!< All error interrupt enable */
  201. };
  202. /*! @brief QSPI DMA request flag */
  203. enum _qspi_dma_enable
  204. {
  205. #if !defined(FSL_FEATURE_QSPI_HAS_NO_TXDMA) || (!FSL_FEATURE_QSPI_HAS_NO_TXDMA)
  206. kQSPI_TxBufferFillDMAEnable = QuadSPI_RSER_TBFDE_MASK, /*!< Tx buffer fill DMA */
  207. #endif /* FSL_FEATURE_QSPI_HAS_NO_TXDMA */
  208. kQSPI_RxBufferDrainDMAEnable = QuadSPI_RSER_RBDDE_MASK, /*!< Rx buffer drain DMA */
  209. #if !defined(FSL_FEATURE_QSPI_HAS_NO_TXDMA) || (!FSL_FEATURE_QSPI_HAS_NO_TXDMA)
  210. kQSPI_AllDDMAEnable = QuadSPI_RSER_TBFDE_MASK | QuadSPI_RSER_RBDDE_MASK /*!< All DMA source */
  211. #else
  212. kQSPI_AllDDMAEnable = QuadSPI_RSER_RBDDE_MASK /* All DMA source */
  213. #endif /* FSL_FEATURE_QSPI_HAS_NO_TXDMA */
  214. };
  215. /*! @brief Phrase shift number for DQS mode. */
  216. typedef enum _qspi_dqs_phrase_shift
  217. {
  218. kQSPI_DQSNoPhraseShift = 0x0U, /*!< No phase shift */
  219. kQSPI_DQSPhraseShift45Degree, /*!< Select 45 degree phase shift*/
  220. kQSPI_DQSPhraseShift90Degree, /*!< Select 90 degree phase shift */
  221. kQSPI_DQSPhraseShift135Degree /*!< Select 135 degree phase shift */
  222. } qspi_dqs_phrase_shift_t;
  223. /*! @brief DQS configure features*/
  224. typedef struct QspiDQSConfig
  225. {
  226. uint32_t portADelayTapNum; /*!< Delay chain tap number selection for QSPI port A DQS */
  227. uint32_t portBDelayTapNum; /*!< Delay chain tap number selection for QSPI port B DQS*/
  228. qspi_dqs_phrase_shift_t shift; /*!< Phase shift for internal DQS generation */
  229. bool enableDQSClkInverse; /*!< Enable inverse clock for internal DQS generation */
  230. bool enableDQSPadLoopback; /*!< Enable DQS loop back from DQS pad */
  231. bool enableDQSLoopback; /*!< Enable DQS loop back */
  232. } qspi_dqs_config_t;
  233. /*! @brief Flash timing configuration. */
  234. typedef struct QspiFlashTiming
  235. {
  236. uint32_t dataHoldTime; /*!< Serial flash data in hold time */
  237. uint32_t CSHoldTime; /*!< Serial flash CS hold time in terms of serial flash clock cycles */
  238. uint32_t CSSetupTime; /*!< Serial flash CS setup time in terms of serial flash clock cycles */
  239. } qspi_flash_timing_t;
  240. /*! @brief QSPI configuration structure*/
  241. typedef struct QspiConfig
  242. {
  243. uint32_t clockSource; /*!< Clock source for QSPI module */
  244. uint32_t baudRate; /*!< Serial flash clock baud rate */
  245. uint8_t txWatermark; /*!< QSPI transmit watermark value */
  246. uint8_t rxWatermark; /*!< QSPI receive watermark value. */
  247. uint32_t AHBbufferSize[FSL_FEATURE_QSPI_AHB_BUFFER_COUNT]; /*!< AHB buffer size. */
  248. uint8_t AHBbufferMaster[FSL_FEATURE_QSPI_AHB_BUFFER_COUNT]; /*!< AHB buffer master. */
  249. bool enableAHBbuffer3AllMaster; /*!< Is AHB buffer3 for all master.*/
  250. qspi_read_area_t area; /*!< Which area Rx data readout */
  251. bool enableQspi; /*!< Enable QSPI after initialization */
  252. } qspi_config_t;
  253. /*! @brief External flash configuration items*/
  254. typedef struct _qspi_flash_config
  255. {
  256. uint32_t flashA1Size; /*!< Flash A1 size */
  257. uint32_t flashA2Size; /*!< Flash A2 size */
  258. #if defined(FSL_FEATURE_QSPI_SUPPORT_PARALLEL_MODE) && (FSL_FEATURE_QSPI_SUPPORT_PARALLEL_MODE)
  259. uint32_t flashB1Size; /*!< Flash B1 size */
  260. uint32_t flashB2Size; /*!< Flash B2 size */
  261. #endif /* FSL_FEATURE_QSPI_SUPPORT_PARALLEL_MODE */
  262. uint32_t lookuptable[FSL_FEATURE_QSPI_LUT_DEPTH]; /*!< Flash command in LUT */
  263. #if !defined(FSL_FEATURE_QSPI_HAS_NO_TDH) || (!FSL_FEATURE_QSPI_HAS_NO_TDH)
  264. uint32_t dataHoldTime; /*!< Data line hold time. */
  265. #endif /* FSL_FEATURE_QSPI_HAS_NO_TDH */
  266. uint32_t CSHoldTime; /*!< CS line hold time */
  267. uint32_t CSSetupTime; /*!< CS line setup time*/
  268. uint32_t cloumnspace; /*!< Column space size */
  269. uint32_t dataLearnValue; /*!< Data Learn value if enable data learn */
  270. qspi_endianness_t endian; /*!< Flash data endianess. */
  271. bool enableWordAddress; /*!< If enable word address.*/
  272. } qspi_flash_config_t;
  273. /*! @brief Transfer structure for QSPI */
  274. typedef struct _qspi_transfer
  275. {
  276. uint32_t *data; /*!< Pointer to data to transmit */
  277. size_t dataSize; /*!< Bytes to be transmit */
  278. } qspi_transfer_t;
  279. /******************************************************************************
  280. * API
  281. *****************************************************************************/
  282. #if defined(__cplusplus)
  283. extern "C" {
  284. #endif
  285. /*!
  286. * @name Initialization and deinitialization
  287. * @{
  288. */
  289. /*!
  290. * @brief Get the instance number for QSPI.
  291. *
  292. * @param base QSPI base pointer.
  293. */
  294. uint32_t QSPI_GetInstance(QuadSPI_Type *base);
  295. /*!
  296. * @brief Initializes the QSPI module and internal state.
  297. *
  298. * This function enables the clock for QSPI and also configures the QSPI with the
  299. * input configure parameters. Users should call this function before any QSPI operations.
  300. *
  301. * @param base Pointer to QuadSPI Type.
  302. * @param config QSPI configure structure.
  303. * @param srcClock_Hz QSPI source clock frequency in Hz.
  304. */
  305. void QSPI_Init(QuadSPI_Type *base, qspi_config_t *config, uint32_t srcClock_Hz);
  306. /*!
  307. * @brief Gets default settings for QSPI.
  308. *
  309. * @param config QSPI configuration structure.
  310. */
  311. void QSPI_GetDefaultQspiConfig(qspi_config_t *config);
  312. /*!
  313. * @brief Deinitializes the QSPI module.
  314. *
  315. * Clears the QSPI state and QSPI module registers.
  316. * @param base Pointer to QuadSPI Type.
  317. */
  318. void QSPI_Deinit(QuadSPI_Type *base);
  319. /*!
  320. * @brief Configures the serial flash parameter.
  321. *
  322. * This function configures the serial flash relevant parameters, such as the size, command, and so on.
  323. * The flash configuration value cannot have a default value. The user needs to configure it according to the
  324. * QSPI features.
  325. *
  326. * @param base Pointer to QuadSPI Type.
  327. * @param config Flash configuration parameters.
  328. */
  329. void QSPI_SetFlashConfig(QuadSPI_Type *base, qspi_flash_config_t *config);
  330. /*!
  331. * @brief Software reset for the QSPI logic.
  332. *
  333. * This function sets the software reset flags for both AHB and buffer domain and
  334. * resets both AHB buffer and also IP FIFOs.
  335. *
  336. * @param base Pointer to QuadSPI Type.
  337. */
  338. void QSPI_SoftwareReset(QuadSPI_Type *base);
  339. /*!
  340. * @brief Enables or disables the QSPI module.
  341. *
  342. * @param base Pointer to QuadSPI Type.
  343. * @param enable True means enable QSPI, false means disable.
  344. */
  345. static inline void QSPI_Enable(QuadSPI_Type *base, bool enable)
  346. {
  347. if (enable)
  348. {
  349. base->MCR &= ~QuadSPI_MCR_MDIS_MASK;
  350. }
  351. else
  352. {
  353. base->MCR |= QuadSPI_MCR_MDIS_MASK;
  354. }
  355. }
  356. /*! @} */
  357. /*!
  358. * @name Status
  359. * @{
  360. */
  361. /*!
  362. * @brief Gets the state value of QSPI.
  363. *
  364. * @param base Pointer to QuadSPI Type.
  365. * @return status flag, use status flag to AND #_qspi_flags could get the related status.
  366. */
  367. static inline uint32_t QSPI_GetStatusFlags(QuadSPI_Type *base)
  368. {
  369. return base->SR;
  370. }
  371. /*!
  372. * @brief Gets QSPI error status flags.
  373. *
  374. * @param base Pointer to QuadSPI Type.
  375. * @return status flag, use status flag to AND #_qspi_error_flags could get the related status.
  376. */
  377. static inline uint32_t QSPI_GetErrorStatusFlags(QuadSPI_Type *base)
  378. {
  379. return base->FR;
  380. }
  381. /*! @brief Clears the QSPI error flags.
  382. *
  383. * @param base Pointer to QuadSPI Type.
  384. * @param mask Which kind of QSPI flags to be cleared, a combination of _qspi_error_flags.
  385. */
  386. static inline void QSPI_ClearErrorFlag(QuadSPI_Type *base, uint32_t mask)
  387. {
  388. base->FR = mask;
  389. }
  390. /*! @} */
  391. /*!
  392. * @name Interrupts
  393. * @{
  394. */
  395. /*!
  396. * @brief Enables the QSPI interrupts.
  397. *
  398. * @param base Pointer to QuadSPI Type.
  399. * @param mask QSPI interrupt source.
  400. */
  401. static inline void QSPI_EnableInterrupts(QuadSPI_Type *base, uint32_t mask)
  402. {
  403. base->RSER |= mask;
  404. }
  405. /*!
  406. * @brief Disables the QSPI interrupts.
  407. *
  408. * @param base Pointer to QuadSPI Type.
  409. * @param mask QSPI interrupt source.
  410. */
  411. static inline void QSPI_DisableInterrupts(QuadSPI_Type *base, uint32_t mask)
  412. {
  413. base->RSER &= ~mask;
  414. }
  415. /*! @} */
  416. /*!
  417. * @name DMA Control
  418. * @{
  419. */
  420. /*!
  421. * @brief Enables the QSPI DMA source.
  422. *
  423. * @param base Pointer to QuadSPI Type.
  424. * @param mask QSPI DMA source.
  425. * @param enable True means enable DMA, false means disable.
  426. */
  427. static inline void QSPI_EnableDMA(QuadSPI_Type *base, uint32_t mask, bool enable)
  428. {
  429. if (enable)
  430. {
  431. base->RSER |= mask;
  432. }
  433. else
  434. {
  435. base->RSER &= ~mask;
  436. }
  437. }
  438. /*!
  439. * @brief Gets the Tx data register address. It is used for DMA operation.
  440. *
  441. * @param base Pointer to QuadSPI Type.
  442. * @return QSPI Tx data register address.
  443. */
  444. static inline uint32_t QSPI_GetTxDataRegisterAddress(QuadSPI_Type *base)
  445. {
  446. return (uint32_t)(&base->TBDR);
  447. }
  448. /*!
  449. * @brief Gets the Rx data register address used for DMA operation.
  450. *
  451. * This function returns the Rx data register address or Rx buffer address
  452. * according to the Rx read area settings.
  453. *
  454. * @param base Pointer to QuadSPI Type.
  455. * @return QSPI Rx data register address.
  456. */
  457. uint32_t QSPI_GetRxDataRegisterAddress(QuadSPI_Type *base);
  458. /* @} */
  459. /*!
  460. * @name Bus Operations
  461. * @{
  462. */
  463. /*! @brief Sets the IP command address.
  464. *
  465. * @param base Pointer to QuadSPI Type.
  466. * @param addr IP command address.
  467. */
  468. static inline void QSPI_SetIPCommandAddress(QuadSPI_Type *base, uint32_t addr)
  469. {
  470. base->SFAR = addr;
  471. }
  472. /*! @brief Sets the IP command size.
  473. *
  474. * @param base Pointer to QuadSPI Type.
  475. * @param size IP command size.
  476. */
  477. static inline void QSPI_SetIPCommandSize(QuadSPI_Type *base, uint32_t size)
  478. {
  479. base->IPCR = ((base->IPCR & (~QuadSPI_IPCR_IDATSZ_MASK)) | QuadSPI_IPCR_IDATSZ(size));
  480. }
  481. /*! @brief Executes IP commands located in LUT table.
  482. *
  483. * @param base Pointer to QuadSPI Type.
  484. * @param index IP command located in which LUT table index.
  485. */
  486. void QSPI_ExecuteIPCommand(QuadSPI_Type *base, uint32_t index);
  487. /*! @brief Executes AHB commands located in LUT table.
  488. *
  489. * @param base Pointer to QuadSPI Type.
  490. * @param index AHB command located in which LUT table index.
  491. */
  492. void QSPI_ExecuteAHBCommand(QuadSPI_Type *base, uint32_t index);
  493. #if defined(FSL_FEATURE_QSPI_SUPPORT_PARALLEL_MODE) && (FSL_FEATURE_QSPI_SUPPORT_PARALLEL_MODE)
  494. /*! @brief Enables/disables the QSPI IP command parallel mode.
  495. *
  496. * @param base Pointer to QuadSPI Type.
  497. * @param enable True means enable parallel mode, false means disable parallel mode.
  498. */
  499. static inline void QSPI_EnableIPParallelMode(QuadSPI_Type *base, bool enable)
  500. {
  501. if (enable)
  502. {
  503. base->IPCR |= QuadSPI_IPCR_PAR_EN_MASK;
  504. }
  505. else
  506. {
  507. base->IPCR &= ~QuadSPI_IPCR_PAR_EN_MASK;
  508. }
  509. }
  510. /*! @brief Enables/disables the QSPI AHB command parallel mode.
  511. *
  512. * @param base Pointer to QuadSPI Type.
  513. * @param enable True means enable parallel mode, false means disable parallel mode.
  514. */
  515. static inline void QSPI_EnableAHBParallelMode(QuadSPI_Type *base, bool enable)
  516. {
  517. if (enable)
  518. {
  519. base->BFGENCR |= QuadSPI_BFGENCR_PAR_EN_MASK;
  520. }
  521. else
  522. {
  523. base->BFGENCR &= ~QuadSPI_BFGENCR_PAR_EN_MASK;
  524. }
  525. }
  526. #endif /* FSL_FEATURE_QSPI_SUPPORT_PARALLEL_MODE */
  527. /*! @brief Updates the LUT table.
  528. *
  529. * @param base Pointer to QuadSPI Type.
  530. * @param index Which LUT index needs to be located. It should be an integer divided by 4.
  531. * @param cmd Command sequence array.
  532. */
  533. void QSPI_UpdateLUT(QuadSPI_Type *base, uint32_t index, uint32_t *cmd);
  534. /*! @brief Clears the QSPI FIFO logic.
  535. *
  536. * @param base Pointer to QuadSPI Type.
  537. * @param mask Which kind of QSPI FIFO to be cleared.
  538. */
  539. static inline void QSPI_ClearFifo(QuadSPI_Type *base, uint32_t mask)
  540. {
  541. base->MCR |= mask;
  542. }
  543. /*!@ brief Clears the command sequence for the IP/buffer command.
  544. *
  545. * This function can reset the command sequence.
  546. * @param base QSPI base address.
  547. * @param seq Which command sequence need to reset, IP command, buffer command or both.
  548. */
  549. static inline void QSPI_ClearCommandSequence(QuadSPI_Type *base, qspi_command_seq_t seq)
  550. {
  551. base->SPTRCLR = seq;
  552. }
  553. /*!
  554. * @brief Enable or disable DDR mode.
  555. *
  556. * @param base QSPI base pointer
  557. * @param eanble True means enable DDR mode, false means disable DDR mode.
  558. */
  559. static inline void QSPI_EnableDDRMode(QuadSPI_Type *base, bool enable)
  560. {
  561. if (enable)
  562. {
  563. base->MCR |= QuadSPI_MCR_DDR_EN_MASK;
  564. }
  565. else
  566. {
  567. base->MCR &= ~QuadSPI_MCR_DDR_EN_MASK;
  568. }
  569. }
  570. /*!@ brief Set the RX buffer readout area.
  571. *
  572. * This function can set the RX buffer readout, from AHB bus or IP Bus.
  573. * @param base QSPI base address.
  574. * @param area QSPI Rx buffer readout area. AHB bus buffer or IP bus buffer.
  575. */
  576. void QSPI_SetReadDataArea(QuadSPI_Type *base, qspi_read_area_t area);
  577. /*!
  578. * @brief Sends a buffer of data bytes using a blocking method.
  579. * @note This function blocks via polling until all bytes have been sent.
  580. * @param base QSPI base pointer
  581. * @param buffer The data bytes to send
  582. * @param size The number of data bytes to send
  583. */
  584. void QSPI_WriteBlocking(QuadSPI_Type *base, uint32_t *buffer, size_t size);
  585. /*!
  586. * @brief Writes data into FIFO.
  587. *
  588. * @param base QSPI base pointer
  589. * @param data The data bytes to send
  590. */
  591. static inline void QSPI_WriteData(QuadSPI_Type *base, uint32_t data)
  592. {
  593. base->TBDR = data;
  594. }
  595. /*!
  596. * @brief Receives a buffer of data bytes using a blocking method.
  597. * @note This function blocks via polling until all bytes have been sent. Users shall notice that
  598. * this receive size shall not bigger than 64 bytes. As this interface is used to read flash status registers.
  599. * For flash contents read, please use AHB bus read, this is much more efficiency.
  600. *
  601. * @param base QSPI base pointer
  602. * @param buffer The data bytes to send
  603. * @param size The number of data bytes to receive
  604. */
  605. void QSPI_ReadBlocking(QuadSPI_Type *base, uint32_t *buffer, size_t size);
  606. /*!
  607. * @brief Receives data from data FIFO.
  608. *
  609. * @param base QSPI base pointer
  610. * @return The data in the FIFO.
  611. */
  612. uint32_t QSPI_ReadData(QuadSPI_Type *base);
  613. /*! @} */
  614. /*!
  615. * @name Transactional
  616. * @{
  617. */
  618. /*!
  619. * @brief Writes data to the QSPI transmit buffer.
  620. *
  621. * This function writes a continuous data to the QSPI transmit FIFO. This function is a block function
  622. * and can return only when finished. This function uses polling methods.
  623. *
  624. * @param base Pointer to QuadSPI Type.
  625. * @param xfer QSPI transfer structure.
  626. */
  627. static inline void QSPI_TransferSendBlocking(QuadSPI_Type *base, qspi_transfer_t *xfer)
  628. {
  629. QSPI_WriteBlocking(base, xfer->data, xfer->dataSize);
  630. }
  631. /*!
  632. * @brief Reads data from the QSPI receive buffer in polling way.
  633. *
  634. * This function reads continuous data from the QSPI receive buffer/FIFO. This function is a blocking
  635. * function and can return only when finished. This function uses polling methods. Users shall notice that
  636. * this receive size shall not bigger than 64 bytes. As this interface is used to read flash status registers.
  637. * For flash contents read, please use AHB bus read, this is much more efficiency.
  638. *
  639. * @param base Pointer to QuadSPI Type.
  640. * @param xfer QSPI transfer structure.
  641. */
  642. static inline void QSPI_TransferReceiveBlocking(QuadSPI_Type *base, qspi_transfer_t *xfer)
  643. {
  644. QSPI_ReadBlocking(base, xfer->data, xfer->dataSize);
  645. }
  646. /*! @} */
  647. #if defined(__cplusplus)
  648. }
  649. #endif
  650. /* @}*/
  651. #endif /* _FSL_QSPI_H_*/