stm32l4xx_hal_qspi.h 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. /**
  2. ******************************************************************************
  3. * @file stm32l4xx_hal_qspi.h
  4. * @author MCD Application Team
  5. * @brief Header file of QSPI HAL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  10. *
  11. * Redistribution and use in source and binary forms, with or without modification,
  12. * are permitted provided that the following conditions are met:
  13. * 1. Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  19. * may be used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  25. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  28. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  29. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  30. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. ******************************************************************************
  34. */
  35. /* Define to prevent recursive inclusion -------------------------------------*/
  36. #ifndef __STM32L4xx_HAL_QSPI_H
  37. #define __STM32L4xx_HAL_QSPI_H
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. /* Includes ------------------------------------------------------------------*/
  42. #include "stm32l4xx_hal_def.h"
  43. #if defined(QUADSPI) || defined(QUADSPI1) || defined(QUADSPI2)
  44. /** @addtogroup STM32L4xx_HAL_Driver
  45. * @{
  46. */
  47. /** @addtogroup QSPI
  48. * @{
  49. */
  50. /* Exported types ------------------------------------------------------------*/
  51. /** @defgroup QSPI_Exported_Types QSPI Exported Types
  52. * @{
  53. */
  54. /**
  55. * @brief QSPI Init structure definition
  56. */
  57. typedef struct
  58. {
  59. uint32_t ClockPrescaler; /* Specifies the prescaler factor for generating clock based on the AHB clock.
  60. This parameter can be a number between 0 and 255 */
  61. uint32_t FifoThreshold; /* Specifies the threshold number of bytes in the FIFO (used only in indirect mode)
  62. This parameter can be a value between 1 and 16 */
  63. uint32_t SampleShifting; /* Specifies the Sample Shift. The data is sampled 1/2 clock cycle delay later to
  64. take in account external signal delays. (It should be QSPI_SAMPLE_SHIFTING_NONE in DDR mode)
  65. This parameter can be a value of @ref QSPI_SampleShifting */
  66. uint32_t FlashSize; /* Specifies the Flash Size. FlashSize+1 is effectively the number of address bits
  67. required to address the flash memory. The flash capacity can be up to 4GB
  68. (addressed using 32 bits) in indirect mode, but the addressable space in
  69. memory-mapped mode is limited to 256MB
  70. This parameter can be a number between 0 and 31 */
  71. uint32_t ChipSelectHighTime; /* Specifies the Chip Select High Time. ChipSelectHighTime+1 defines the minimum number
  72. of clock cycles which the chip select must remain high between commands.
  73. This parameter can be a value of @ref QSPI_ChipSelectHighTime */
  74. uint32_t ClockMode; /* Specifies the Clock Mode. It indicates the level that clock takes between commands.
  75. This parameter can be a value of @ref QSPI_ClockMode */
  76. #if defined(QUADSPI_CR_DFM)
  77. uint32_t FlashID; /* Specifies the Flash which will be used,
  78. This parameter can be a value of @ref QSPI_Flash_Select */
  79. uint32_t DualFlash; /* Specifies the Dual Flash Mode State
  80. This parameter can be a value of @ref QSPI_DualFlash_Mode */
  81. #endif
  82. }QSPI_InitTypeDef;
  83. /**
  84. * @brief HAL QSPI State structures definition
  85. */
  86. typedef enum
  87. {
  88. HAL_QSPI_STATE_RESET = 0x00, /*!< Peripheral not initialized */
  89. HAL_QSPI_STATE_READY = 0x01, /*!< Peripheral initialized and ready for use */
  90. HAL_QSPI_STATE_BUSY = 0x02, /*!< Peripheral in indirect mode and busy */
  91. HAL_QSPI_STATE_BUSY_INDIRECT_TX = 0x12, /*!< Peripheral in indirect mode with transmission ongoing */
  92. HAL_QSPI_STATE_BUSY_INDIRECT_RX = 0x22, /*!< Peripheral in indirect mode with reception ongoing */
  93. HAL_QSPI_STATE_BUSY_AUTO_POLLING = 0x42, /*!< Peripheral in auto polling mode ongoing */
  94. HAL_QSPI_STATE_BUSY_MEM_MAPPED = 0x82, /*!< Peripheral in memory mapped mode ongoing */
  95. HAL_QSPI_STATE_ABORT = 0x08, /*!< Peripheral with abort request ongoing */
  96. HAL_QSPI_STATE_ERROR = 0x04 /*!< Peripheral in error */
  97. }HAL_QSPI_StateTypeDef;
  98. /**
  99. * @brief QSPI Handle Structure definition
  100. */
  101. typedef struct
  102. {
  103. QUADSPI_TypeDef *Instance; /* QSPI registers base address */
  104. QSPI_InitTypeDef Init; /* QSPI communication parameters */
  105. uint8_t *pTxBuffPtr; /* Pointer to QSPI Tx transfer Buffer */
  106. __IO uint32_t TxXferSize; /* QSPI Tx Transfer size */
  107. __IO uint32_t TxXferCount; /* QSPI Tx Transfer Counter */
  108. uint8_t *pRxBuffPtr; /* Pointer to QSPI Rx transfer Buffer */
  109. __IO uint32_t RxXferSize; /* QSPI Rx Transfer size */
  110. __IO uint32_t RxXferCount; /* QSPI Rx Transfer Counter */
  111. DMA_HandleTypeDef *hdma; /* QSPI Rx/Tx DMA Handle parameters */
  112. __IO HAL_LockTypeDef Lock; /* Locking object */
  113. __IO HAL_QSPI_StateTypeDef State; /* QSPI communication state */
  114. __IO uint32_t ErrorCode; /* QSPI Error code */
  115. uint32_t Timeout; /* Timeout for the QSPI memory access */
  116. }QSPI_HandleTypeDef;
  117. /**
  118. * @brief QSPI Command structure definition
  119. */
  120. typedef struct
  121. {
  122. uint32_t Instruction; /* Specifies the Instruction to be sent
  123. This parameter can be a value (8-bit) between 0x00 and 0xFF */
  124. uint32_t Address; /* Specifies the Address to be sent (Size from 1 to 4 bytes according AddressSize)
  125. This parameter can be a value (32-bits) between 0x0 and 0xFFFFFFFF */
  126. uint32_t AlternateBytes; /* Specifies the Alternate Bytes to be sent (Size from 1 to 4 bytes according AlternateBytesSize)
  127. This parameter can be a value (32-bits) between 0x0 and 0xFFFFFFFF */
  128. uint32_t AddressSize; /* Specifies the Address Size
  129. This parameter can be a value of @ref QSPI_AddressSize */
  130. uint32_t AlternateBytesSize; /* Specifies the Alternate Bytes Size
  131. This parameter can be a value of @ref QSPI_AlternateBytesSize */
  132. uint32_t DummyCycles; /* Specifies the Number of Dummy Cycles.
  133. This parameter can be a number between 0 and 31 */
  134. uint32_t InstructionMode; /* Specifies the Instruction Mode
  135. This parameter can be a value of @ref QSPI_InstructionMode */
  136. uint32_t AddressMode; /* Specifies the Address Mode
  137. This parameter can be a value of @ref QSPI_AddressMode */
  138. uint32_t AlternateByteMode; /* Specifies the Alternate Bytes Mode
  139. This parameter can be a value of @ref QSPI_AlternateBytesMode */
  140. uint32_t DataMode; /* Specifies the Data Mode (used for dummy cycles and data phases)
  141. This parameter can be a value of @ref QSPI_DataMode */
  142. uint32_t NbData; /* Specifies the number of data to transfer. (This is the number of bytes)
  143. This parameter can be any value between 0 and 0xFFFFFFFF (0 means undefined length
  144. until end of memory)*/
  145. uint32_t DdrMode; /* Specifies the double data rate mode for address, alternate byte and data phase
  146. This parameter can be a value of @ref QSPI_DdrMode */
  147. uint32_t DdrHoldHalfCycle; /* Specifies the DDR hold half cycle. It delays the data output by one half of
  148. system clock in DDR mode. Not available on STM32L4x6 devices but in future devices.
  149. This parameter can be a value of @ref QSPI_DdrHoldHalfCycle */
  150. uint32_t SIOOMode; /* Specifies the send instruction only once mode
  151. This parameter can be a value of @ref QSPI_SIOOMode */
  152. }QSPI_CommandTypeDef;
  153. /**
  154. * @brief QSPI Auto Polling mode configuration structure definition
  155. */
  156. typedef struct
  157. {
  158. uint32_t Match; /* Specifies the value to be compared with the masked status register to get a match.
  159. This parameter can be any value between 0 and 0xFFFFFFFF */
  160. uint32_t Mask; /* Specifies the mask to be applied to the status bytes received.
  161. This parameter can be any value between 0 and 0xFFFFFFFF */
  162. uint32_t Interval; /* Specifies the number of clock cycles between two read during automatic polling phases.
  163. This parameter can be any value between 0 and 0xFFFF */
  164. uint32_t StatusBytesSize; /* Specifies the size of the status bytes received.
  165. This parameter can be any value between 1 and 4 */
  166. uint32_t MatchMode; /* Specifies the method used for determining a match.
  167. This parameter can be a value of @ref QSPI_MatchMode */
  168. uint32_t AutomaticStop; /* Specifies if automatic polling is stopped after a match.
  169. This parameter can be a value of @ref QSPI_AutomaticStop */
  170. }QSPI_AutoPollingTypeDef;
  171. /**
  172. * @brief QSPI Memory Mapped mode configuration structure definition
  173. */
  174. typedef struct
  175. {
  176. uint32_t TimeOutPeriod; /* Specifies the number of clock to wait when the FIFO is full before to release the chip select.
  177. This parameter can be any value between 0 and 0xFFFF */
  178. uint32_t TimeOutActivation; /* Specifies if the timeout counter is enabled to release the chip select.
  179. This parameter can be a value of @ref QSPI_TimeOutActivation */
  180. }QSPI_MemoryMappedTypeDef;
  181. /**
  182. * @}
  183. */
  184. /* Exported constants --------------------------------------------------------*/
  185. /** @defgroup QSPI_Exported_Constants QSPI Exported Constants
  186. * @{
  187. */
  188. /** @defgroup QSPI_ErrorCode QSPI Error Code
  189. * @{
  190. */
  191. #define HAL_QSPI_ERROR_NONE ((uint32_t)0x00000000) /*!< No error */
  192. #define HAL_QSPI_ERROR_TIMEOUT ((uint32_t)0x00000001) /*!< Timeout error */
  193. #define HAL_QSPI_ERROR_TRANSFER ((uint32_t)0x00000002) /*!< Transfer error */
  194. #define HAL_QSPI_ERROR_DMA ((uint32_t)0x00000004) /*!< DMA transfer error */
  195. #define HAL_QSPI_ERROR_INVALID_PARAM ((uint32_t)0x00000008) /*!< Invalid parameters error */
  196. /**
  197. * @}
  198. */
  199. /** @defgroup QSPI_SampleShifting QSPI Sample Shifting
  200. * @{
  201. */
  202. #define QSPI_SAMPLE_SHIFTING_NONE ((uint32_t)0x00000000) /*!<No clock cycle shift to sample data*/
  203. #define QSPI_SAMPLE_SHIFTING_HALFCYCLE ((uint32_t)QUADSPI_CR_SSHIFT) /*!<1/2 clock cycle shift to sample data*/
  204. /**
  205. * @}
  206. */
  207. /** @defgroup QSPI_ChipSelectHighTime QSPI ChipSelect High Time
  208. * @{
  209. */
  210. #define QSPI_CS_HIGH_TIME_1_CYCLE ((uint32_t)0x00000000) /*!<nCS stay high for at least 1 clock cycle between commands*/
  211. #define QSPI_CS_HIGH_TIME_2_CYCLE ((uint32_t)QUADSPI_DCR_CSHT_0) /*!<nCS stay high for at least 2 clock cycles between commands*/
  212. #define QSPI_CS_HIGH_TIME_3_CYCLE ((uint32_t)QUADSPI_DCR_CSHT_1) /*!<nCS stay high for at least 3 clock cycles between commands*/
  213. #define QSPI_CS_HIGH_TIME_4_CYCLE ((uint32_t)QUADSPI_DCR_CSHT_0 | QUADSPI_DCR_CSHT_1) /*!<nCS stay high for at least 4 clock cycles between commands*/
  214. #define QSPI_CS_HIGH_TIME_5_CYCLE ((uint32_t)QUADSPI_DCR_CSHT_2) /*!<nCS stay high for at least 5 clock cycles between commands*/
  215. #define QSPI_CS_HIGH_TIME_6_CYCLE ((uint32_t)QUADSPI_DCR_CSHT_2 | QUADSPI_DCR_CSHT_0) /*!<nCS stay high for at least 6 clock cycles between commands*/
  216. #define QSPI_CS_HIGH_TIME_7_CYCLE ((uint32_t)QUADSPI_DCR_CSHT_2 | QUADSPI_DCR_CSHT_1) /*!<nCS stay high for at least 7 clock cycles between commands*/
  217. #define QSPI_CS_HIGH_TIME_8_CYCLE ((uint32_t)QUADSPI_DCR_CSHT) /*!<nCS stay high for at least 8 clock cycles between commands*/
  218. /**
  219. * @}
  220. */
  221. /** @defgroup QSPI_ClockMode QSPI Clock Mode
  222. * @{
  223. */
  224. #define QSPI_CLOCK_MODE_0 ((uint32_t)0x00000000) /*!<Clk stays low while nCS is released*/
  225. #define QSPI_CLOCK_MODE_3 ((uint32_t)QUADSPI_DCR_CKMODE) /*!<Clk goes high while nCS is released*/
  226. /**
  227. * @}
  228. */
  229. #if defined(QUADSPI_CR_DFM)
  230. /** @defgroup QSPI_Flash_Select QSPI Flash Select
  231. * @{
  232. */
  233. #define QSPI_FLASH_ID_1 ((uint32_t)0x00000000) /*!<FLASH 1 selected*/
  234. #define QSPI_FLASH_ID_2 ((uint32_t)QUADSPI_CR_FSEL) /*!<FLASH 2 selected*/
  235. /**
  236. * @}
  237. */
  238. /** @defgroup QSPI_DualFlash_Mode QSPI Dual Flash Mode
  239. * @{
  240. */
  241. #define QSPI_DUALFLASH_ENABLE ((uint32_t)QUADSPI_CR_DFM) /*!<Dual-flash mode enabled*/
  242. #define QSPI_DUALFLASH_DISABLE ((uint32_t)0x00000000) /*!<Dual-flash mode disabled*/
  243. /**
  244. * @}
  245. */
  246. #endif
  247. /** @defgroup QSPI_AddressSize QSPI Address Size
  248. * @{
  249. */
  250. #define QSPI_ADDRESS_8_BITS ((uint32_t)0x00000000) /*!<8-bit address*/
  251. #define QSPI_ADDRESS_16_BITS ((uint32_t)QUADSPI_CCR_ADSIZE_0) /*!<16-bit address*/
  252. #define QSPI_ADDRESS_24_BITS ((uint32_t)QUADSPI_CCR_ADSIZE_1) /*!<24-bit address*/
  253. #define QSPI_ADDRESS_32_BITS ((uint32_t)QUADSPI_CCR_ADSIZE) /*!<32-bit address*/
  254. /**
  255. * @}
  256. */
  257. /** @defgroup QSPI_AlternateBytesSize QSPI Alternate Bytes Size
  258. * @{
  259. */
  260. #define QSPI_ALTERNATE_BYTES_8_BITS ((uint32_t)0x00000000) /*!<8-bit alternate bytes*/
  261. #define QSPI_ALTERNATE_BYTES_16_BITS ((uint32_t)QUADSPI_CCR_ABSIZE_0) /*!<16-bit alternate bytes*/
  262. #define QSPI_ALTERNATE_BYTES_24_BITS ((uint32_t)QUADSPI_CCR_ABSIZE_1) /*!<24-bit alternate bytes*/
  263. #define QSPI_ALTERNATE_BYTES_32_BITS ((uint32_t)QUADSPI_CCR_ABSIZE) /*!<32-bit alternate bytes*/
  264. /**
  265. * @}
  266. */
  267. /** @defgroup QSPI_InstructionMode QSPI Instruction Mode
  268. * @{
  269. */
  270. #define QSPI_INSTRUCTION_NONE ((uint32_t)0x00000000) /*!<No instruction*/
  271. #define QSPI_INSTRUCTION_1_LINE ((uint32_t)QUADSPI_CCR_IMODE_0) /*!<Instruction on a single line*/
  272. #define QSPI_INSTRUCTION_2_LINES ((uint32_t)QUADSPI_CCR_IMODE_1) /*!<Instruction on two lines*/
  273. #define QSPI_INSTRUCTION_4_LINES ((uint32_t)QUADSPI_CCR_IMODE) /*!<Instruction on four lines*/
  274. /**
  275. * @}
  276. */
  277. /** @defgroup QSPI_AddressMode QSPI Address Mode
  278. * @{
  279. */
  280. #define QSPI_ADDRESS_NONE ((uint32_t)0x00000000) /*!<No address*/
  281. #define QSPI_ADDRESS_1_LINE ((uint32_t)QUADSPI_CCR_ADMODE_0) /*!<Address on a single line*/
  282. #define QSPI_ADDRESS_2_LINES ((uint32_t)QUADSPI_CCR_ADMODE_1) /*!<Address on two lines*/
  283. #define QSPI_ADDRESS_4_LINES ((uint32_t)QUADSPI_CCR_ADMODE) /*!<Address on four lines*/
  284. /**
  285. * @}
  286. */
  287. /** @defgroup QSPI_AlternateBytesMode QSPI Alternate Bytes Mode
  288. * @{
  289. */
  290. #define QSPI_ALTERNATE_BYTES_NONE ((uint32_t)0x00000000) /*!<No alternate bytes*/
  291. #define QSPI_ALTERNATE_BYTES_1_LINE ((uint32_t)QUADSPI_CCR_ABMODE_0) /*!<Alternate bytes on a single line*/
  292. #define QSPI_ALTERNATE_BYTES_2_LINES ((uint32_t)QUADSPI_CCR_ABMODE_1) /*!<Alternate bytes on two lines*/
  293. #define QSPI_ALTERNATE_BYTES_4_LINES ((uint32_t)QUADSPI_CCR_ABMODE) /*!<Alternate bytes on four lines*/
  294. /**
  295. * @}
  296. */
  297. /** @defgroup QSPI_DataMode QSPI Data Mode
  298. * @{
  299. */
  300. #define QSPI_DATA_NONE ((uint32_t)0X00000000) /*!<No data*/
  301. #define QSPI_DATA_1_LINE ((uint32_t)QUADSPI_CCR_DMODE_0) /*!<Data on a single line*/
  302. #define QSPI_DATA_2_LINES ((uint32_t)QUADSPI_CCR_DMODE_1) /*!<Data on two lines*/
  303. #define QSPI_DATA_4_LINES ((uint32_t)QUADSPI_CCR_DMODE) /*!<Data on four lines*/
  304. /**
  305. * @}
  306. */
  307. /** @defgroup QSPI_DdrMode QSPI DDR Mode
  308. * @{
  309. */
  310. #define QSPI_DDR_MODE_DISABLE ((uint32_t)0x00000000) /*!<Double data rate mode disabled*/
  311. #define QSPI_DDR_MODE_ENABLE ((uint32_t)QUADSPI_CCR_DDRM) /*!<Double data rate mode enabled*/
  312. /**
  313. * @}
  314. */
  315. /** @defgroup QSPI_DdrHoldHalfCycle QSPI DDR Data Output Delay
  316. * @{
  317. */
  318. #define QSPI_DDR_HHC_ANALOG_DELAY ((uint32_t)0x00000000) /*!<Delay the data output using analog delay in DDR mode*/
  319. #if defined(QUADSPI_CCR_DHHC)
  320. #define QSPI_DDR_HHC_HALF_CLK_DELAY ((uint32_t)QUADSPI_CCR_DHHC) /*!<Delay the data output by 1/2 clock cycle in DDR mode*/
  321. #endif
  322. /**
  323. * @}
  324. */
  325. /** @defgroup QSPI_SIOOMode QSPI Send Instruction Mode
  326. * @{
  327. */
  328. #define QSPI_SIOO_INST_EVERY_CMD ((uint32_t)0x00000000) /*!<Send instruction on every transaction*/
  329. #define QSPI_SIOO_INST_ONLY_FIRST_CMD ((uint32_t)QUADSPI_CCR_SIOO) /*!<Send instruction only for the first command*/
  330. /**
  331. * @}
  332. */
  333. /** @defgroup QSPI_MatchMode QSPI Match Mode
  334. * @{
  335. */
  336. #define QSPI_MATCH_MODE_AND ((uint32_t)0x00000000) /*!<AND match mode between unmasked bits*/
  337. #define QSPI_MATCH_MODE_OR ((uint32_t)QUADSPI_CR_PMM) /*!<OR match mode between unmasked bits*/
  338. /**
  339. * @}
  340. */
  341. /** @defgroup QSPI_AutomaticStop QSPI Automatic Stop
  342. * @{
  343. */
  344. #define QSPI_AUTOMATIC_STOP_DISABLE ((uint32_t)0x00000000) /*!<AutoPolling stops only with abort or QSPI disabling*/
  345. #define QSPI_AUTOMATIC_STOP_ENABLE ((uint32_t)QUADSPI_CR_APMS) /*!<AutoPolling stops as soon as there is a match*/
  346. /**
  347. * @}
  348. */
  349. /** @defgroup QSPI_TimeOutActivation QSPI Timeout Activation
  350. * @{
  351. */
  352. #define QSPI_TIMEOUT_COUNTER_DISABLE ((uint32_t)0x00000000) /*!<Timeout counter disabled, nCS remains active*/
  353. #define QSPI_TIMEOUT_COUNTER_ENABLE ((uint32_t)QUADSPI_CR_TCEN) /*!<Timeout counter enabled, nCS released when timeout expires*/
  354. /**
  355. * @}
  356. */
  357. /** @defgroup QSPI_Flags QSPI Flags
  358. * @{
  359. */
  360. #define QSPI_FLAG_BUSY QUADSPI_SR_BUSY /*!<Busy flag: operation is ongoing*/
  361. #define QSPI_FLAG_TO QUADSPI_SR_TOF /*!<Timeout flag: timeout occurs in memory-mapped mode*/
  362. #define QSPI_FLAG_SM QUADSPI_SR_SMF /*!<Status match flag: received data matches in autopolling mode*/
  363. #define QSPI_FLAG_FT QUADSPI_SR_FTF /*!<Fifo threshold flag: Fifo threshold reached or data left after read from memory is complete*/
  364. #define QSPI_FLAG_TC QUADSPI_SR_TCF /*!<Transfer complete flag: programmed number of data have been transferred or the transfer has been aborted*/
  365. #define QSPI_FLAG_TE QUADSPI_SR_TEF /*!<Transfer error flag: invalid address is being accessed*/
  366. /**
  367. * @}
  368. */
  369. /** @defgroup QSPI_Interrupts QSPI Interrupts
  370. * @{
  371. */
  372. #define QSPI_IT_TO QUADSPI_CR_TOIE /*!<Interrupt on the timeout flag*/
  373. #define QSPI_IT_SM QUADSPI_CR_SMIE /*!<Interrupt on the status match flag*/
  374. #define QSPI_IT_FT QUADSPI_CR_FTIE /*!<Interrupt on the fifo threshold flag*/
  375. #define QSPI_IT_TC QUADSPI_CR_TCIE /*!<Interrupt on the transfer complete flag*/
  376. #define QSPI_IT_TE QUADSPI_CR_TEIE /*!<Interrupt on the transfer error flag*/
  377. /**
  378. * @}
  379. */
  380. /** @defgroup QSPI_Timeout_definition QSPI Timeout definition
  381. * @brief QSPI Timeout definition
  382. * @{
  383. */
  384. #define HAL_QPSI_TIMEOUT_DEFAULT_VALUE ((uint32_t)5000)/* 5 s */
  385. /**
  386. * @}
  387. */
  388. /**
  389. * @}
  390. */
  391. /* Exported macros -----------------------------------------------------------*/
  392. /** @defgroup QSPI_Exported_Macros QSPI Exported Macros
  393. * @{
  394. */
  395. /** @brief Reset QSPI handle state.
  396. * @param __HANDLE__ : QSPI handle.
  397. * @retval None
  398. */
  399. #define __HAL_QSPI_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_QSPI_STATE_RESET)
  400. /** @brief Enable the QSPI peripheral.
  401. * @param __HANDLE__ : specifies the QSPI Handle.
  402. * @retval None
  403. */
  404. #define __HAL_QSPI_ENABLE(__HANDLE__) SET_BIT((__HANDLE__)->Instance->CR, QUADSPI_CR_EN)
  405. /** @brief Disable the QSPI peripheral.
  406. * @param __HANDLE__ : specifies the QSPI Handle.
  407. * @retval None
  408. */
  409. #define __HAL_QSPI_DISABLE(__HANDLE__) CLEAR_BIT((__HANDLE__)->Instance->CR, QUADSPI_CR_EN)
  410. /** @brief Enable the specified QSPI interrupt.
  411. * @param __HANDLE__: specifies the QSPI Handle.
  412. * @param __INTERRUPT__: specifies the QSPI interrupt source to enable.
  413. * This parameter can be one of the following values:
  414. * @arg QSPI_IT_TO: QSPI Timeout interrupt
  415. * @arg QSPI_IT_SM: QSPI Status match interrupt
  416. * @arg QSPI_IT_FT: QSPI FIFO threshold interrupt
  417. * @arg QSPI_IT_TC: QSPI Transfer complete interrupt
  418. * @arg QSPI_IT_TE: QSPI Transfer error interrupt
  419. * @retval None
  420. */
  421. #define __HAL_QSPI_ENABLE_IT(__HANDLE__, __INTERRUPT__) SET_BIT((__HANDLE__)->Instance->CR, (__INTERRUPT__))
  422. /** @brief Disable the specified QSPI interrupt.
  423. * @param __HANDLE__: specifies the QSPI Handle.
  424. * @param __INTERRUPT__: specifies the QSPI interrupt source to disable.
  425. * This parameter can be one of the following values:
  426. * @arg QSPI_IT_TO: QSPI Timeout interrupt
  427. * @arg QSPI_IT_SM: QSPI Status match interrupt
  428. * @arg QSPI_IT_FT: QSPI FIFO threshold interrupt
  429. * @arg QSPI_IT_TC: QSPI Transfer complete interrupt
  430. * @arg QSPI_IT_TE: QSPI Transfer error interrupt
  431. * @retval None
  432. */
  433. #define __HAL_QSPI_DISABLE_IT(__HANDLE__, __INTERRUPT__) CLEAR_BIT((__HANDLE__)->Instance->CR, (__INTERRUPT__))
  434. /** @brief Check whether the specified QSPI interrupt source is enabled or not.
  435. * @param __HANDLE__: specifies the QSPI Handle.
  436. * @param __INTERRUPT__: specifies the QSPI interrupt source to check.
  437. * This parameter can be one of the following values:
  438. * @arg QSPI_IT_TO: QSPI Timeout interrupt
  439. * @arg QSPI_IT_SM: QSPI Status match interrupt
  440. * @arg QSPI_IT_FT: QSPI FIFO threshold interrupt
  441. * @arg QSPI_IT_TC: QSPI Transfer complete interrupt
  442. * @arg QSPI_IT_TE: QSPI Transfer error interrupt
  443. * @retval The new state of __INTERRUPT__ (TRUE or FALSE).
  444. */
  445. #define __HAL_QSPI_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (READ_BIT((__HANDLE__)->Instance->CR, (__INTERRUPT__)) == (__INTERRUPT__))
  446. /**
  447. * @brief Check whether the selected QSPI flag is set or not.
  448. * @param __HANDLE__: specifies the QSPI Handle.
  449. * @param __FLAG__: specifies the QSPI flag to check.
  450. * This parameter can be one of the following values:
  451. * @arg QSPI_FLAG_BUSY: QSPI Busy flag
  452. * @arg QSPI_FLAG_TO: QSPI Timeout flag
  453. * @arg QSPI_FLAG_SM: QSPI Status match flag
  454. * @arg QSPI_FLAG_FT: QSPI FIFO threshold flag
  455. * @arg QSPI_FLAG_TC: QSPI Transfer complete flag
  456. * @arg QSPI_FLAG_TE: QSPI Transfer error flag
  457. * @retval None
  458. */
  459. #define __HAL_QSPI_GET_FLAG(__HANDLE__, __FLAG__) ((READ_BIT((__HANDLE__)->Instance->SR, (__FLAG__)) != 0) ? SET : RESET)
  460. /** @brief Clears the specified QSPI's flag status.
  461. * @param __HANDLE__: specifies the QSPI Handle.
  462. * @param __FLAG__: specifies the QSPI clear register flag that needs to be set
  463. * This parameter can be one of the following values:
  464. * @arg QSPI_FLAG_TO: QSPI Timeout flag
  465. * @arg QSPI_FLAG_SM: QSPI Status match flag
  466. * @arg QSPI_FLAG_TC: QSPI Transfer complete flag
  467. * @arg QSPI_FLAG_TE: QSPI Transfer error flag
  468. * @retval None
  469. */
  470. #define __HAL_QSPI_CLEAR_FLAG(__HANDLE__, __FLAG__) WRITE_REG((__HANDLE__)->Instance->FCR, (__FLAG__))
  471. /**
  472. * @}
  473. */
  474. /* Exported functions --------------------------------------------------------*/
  475. /** @addtogroup QSPI_Exported_Functions
  476. * @{
  477. */
  478. /* Initialization/de-initialization functions ********************************/
  479. HAL_StatusTypeDef HAL_QSPI_Init (QSPI_HandleTypeDef *hqspi);
  480. HAL_StatusTypeDef HAL_QSPI_DeInit (QSPI_HandleTypeDef *hqspi);
  481. void HAL_QSPI_MspInit (QSPI_HandleTypeDef *hqspi);
  482. void HAL_QSPI_MspDeInit(QSPI_HandleTypeDef *hqspi);
  483. /* IO operation functions *****************************************************/
  484. /* QSPI IRQ handler method */
  485. void HAL_QSPI_IRQHandler(QSPI_HandleTypeDef *hqspi);
  486. /* QSPI indirect mode */
  487. HAL_StatusTypeDef HAL_QSPI_Command (QSPI_HandleTypeDef *hqspi, QSPI_CommandTypeDef *cmd, uint32_t Timeout);
  488. HAL_StatusTypeDef HAL_QSPI_Transmit (QSPI_HandleTypeDef *hqspi, uint8_t *pData, uint32_t Timeout);
  489. HAL_StatusTypeDef HAL_QSPI_Receive (QSPI_HandleTypeDef *hqspi, uint8_t *pData, uint32_t Timeout);
  490. HAL_StatusTypeDef HAL_QSPI_Command_IT (QSPI_HandleTypeDef *hqspi, QSPI_CommandTypeDef *cmd);
  491. HAL_StatusTypeDef HAL_QSPI_Transmit_IT (QSPI_HandleTypeDef *hqspi, uint8_t *pData);
  492. HAL_StatusTypeDef HAL_QSPI_Receive_IT (QSPI_HandleTypeDef *hqspi, uint8_t *pData);
  493. HAL_StatusTypeDef HAL_QSPI_Transmit_DMA (QSPI_HandleTypeDef *hqspi, uint8_t *pData);
  494. HAL_StatusTypeDef HAL_QSPI_Receive_DMA (QSPI_HandleTypeDef *hqspi, uint8_t *pData);
  495. /* QSPI status flag polling mode */
  496. HAL_StatusTypeDef HAL_QSPI_AutoPolling (QSPI_HandleTypeDef *hqspi, QSPI_CommandTypeDef *cmd, QSPI_AutoPollingTypeDef *cfg, uint32_t Timeout);
  497. HAL_StatusTypeDef HAL_QSPI_AutoPolling_IT(QSPI_HandleTypeDef *hqspi, QSPI_CommandTypeDef *cmd, QSPI_AutoPollingTypeDef *cfg);
  498. /* QSPI memory-mapped mode */
  499. HAL_StatusTypeDef HAL_QSPI_MemoryMapped(QSPI_HandleTypeDef *hqspi, QSPI_CommandTypeDef *cmd, QSPI_MemoryMappedTypeDef *cfg);
  500. /* Callback functions in non-blocking modes ***********************************/
  501. void HAL_QSPI_ErrorCallback (QSPI_HandleTypeDef *hqspi);
  502. void HAL_QSPI_AbortCpltCallback (QSPI_HandleTypeDef *hqspi);
  503. void HAL_QSPI_FifoThresholdCallback(QSPI_HandleTypeDef *hqspi);
  504. /* QSPI indirect mode */
  505. void HAL_QSPI_CmdCpltCallback (QSPI_HandleTypeDef *hqspi);
  506. void HAL_QSPI_RxCpltCallback (QSPI_HandleTypeDef *hqspi);
  507. void HAL_QSPI_TxCpltCallback (QSPI_HandleTypeDef *hqspi);
  508. void HAL_QSPI_RxHalfCpltCallback (QSPI_HandleTypeDef *hqspi);
  509. void HAL_QSPI_TxHalfCpltCallback (QSPI_HandleTypeDef *hqspi);
  510. /* QSPI status flag polling mode */
  511. void HAL_QSPI_StatusMatchCallback (QSPI_HandleTypeDef *hqspi);
  512. /* QSPI memory-mapped mode */
  513. void HAL_QSPI_TimeOutCallback (QSPI_HandleTypeDef *hqspi);
  514. /* Peripheral Control and State functions ************************************/
  515. HAL_QSPI_StateTypeDef HAL_QSPI_GetState (QSPI_HandleTypeDef *hqspi);
  516. uint32_t HAL_QSPI_GetError (QSPI_HandleTypeDef *hqspi);
  517. HAL_StatusTypeDef HAL_QSPI_Abort (QSPI_HandleTypeDef *hqspi);
  518. HAL_StatusTypeDef HAL_QSPI_Abort_IT (QSPI_HandleTypeDef *hqspi);
  519. void HAL_QSPI_SetTimeout (QSPI_HandleTypeDef *hqspi, uint32_t Timeout);
  520. HAL_StatusTypeDef HAL_QSPI_SetFifoThreshold(QSPI_HandleTypeDef *hqspi, uint32_t Threshold);
  521. uint32_t HAL_QSPI_GetFifoThreshold(QSPI_HandleTypeDef *hqspi);
  522. /**
  523. * @}
  524. */
  525. /* End of exported functions -------------------------------------------------*/
  526. /* Private macros ------------------------------------------------------------*/
  527. /** @defgroup QSPI_Private_Macros QSPI Private Macros
  528. * @{
  529. */
  530. #define IS_QSPI_CLOCK_PRESCALER(PRESCALER) ((PRESCALER) <= 0xFF)
  531. #define IS_QSPI_FIFO_THRESHOLD(THR) (((THR) > 0) && ((THR) <= 16))
  532. #define IS_QSPI_SSHIFT(SSHIFT) (((SSHIFT) == QSPI_SAMPLE_SHIFTING_NONE) || \
  533. ((SSHIFT) == QSPI_SAMPLE_SHIFTING_HALFCYCLE))
  534. #define IS_QSPI_FLASH_SIZE(FSIZE) (((FSIZE) <= 31))
  535. #define IS_QSPI_CS_HIGH_TIME(CSHTIME) (((CSHTIME) == QSPI_CS_HIGH_TIME_1_CYCLE) || \
  536. ((CSHTIME) == QSPI_CS_HIGH_TIME_2_CYCLE) || \
  537. ((CSHTIME) == QSPI_CS_HIGH_TIME_3_CYCLE) || \
  538. ((CSHTIME) == QSPI_CS_HIGH_TIME_4_CYCLE) || \
  539. ((CSHTIME) == QSPI_CS_HIGH_TIME_5_CYCLE) || \
  540. ((CSHTIME) == QSPI_CS_HIGH_TIME_6_CYCLE) || \
  541. ((CSHTIME) == QSPI_CS_HIGH_TIME_7_CYCLE) || \
  542. ((CSHTIME) == QSPI_CS_HIGH_TIME_8_CYCLE))
  543. #define IS_QSPI_CLOCK_MODE(CLKMODE) (((CLKMODE) == QSPI_CLOCK_MODE_0) || \
  544. ((CLKMODE) == QSPI_CLOCK_MODE_3))
  545. #if defined(QUADSPI_CR_DFM)
  546. #define IS_QSPI_FLASH_ID(FLASH) (((FLASH) == QSPI_FLASH_ID_1) || \
  547. ((FLASH) == QSPI_FLASH_ID_2))
  548. #define IS_QSPI_DUAL_FLASH_MODE(MODE) (((MODE) == QSPI_DUALFLASH_ENABLE) || \
  549. ((MODE) == QSPI_DUALFLASH_DISABLE))
  550. #endif
  551. #define IS_QSPI_INSTRUCTION(INSTRUCTION) ((INSTRUCTION) <= 0xFF)
  552. #define IS_QSPI_ADDRESS_SIZE(ADDR_SIZE) (((ADDR_SIZE) == QSPI_ADDRESS_8_BITS) || \
  553. ((ADDR_SIZE) == QSPI_ADDRESS_16_BITS) || \
  554. ((ADDR_SIZE) == QSPI_ADDRESS_24_BITS) || \
  555. ((ADDR_SIZE) == QSPI_ADDRESS_32_BITS))
  556. #define IS_QSPI_ALTERNATE_BYTES_SIZE(SIZE) (((SIZE) == QSPI_ALTERNATE_BYTES_8_BITS) || \
  557. ((SIZE) == QSPI_ALTERNATE_BYTES_16_BITS) || \
  558. ((SIZE) == QSPI_ALTERNATE_BYTES_24_BITS) || \
  559. ((SIZE) == QSPI_ALTERNATE_BYTES_32_BITS))
  560. #define IS_QSPI_DUMMY_CYCLES(DCY) ((DCY) <= 31)
  561. #define IS_QSPI_INSTRUCTION_MODE(MODE) (((MODE) == QSPI_INSTRUCTION_NONE) || \
  562. ((MODE) == QSPI_INSTRUCTION_1_LINE) || \
  563. ((MODE) == QSPI_INSTRUCTION_2_LINES) || \
  564. ((MODE) == QSPI_INSTRUCTION_4_LINES))
  565. #define IS_QSPI_ADDRESS_MODE(MODE) (((MODE) == QSPI_ADDRESS_NONE) || \
  566. ((MODE) == QSPI_ADDRESS_1_LINE) || \
  567. ((MODE) == QSPI_ADDRESS_2_LINES) || \
  568. ((MODE) == QSPI_ADDRESS_4_LINES))
  569. #define IS_QSPI_ALTERNATE_BYTES_MODE(MODE) (((MODE) == QSPI_ALTERNATE_BYTES_NONE) || \
  570. ((MODE) == QSPI_ALTERNATE_BYTES_1_LINE) || \
  571. ((MODE) == QSPI_ALTERNATE_BYTES_2_LINES) || \
  572. ((MODE) == QSPI_ALTERNATE_BYTES_4_LINES))
  573. #define IS_QSPI_DATA_MODE(MODE) (((MODE) == QSPI_DATA_NONE) || \
  574. ((MODE) == QSPI_DATA_1_LINE) || \
  575. ((MODE) == QSPI_DATA_2_LINES) || \
  576. ((MODE) == QSPI_DATA_4_LINES))
  577. #define IS_QSPI_DDR_MODE(DDR_MODE) (((DDR_MODE) == QSPI_DDR_MODE_DISABLE) || \
  578. ((DDR_MODE) == QSPI_DDR_MODE_ENABLE))
  579. #if defined(QUADSPI_CCR_DHHC)
  580. #define IS_QSPI_DDR_HHC(DDR_HHC) (((DDR_HHC) == QSPI_DDR_HHC_ANALOG_DELAY) || \
  581. ((DDR_HHC) == QSPI_DDR_HHC_HALF_CLK_DELAY))
  582. #else
  583. #define IS_QSPI_DDR_HHC(DDR_HHC) (((DDR_HHC) == QSPI_DDR_HHC_ANALOG_DELAY))
  584. #endif
  585. #define IS_QSPI_SIOO_MODE(SIOO_MODE) (((SIOO_MODE) == QSPI_SIOO_INST_EVERY_CMD) || \
  586. ((SIOO_MODE) == QSPI_SIOO_INST_ONLY_FIRST_CMD))
  587. #define IS_QSPI_INTERVAL(INTERVAL) ((INTERVAL) <= QUADSPI_PIR_INTERVAL)
  588. #define IS_QSPI_STATUS_BYTES_SIZE(SIZE) (((SIZE) >= 1) && ((SIZE) <= 4))
  589. #define IS_QSPI_MATCH_MODE(MODE) (((MODE) == QSPI_MATCH_MODE_AND) || \
  590. ((MODE) == QSPI_MATCH_MODE_OR))
  591. #define IS_QSPI_AUTOMATIC_STOP(APMS) (((APMS) == QSPI_AUTOMATIC_STOP_DISABLE) || \
  592. ((APMS) == QSPI_AUTOMATIC_STOP_ENABLE))
  593. #define IS_QSPI_TIMEOUT_ACTIVATION(TCEN) (((TCEN) == QSPI_TIMEOUT_COUNTER_DISABLE) || \
  594. ((TCEN) == QSPI_TIMEOUT_COUNTER_ENABLE))
  595. #define IS_QSPI_TIMEOUT_PERIOD(PERIOD) ((PERIOD) <= 0xFFFF)
  596. /**
  597. * @}
  598. */
  599. /* End of private macros -----------------------------------------------------*/
  600. /**
  601. * @}
  602. */
  603. /**
  604. * @}
  605. */
  606. #endif /* defined(QUADSPI) || defined(QUADSPI1) || defined(QUADSPI2) */
  607. #ifdef __cplusplus
  608. }
  609. #endif
  610. #endif /* __STM32L4xx_HAL_QSPI_H */
  611. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/