stm32l4xx_hal_ospi.h 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968
  1. /**
  2. ******************************************************************************
  3. * @file stm32l4xx_hal_ospi.h
  4. * @author MCD Application Team
  5. * @brief Header file of OSPI 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_OSPI_H
  37. #define __STM32L4xx_HAL_OSPI_H
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. /* Includes ------------------------------------------------------------------*/
  42. #include "stm32l4xx_hal_def.h"
  43. #if defined(OCTOSPI) || defined(OCTOSPI1) || defined(OCTOSPI2)
  44. /** @addtogroup STM32L4xx_HAL_Driver
  45. * @{
  46. */
  47. /** @addtogroup OSPI
  48. * @{
  49. */
  50. /* Exported types ------------------------------------------------------------*/
  51. /** @defgroup OSPI_Exported_Types OSPI Exported Types
  52. * @{
  53. */
  54. /**
  55. * @brief OSPI Init structure definition
  56. */
  57. typedef struct
  58. {
  59. uint32_t FifoThreshold; /* This is the threshold used byt the IP to generate the interrupt
  60. indicating that data are available in reception or free place
  61. is available in transmission.
  62. This parameter can be a value between 1 and 32 */
  63. uint32_t DualQuad; /* It enables or not the dual-quad mode which allow to access up to
  64. quad mode on two different devices to increase the throughput.
  65. This parameter can be a value of @ref OSPI_DualQuad */
  66. uint32_t MemoryType; /* It indicates the external device type connected to the OSPI.
  67. This parameter can be a value of @ref OSPI_MemoryType */
  68. uint32_t DeviceSize; /* It defines the size of the external device connected to the OSPI,
  69. it corresponds to the number of address bits required to access
  70. the external device.
  71. This parameter can be a value between 1 and 32 */
  72. uint32_t ChipSelectHighTime; /* It defines the minimun number of clocks which the chip select
  73. must remain high between commands.
  74. This parameter can be a value between 1 and 8 */
  75. uint32_t FreeRunningClock; /* It enables or not the free running clock.
  76. This parameter can be a value of @ref OSPI_FreeRunningClock */
  77. uint32_t ClockMode; /* It indicates the level of clock when the chip select is released.
  78. This parameter can be a value of @ref OSPI_ClockMode */
  79. uint32_t WrapSize; /* It indicates the wrap-size corresponding the external device configuration.
  80. This parameter can be a value of @ref OSPI_WrapSize */
  81. uint32_t ClockPrescaler; /* It specifies the prescaler factor used for generating
  82. the external clock based on the AHB clock.
  83. This parameter can be a value between 1 and 256 */
  84. uint32_t SampleShifting; /* It allows to delay to 1/2 cycle the data sampling in order
  85. to take in account external signal delays.
  86. This parameter can be a value of @ref OSPI_SampleShifting */
  87. uint32_t DelayHoldQuarterCycle; /* It allows to hold to 1/4 cycle the data.
  88. This parameter can be a value of @ref OSPI_DelayHoldQuarterCycle */
  89. uint32_t ChipSelectBoundary; /* It enables the transaction boundary feature and
  90. defines the boundary of bytes to release the chip select.
  91. This parameter can be a value between 0 and 31 */
  92. }OSPI_InitTypeDef;
  93. /**
  94. * @brief HAL OSPI Handle Structure definition
  95. */
  96. typedef struct
  97. {
  98. OCTOSPI_TypeDef *Instance; /* OSPI registers base address */
  99. OSPI_InitTypeDef Init; /* OSPI initialization parameters */
  100. uint8_t *pBuffPtr; /* Address of the OSPI buffer for transfer */
  101. __IO uint32_t XferSize; /* Number of data to transfer */
  102. __IO uint32_t XferCount; /* Counter of data transferred */
  103. DMA_HandleTypeDef *hdma; /* Handle of the DMA channel used for the transfer */
  104. __IO uint32_t State; /* Internal state of the OSPI HAL driver */
  105. __IO uint32_t ErrorCode; /* Error code in case of HAL driver internal error */
  106. uint32_t Timeout; /* Timeout used for the OSPI external device access */
  107. }OSPI_HandleTypeDef;
  108. /**
  109. * @brief HAL OSPI Regular Command Structure definition
  110. */
  111. typedef struct
  112. {
  113. uint32_t OperationType; /* It indicates if the configuration applies to the common regsiters or
  114. to the registers for the write operation (these registers are only
  115. used for memory-mapped mode).
  116. This parameter can be a value of @ref OSPI_OperationType */
  117. uint32_t FlashId; /* It indicates which external device is selected for this command (it
  118. applies only if Dualquad is disabled in the initialization structure).
  119. This parameter can be a value of @ref OSPI_FlashId */
  120. uint32_t Instruction; /* It contains the instruction to be sent to the device.
  121. This parameter can be a value between 0 and 0xFFFFFFFF */
  122. uint32_t InstructionMode; /* It indicates the mode of the instruction.
  123. This parameter can be a value of @ref OSPI_InstructionMode */
  124. uint32_t InstructionSize; /* It indicates the size of the instruction.
  125. This parameter can be a value of @ref OSPI_InstructionSize */
  126. uint32_t InstructionDtrMode; /* It enables or not the DTR mode for the instruction phase.
  127. This parameter can be a value of @ref OSPI_InstructionDtrMode */
  128. uint32_t Address; /* It contains the address to be sent to the device.
  129. This parameter can be a value between 0 and 0xFFFFFFFF */
  130. uint32_t AddressMode; /* It indicates the mode of the address.
  131. This parameter can be a value of @ref OSPI_AddressMode */
  132. uint32_t AddressSize; /* It indicates the size of the address.
  133. This parameter can be a value of @ref OSPI_AddressSize */
  134. uint32_t AddressDtrMode; /* It enables or not the DTR mode for the address phase.
  135. This parameter can be a value of @ref OSPI_AddressDtrMode */
  136. uint32_t AlternateBytes; /* It contains the alternate bytes to be sent to the device.
  137. This parameter can be a value between 0 and 0xFFFFFFFF */
  138. uint32_t AlternateBytesMode; /* It indicates the mode of the alternate bytes.
  139. This parameter can be a value of @ref OSPI_AlternateBytesMode */
  140. uint32_t AlternateBytesSize; /* It indicates the size of the alternate bytes.
  141. This parameter can be a value of @ref OSPI_AlternateBytesSize */
  142. uint32_t AlternateBytesDtrMode; /* It enables or not the DTR mode for the alternate bytes phase.
  143. This parameter can be a value of @ref OSPI_AlternateBytesDtrMode */
  144. uint32_t DataMode; /* It indicates the mode of the data.
  145. This parameter can be a value of @ref OSPI_DataMode */
  146. uint32_t NbData; /* It indicates the number of data transferred with this command.
  147. This field is only used for indirect mode.
  148. This parameter can be a value between 1 and 0xFFFFFFFF */
  149. uint32_t DataDtrMode; /* It enables or not the DTR mode for the data phase.
  150. This parameter can be a value of @ref OSPI_DataDtrMode */
  151. uint32_t DummyCycles; /* It indicates the number of dummy cycles inserted before data phase.
  152. This parameter can be a value between 0 and 31 */
  153. uint32_t DQSMode; /* It enables or not the data strobe management.
  154. This parameter can be a value of @ref OSPI_DQSMode */
  155. uint32_t SIOOMode; /* It enables or not the SIOO mode.
  156. This parameter can be a value of @ref OSPI_SIOOMode */
  157. }OSPI_RegularCmdTypeDef;
  158. /**
  159. * @brief HAL OSPI Hyperbus Configuration Structure definition
  160. */
  161. typedef struct
  162. {
  163. uint32_t RWRecoveryTime; /* It indicates the number of cycles for the device read write recovery time.
  164. This parameter can be a value between 0 and 255 */
  165. uint32_t AccessTime; /* It indicates the number of cycles for the device acces time.
  166. This parameter can be a value between 0 and 255 */
  167. uint32_t WriteZeroLatency; /* It enables or not the latency for the write access.
  168. This parameter can be a value of @ref OSPI_WriteZeroLatency */
  169. uint32_t LatencyMode; /* It configures the latency mode.
  170. This parameter can be a value of @ref OSPI_LatencyMode */
  171. }OSPI_HyperbusCfgTypeDef;
  172. /**
  173. * @brief HAL OSPI Hyperbus Command Structure definition
  174. */
  175. typedef struct
  176. {
  177. uint32_t AddressSpace; /* It indicates the address space accessed by the command.
  178. This parameter can be a value of @ref OSPI_AddressSpace */
  179. uint32_t Address; /* It contains the address to be sent tot he device.
  180. This parameter can be a value between 0 and 0xFFFFFFFF */
  181. uint32_t AddressSize; /* It indicates the size of the address.
  182. This parameter can be a value of @ref OSPI_AddressSize */
  183. uint32_t NbData; /* It indicates the number of data transferred with this command.
  184. This field is only used for indirect mode.
  185. This parameter can be a value between 1 and 0xFFFFFFFF
  186. In case of autopolling mode, this parameter can be any value between 1 and 4 */
  187. uint32_t DQSMode; /* It enables or not the data strobe management.
  188. This parameter can be a value of @ref OSPI_DQSMode */
  189. }OSPI_HyperbusCmdTypeDef;
  190. /**
  191. * @brief HAL OSPI Auto Polling mode configuration structure definition
  192. */
  193. typedef struct
  194. {
  195. uint32_t Match; /* Specifies the value to be compared with the masked status register to get a match.
  196. This parameter can be any value between 0 and 0xFFFFFFFF */
  197. uint32_t Mask; /* Specifies the mask to be applied to the status bytes received.
  198. This parameter can be any value between 0 and 0xFFFFFFFF */
  199. uint32_t MatchMode; /* Specifies the method used for determining a match.
  200. This parameter can be a value of @ref OSPI_MatchMode */
  201. uint32_t AutomaticStop; /* Specifies if automatic polling is stopped after a match.
  202. This parameter can be a value of @ref OSPI_AutomaticStop */
  203. uint32_t Interval; /* Specifies the number of clock cycles between two read during automatic polling phases.
  204. This parameter can be any value between 0 and 0xFFFF */
  205. }OSPI_AutoPollingTypeDef;
  206. /**
  207. * @brief HAL OSPI Memory Mapped mode configuration structure definition
  208. */
  209. typedef struct
  210. {
  211. uint32_t TimeOutActivation; /* Specifies if the timeout counter is enabled to release the chip select.
  212. This parameter can be a value of @ref OSPI_TimeOutActivation */
  213. uint32_t TimeOutPeriod; /* Specifies the number of clock to wait when the FIFO is full before to release the chip select.
  214. This parameter can be any value between 0 and 0xFFFF */
  215. }OSPI_MemoryMappedTypeDef;
  216. /**
  217. * @brief HAL OSPI IO Manager Configuration structure definition
  218. */
  219. typedef struct
  220. {
  221. uint32_t ClkPort; /* It indicates which port of the OSPI IO Manager is used for the CLK pins.
  222. This parameter can be a value between 1 and 8 */
  223. uint32_t DQSPort; /* It indicates which port of the OSPI IO Manager is used for the DQS pin.
  224. This parameter can be a value between 1 and 8 */
  225. uint32_t NCSPort; /* It indicates which port of the OSPI IO Manager is used for the NCS pin.
  226. This parameter can be a value between 1 and 8 */
  227. uint32_t IOLowPort; /* It indicates which port of the OSPI IO Manager is used for the IO[3:0] pins.
  228. This parameter can be a value of @ref OSPIM_IOPort */
  229. uint32_t IOHighPort; /* It indicates which port of the OSPI IO Manager is used for the IO[7:4] pins.
  230. This parameter can be a value of @ref OSPIM_IOPort */
  231. }OSPIM_CfgTypeDef;
  232. /**
  233. * @}
  234. */
  235. /* Exported constants --------------------------------------------------------*/
  236. /** @defgroup OSPI_Exported_Constants OSPI Exported Constants
  237. * @{
  238. */
  239. /** @defgroup OSPI_State OSPI State
  240. * @{
  241. */
  242. #define HAL_OSPI_STATE_RESET ((uint32_t)0x00000000U) /*!< Initial state */
  243. #define HAL_OSPI_STATE_HYPERBUS_INIT ((uint32_t)0x00000001U) /*!< Initialization done in hyperbus mode but timing configuration not done */
  244. #define HAL_OSPI_STATE_READY ((uint32_t)0x00000002U) /*!< Driver ready to be used */
  245. #define HAL_OSPI_STATE_CMD_CFG ((uint32_t)0x00000004U) /*!< Command (regular or hyperbus) configured, ready for an action */
  246. #define HAL_OSPI_STATE_READ_CMD_CFG ((uint32_t)0x00000014U) /*!< Read command configuration done, not the write command configuration */
  247. #define HAL_OSPI_STATE_WRITE_CMD_CFG ((uint32_t)0x00000024U) /*!< Write command configuration done, not the read command configuration */
  248. #define HAL_OSPI_STATE_BUSY_CMD ((uint32_t)0x00000008U) /*!< Command without data on-going */
  249. #define HAL_OSPI_STATE_BUSY_TX ((uint32_t)0x00000018U) /*!< Indirect Tx on-going */
  250. #define HAL_OSPI_STATE_BUSY_RX ((uint32_t)0x00000028U) /*!< Indirect Rx on-going */
  251. #define HAL_OSPI_STATE_BUSY_AUTO_POLLING ((uint32_t)0x00000048U) /*!< Auto-polling on-going */
  252. #define HAL_OSPI_STATE_BUSY_MEM_MAPPED ((uint32_t)0x00000088U) /*!< Memory-mapped on-going */
  253. #define HAL_OSPI_STATE_ABORT ((uint32_t)0x00000100U) /*!< Abort on-going */
  254. #define HAL_OSPI_STATE_ERROR ((uint32_t)0x00000200U) /*!< Blocking error, driver should be re-initialized */
  255. /**
  256. * @}
  257. */
  258. /** @defgroup OSPI_ErrorCode OSPI Error Code
  259. * @{
  260. */
  261. #define HAL_OSPI_ERROR_NONE ((uint32_t)0x00000000U) /*!< No error */
  262. #define HAL_OSPI_ERROR_TIMEOUT ((uint32_t)0x00000001U) /*!< Timeout error */
  263. #define HAL_OSPI_ERROR_TRANSFER ((uint32_t)0x00000002U) /*!< Transfer error */
  264. #define HAL_OSPI_ERROR_DMA ((uint32_t)0x00000004U) /*!< DMA transfer error */
  265. #define HAL_OSPI_ERROR_INVALID_PARAM ((uint32_t)0x00000008U) /*!< Invalid parameters error */
  266. #define HAL_OSPI_ERROR_INVALID_SEQUENCE ((uint32_t)0x00000010U) /*!< Sequence of the state machine is incorrect */
  267. /**
  268. * @}
  269. */
  270. /** @defgroup OSPI_DualQuad OSPI Dual-Quad
  271. * @{
  272. */
  273. #define HAL_OSPI_DUALQUAD_DISABLE ((uint32_t)0x00000000U) /*!< Dual-Quad mode disabled */
  274. #define HAL_OSPI_DUALQUAD_ENABLE ((uint32_t)OCTOSPI_CR_DQM) /*!< Dual-Quad mode enabled */
  275. /**
  276. * @}
  277. */
  278. /** @defgroup OSPI_MemoryType OSPI Memory Type
  279. * @{
  280. */
  281. #define HAL_OSPI_MEMTYPE_MICRON ((uint32_t)0x00000000U) /*!< Micron mode */
  282. #define HAL_OSPI_MEMTYPE_MACRONIX ((uint32_t)OCTOSPI_DCR1_MTYP_0) /*!< Macronix mode */
  283. #define HAL_OSPI_MEMTYPE_MACRONIX_RAM ((uint32_t)(OCTOSPI_DCR1_MTYP_1 | OCTOSPI_DCR1_MTYP_0)) /*!< Macronix RAM mode */
  284. #define HAL_OSPI_MEMTYPE_HYPERBUS ((uint32_t)OCTOSPI_DCR1_MTYP_2) /*!< Hyperbus mode */
  285. /**
  286. * @}
  287. */
  288. /** @defgroup OSPI_FreeRunningClock OSPI Free Running Clock
  289. * @{
  290. */
  291. #define HAL_OSPI_FREERUNCLK_DISABLE ((uint32_t)0x00000000U) /*!< CLK is not free running */
  292. #define HAL_OSPI_FREERUNCLK_ENABLE ((uint32_t)OCTOSPI_DCR1_FRCK) /*!< CLK is free running (always provided) */
  293. /**
  294. * @}
  295. */
  296. /** @defgroup OSPI_ClockMode OSPI Clock Mode
  297. * @{
  298. */
  299. #define HAL_OSPI_CLOCK_MODE_0 ((uint32_t)0x00000000U) /*!< CLK must stay low while nCS is high */
  300. #define HAL_OSPI_CLOCK_MODE_3 ((uint32_t)OCTOSPI_DCR1_CKMODE) /*!< CLK must stay high while nCS is high */
  301. /**
  302. * @}
  303. */
  304. /** @defgroup OSPI_WrapSize OSPI Wrap-Size
  305. * @{
  306. */
  307. #define HAL_OSPI_WRAP_NOT_SUPPORTED ((uint32_t)0x00000000U) /*!< wrapped reads are not supported by the memory */
  308. #define HAL_OSPI_WRAP_16_BYTES ((uint32_t)OCTOSPI_DCR2_WRAPSIZE_1) /*!< external memory supports wrap size of 16 bytes */
  309. #define HAL_OSPI_WRAP_32_BYTES ((uint32_t)(OCTOSPI_DCR2_WRAPSIZE_0 | OCTOSPI_DCR2_WRAPSIZE_1)) /*!< external memory supports wrap size of 32 bytes */
  310. #define HAL_OSPI_WRAP_64_BYTES ((uint32_t)OCTOSPI_DCR2_WRAPSIZE_2) /*!< external memory supports wrap size of 64 bytes */
  311. #define HAL_OSPI_WRAP_128_BYTES ((uint32_t)(OCTOSPI_DCR2_WRAPSIZE_0 | OCTOSPI_DCR2_WRAPSIZE_2)) /*!< external memory supports wrap size of 128 bytes */
  312. /**
  313. * @}
  314. */
  315. /** @defgroup OSPI_SampleShifting OSPI Sample Shifting
  316. * @{
  317. */
  318. #define HAL_OSPI_SAMPLE_SHIFTING_NONE ((uint32_t)0x00000000U) /*!< No shift */
  319. #define HAL_OSPI_SAMPLE_SHIFTING_HALFCYCLE ((uint32_t)OCTOSPI_TCR_SSHIFT) /*!< 1/2 cycle shift */
  320. /**
  321. * @}
  322. */
  323. /** @defgroup OSPI_DelayHoldQuarterCycle OSPI Delay Hold Quarter Cycle
  324. * @{
  325. */
  326. #define HAL_OSPI_DHQC_DISABLE ((uint32_t)0x00000000U) /*!< No Delay */
  327. #define HAL_OSPI_DHQC_ENABLE ((uint32_t)OCTOSPI_TCR_DHQC) /*!< Delay Hold 1/4 cycle */
  328. /**
  329. * @}
  330. */
  331. /** @defgroup OSPI_OperationType OSPI Operation Type
  332. * @{
  333. */
  334. #define HAL_OSPI_OPTYPE_COMMON_CFG ((uint32_t)0x00000000U) /*!< Common configuration (indirect or auto-polling mode) */
  335. #define HAL_OSPI_OPTYPE_READ_CFG ((uint32_t)0x00000001U) /*!< Read configuration (memory-mapped mode) */
  336. #define HAL_OSPI_OPTYPE_WRITE_CFG ((uint32_t)0x00000002U) /*!< Write configuration (memory-mapped mode) */
  337. /**
  338. * @}
  339. */
  340. /** @defgroup OSPI_FlashID OSPI Flash Id
  341. * @{
  342. */
  343. #define HAL_OSPI_FLASH_ID_1 ((uint32_t)0x00000000U) /*!< FLASH 1 selected */
  344. #define HAL_OSPI_FLASH_ID_2 ((uint32_t)OCTOSPI_CR_FSEL) /*!< FLASH 2 selected */
  345. /**
  346. * @}
  347. */
  348. /** @defgroup OSPI_InstructionMode OSPI Instruction Mode
  349. * @{
  350. */
  351. #define HAL_OSPI_INSTRUCTION_NONE ((uint32_t)0x00000000U) /*!< No instruction */
  352. #define HAL_OSPI_INSTRUCTION_1_LINE ((uint32_t)OCTOSPI_CCR_IMODE_0) /*!< Instruction on a single line */
  353. #define HAL_OSPI_INSTRUCTION_2_LINES ((uint32_t)OCTOSPI_CCR_IMODE_1) /*!< Instruction on two lines */
  354. #define HAL_OSPI_INSTRUCTION_4_LINES ((uint32_t)(OCTOSPI_CCR_IMODE_0 | OCTOSPI_CCR_IMODE_1)) /*!< Instruction on four lines */
  355. #define HAL_OSPI_INSTRUCTION_8_LINES ((uint32_t)OCTOSPI_CCR_IMODE_2) /*!< Instruction on eight lines */
  356. /**
  357. * @}
  358. */
  359. /** @defgroup OSPI_InstructionSize OSPI Instruction Size
  360. * @{
  361. */
  362. #define HAL_OSPI_INSTRUCTION_8_BITS ((uint32_t)0x00000000U) /*!< 8-bit instruction */
  363. #define HAL_OSPI_INSTRUCTION_16_BITS ((uint32_t)OCTOSPI_CCR_ISIZE_0) /*!< 16-bit instruction */
  364. #define HAL_OSPI_INSTRUCTION_24_BITS ((uint32_t)OCTOSPI_CCR_ISIZE_1) /*!< 24-bit instruction */
  365. #define HAL_OSPI_INSTRUCTION_32_BITS ((uint32_t)OCTOSPI_CCR_ISIZE) /*!< 32-bit instruction */
  366. /**
  367. * @}
  368. */
  369. /** @defgroup OSPI_InstructionDtrMode OSPI Instruction DTR Mode
  370. * @{
  371. */
  372. #define HAL_OSPI_INSTRUCTION_DTR_DISABLE ((uint32_t)0x00000000U) /*!< DTR mode disabled for instruction phase */
  373. #define HAL_OSPI_INSTRUCTION_DTR_ENABLE ((uint32_t)OCTOSPI_CCR_IDTR) /*!< DTR mode enabled for instruction phase */
  374. /**
  375. * @}
  376. */
  377. /** @defgroup OSPI_AddressMode OSPI Address Mode
  378. * @{
  379. */
  380. #define HAL_OSPI_ADDRESS_NONE ((uint32_t)0x00000000U) /*!< No address */
  381. #define HAL_OSPI_ADDRESS_1_LINE ((uint32_t)OCTOSPI_CCR_ADMODE_0) /*!< Address on a single line */
  382. #define HAL_OSPI_ADDRESS_2_LINES ((uint32_t)OCTOSPI_CCR_ADMODE_1) /*!< Address on two lines */
  383. #define HAL_OSPI_ADDRESS_4_LINES ((uint32_t)(OCTOSPI_CCR_ADMODE_0 | OCTOSPI_CCR_ADMODE_1)) /*!< Address on four lines */
  384. #define HAL_OSPI_ADDRESS_8_LINES ((uint32_t)OCTOSPI_CCR_ADMODE_2) /*!< Address on eight lines */
  385. /**
  386. * @}
  387. */
  388. /** @defgroup OSPI_AddressSize OSPI Address Size
  389. * @{
  390. */
  391. #define HAL_OSPI_ADDRESS_8_BITS ((uint32_t)0x00000000U) /*!< 8-bit address */
  392. #define HAL_OSPI_ADDRESS_16_BITS ((uint32_t)OCTOSPI_CCR_ADSIZE_0) /*!< 16-bit address */
  393. #define HAL_OSPI_ADDRESS_24_BITS ((uint32_t)OCTOSPI_CCR_ADSIZE_1) /*!< 24-bit address */
  394. #define HAL_OSPI_ADDRESS_32_BITS ((uint32_t)OCTOSPI_CCR_ADSIZE) /*!< 32-bit address */
  395. /**
  396. * @}
  397. */
  398. /** @defgroup OSPI_AddressDtrMode OSPI Address DTR Mode
  399. * @{
  400. */
  401. #define HAL_OSPI_ADDRESS_DTR_DISABLE ((uint32_t)0x00000000U) /*!< DTR mode disabled for address phase */
  402. #define HAL_OSPI_ADDRESS_DTR_ENABLE ((uint32_t)OCTOSPI_CCR_ADDTR) /*!< DTR mode enabled for address phase */
  403. /**
  404. * @}
  405. */
  406. /** @defgroup OSPI_AlternateBytesMode OSPI Alternate Bytes Mode
  407. * @{
  408. */
  409. #define HAL_OSPI_ALTERNATE_BYTES_NONE ((uint32_t)0x00000000U) /*!< No alternate bytes */
  410. #define HAL_OSPI_ALTERNATE_BYTES_1_LINE ((uint32_t)OCTOSPI_CCR_ABMODE_0) /*!< Alternate bytes on a single line */
  411. #define HAL_OSPI_ALTERNATE_BYTES_2_LINES ((uint32_t)OCTOSPI_CCR_ABMODE_1) /*!< Alternate bytes on two lines */
  412. #define HAL_OSPI_ALTERNATE_BYTES_4_LINES ((uint32_t)(OCTOSPI_CCR_ABMODE_0 | OCTOSPI_CCR_ABMODE_1)) /*!< Alternate bytes on four lines */
  413. #define HAL_OSPI_ALTERNATE_BYTES_8_LINES ((uint32_t)OCTOSPI_CCR_ABMODE_2) /*!< Alternate bytes on eight lines */
  414. /**
  415. * @}
  416. */
  417. /** @defgroup OSPI_AlternateBytesSize OSPI Alternate Bytes Size
  418. * @{
  419. */
  420. #define HAL_OSPI_ALTERNATE_BYTES_8_BITS ((uint32_t)0x00000000U) /*!< 8-bit alternate bytes */
  421. #define HAL_OSPI_ALTERNATE_BYTES_16_BITS ((uint32_t)OCTOSPI_CCR_ABSIZE_0) /*!< 16-bit alternate bytes */
  422. #define HAL_OSPI_ALTERNATE_BYTES_24_BITS ((uint32_t)OCTOSPI_CCR_ABSIZE_1) /*!< 24-bit alternate bytes */
  423. #define HAL_OSPI_ALTERNATE_BYTES_32_BITS ((uint32_t)OCTOSPI_CCR_ABSIZE) /*!< 32-bit alternate bytes */
  424. /**
  425. * @}
  426. */
  427. /** @defgroup OSPI_AlternateBytesDtrMode OSPI Alternate Bytes DTR Mode
  428. * @{
  429. */
  430. #define HAL_OSPI_ALTERNATE_BYTES_DTR_DISABLE ((uint32_t)0x00000000U) /*!< DTR mode disabled for alternate bytes phase */
  431. #define HAL_OSPI_ALTERNATE_BYTES_DTR_ENABLE ((uint32_t)OCTOSPI_CCR_ABDTR) /*!< DTR mode enabled for alternate bytes phase */
  432. /**
  433. * @}
  434. */
  435. /** @defgroup OSPI_DataMode OSPI Data Mode
  436. * @{
  437. */
  438. #define HAL_OSPI_DATA_NONE ((uint32_t)0x00000000U) /*!< No data */
  439. #define HAL_OSPI_DATA_1_LINE ((uint32_t)OCTOSPI_CCR_DMODE_0) /*!< Data on a single line */
  440. #define HAL_OSPI_DATA_2_LINES ((uint32_t)OCTOSPI_CCR_DMODE_1) /*!< Data on two lines */
  441. #define HAL_OSPI_DATA_4_LINES ((uint32_t)(OCTOSPI_CCR_DMODE_0 | OCTOSPI_CCR_DMODE_1)) /*!< Data on four lines */
  442. #define HAL_OSPI_DATA_8_LINES ((uint32_t)OCTOSPI_CCR_DMODE_2) /*!< Data on eight lines */
  443. /**
  444. * @}
  445. */
  446. /** @defgroup OSPI_DataDtrMode OSPI Data DTR Mode
  447. * @{
  448. */
  449. #define HAL_OSPI_DATA_DTR_DISABLE ((uint32_t)0x00000000U) /*!< DTR mode disabled for data phase */
  450. #define HAL_OSPI_DATA_DTR_ENABLE ((uint32_t)OCTOSPI_CCR_DDTR) /*!< DTR mode enabled for data phase */
  451. /**
  452. * @}
  453. */
  454. /** @defgroup OSPI_DQSMode OSPI DQS Mode
  455. * @{
  456. */
  457. #define HAL_OSPI_DQS_DISABLE ((uint32_t)0x00000000U) /*!< DQS disabled */
  458. #define HAL_OSPI_DQS_ENABLE ((uint32_t)OCTOSPI_CCR_DQSE) /*!< DQS enabled */
  459. /**
  460. * @}
  461. */
  462. /** @defgroup OSPI_SIOOMode OSPI SIOO Mode
  463. * @{
  464. */
  465. #define HAL_OSPI_SIOO_INST_EVERY_CMD ((uint32_t)0x00000000U) /*!< Send instruction on every transaction */
  466. #define HAL_OSPI_SIOO_INST_ONLY_FIRST_CMD ((uint32_t)OCTOSPI_CCR_SIOO) /*!< Send instruction only for the first command */
  467. /**
  468. * @}
  469. */
  470. /** @defgroup OSPI_WriteZeroLatency OSPI Hyperbus Write Zero Latency Activation
  471. * @{
  472. */
  473. #define HAL_OSPI_LATENCY_ON_WRITE ((uint32_t)0x00000000U) /*!< Latency on write accesses */
  474. #define HAL_OSPI_NO_LATENCY_ON_WRITE ((uint32_t)OCTOSPI_HLCR_WZL) /*!< No latency on write accesses */
  475. /**
  476. * @}
  477. */
  478. /** @defgroup OSPI_LatencyMode OSPI Hyperbus Latency Mode
  479. * @{
  480. */
  481. #define HAL_OSPI_VARIABLE_LATENCY ((uint32_t)0x00000000U) /*!< Variable initial latency */
  482. #define HAL_OSPI_FIXED_LATENCY ((uint32_t)OCTOSPI_HLCR_LM) /*!< Fixed latency */
  483. /**
  484. * @}
  485. */
  486. /** @defgroup OSPI_AddressSpace OSPI Hyperbus Address Space
  487. * @{
  488. */
  489. #define HAL_OSPI_MEMORY_ADDRESS_SPACE ((uint32_t)0x00000000U) /*!< HyperBus memory mode */
  490. #define HAL_OSPI_REGISTER_ADDRESS_SPACE ((uint32_t)OCTOSPI_DCR1_MTYP_0) /*!< HyperBus register mode */
  491. /**
  492. * @}
  493. */
  494. /** @defgroup OSPI_MatchMode OSPI Match Mode
  495. * @{
  496. */
  497. #define HAL_OSPI_MATCH_MODE_AND ((uint32_t)0x00000000U) /*!< AND match mode between unmasked bits */
  498. #define HAL_OSPI_MATCH_MODE_OR ((uint32_t)OCTOSPI_CR_PMM) /*!< OR match mode between unmasked bits */
  499. /**
  500. * @}
  501. */
  502. /** @defgroup OSPI_AutomaticStop OSPI Automatic Stop
  503. * @{
  504. */
  505. #define HAL_OSPI_AUTOMATIC_STOP_DISABLE ((uint32_t)0x00000000U) /*!< AutoPolling stops only with abort or OSPI disabling */
  506. #define HAL_OSPI_AUTOMATIC_STOP_ENABLE ((uint32_t)OCTOSPI_CR_APMS) /*!< AutoPolling stops as soon as there is a match */
  507. /**
  508. * @}
  509. */
  510. /** @defgroup OSPI_TimeOutActivation OSPI Timeout Activation
  511. * @{
  512. */
  513. #define HAL_OSPI_TIMEOUT_COUNTER_DISABLE ((uint32_t)0x00000000U) /*!< Timeout counter disabled, nCS remains active */
  514. #define HAL_OSPI_TIMEOUT_COUNTER_ENABLE ((uint32_t)OCTOSPI_CR_TCEN) /*!< Timeout counter enabled, nCS released when timeout expires */
  515. /**
  516. * @}
  517. */
  518. /** @defgroup OSPI_Flags OSPI Flags
  519. * @{
  520. */
  521. #define HAL_OSPI_FLAG_BUSY OCTOSPI_SR_BUSY /*!< Busy flag: operation is ongoing */
  522. #define HAL_OSPI_FLAG_TO OCTOSPI_SR_TOF /*!< Timeout flag: timeout occurs in memory-mapped mode */
  523. #define HAL_OSPI_FLAG_SM OCTOSPI_SR_SMF /*!< Status match flag: received data matches in autopolling mode */
  524. #define HAL_OSPI_FLAG_FT OCTOSPI_SR_FTF /*!< Fifo threshold flag: Fifo threshold reached or data left after read from memory is complete */
  525. #define HAL_OSPI_FLAG_TC OCTOSPI_SR_TCF /*!< Transfer complete flag: programmed number of data have been transferred or the transfer has been aborted */
  526. #define HAL_OSPI_FLAG_TE OCTOSPI_SR_TEF /*!< Transfer error flag: invalid address is being accessed */
  527. /**
  528. * @}
  529. */
  530. /** @defgroup OSPI_Interrupts OSPI Interrupts
  531. * @{
  532. */
  533. #define HAL_OSPI_IT_TO OCTOSPI_CR_TOIE /*!< Interrupt on the timeout flag */
  534. #define HAL_OSPI_IT_SM OCTOSPI_CR_SMIE /*!< Interrupt on the status match flag */
  535. #define HAL_OSPI_IT_FT OCTOSPI_CR_FTIE /*!< Interrupt on the fifo threshold flag */
  536. #define HAL_OSPI_IT_TC OCTOSPI_CR_TCIE /*!< Interrupt on the transfer complete flag */
  537. #define HAL_OSPI_IT_TE OCTOSPI_CR_TEIE /*!< Interrupt on the transfer error flag */
  538. /**
  539. * @}
  540. */
  541. /** @defgroup OSPI_Timeout_definition OSPI Timeout definition
  542. * @{
  543. */
  544. #define HAL_OSPI_TIMEOUT_DEFAULT_VALUE ((uint32_t)5000U) /* 5 s */
  545. /**
  546. * @}
  547. */
  548. /** @defgroup OSPIM_IOPort OSPI IO Manager IO Port
  549. * @{
  550. */
  551. #define HAL_OSPIM_IOPORT_1_LOW ((uint32_t)(OCTOSPIM_PCR_IOLEN | 0x1)) /*!< Port 1 - IO[3:0] */
  552. #define HAL_OSPIM_IOPORT_1_HIGH ((uint32_t)(OCTOSPIM_PCR_IOHEN | 0x1)) /*!< Port 1 - IO[7:4] */
  553. #define HAL_OSPIM_IOPORT_2_LOW ((uint32_t)(OCTOSPIM_PCR_IOLEN | 0x2)) /*!< Port 2 - IO[3:0] */
  554. #define HAL_OSPIM_IOPORT_2_HIGH ((uint32_t)(OCTOSPIM_PCR_IOHEN | 0x2)) /*!< Port 2 - IO[7:4] */
  555. /**
  556. * @}
  557. */
  558. /**
  559. * @}
  560. */
  561. /* Exported macros -----------------------------------------------------------*/
  562. /** @defgroup OSPI_Exported_Macros OSPI Exported Macros
  563. * @{
  564. */
  565. /** @brief Reset OSPI handle state.
  566. * @param __HANDLE__: OSPI handle.
  567. * @retval None
  568. */
  569. #define __HAL_OSPI_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_OSPI_STATE_RESET)
  570. /** @brief Enable the OSPI peripheral.
  571. * @param __HANDLE__: specifies the OSPI Handle.
  572. * @retval None
  573. */
  574. #define __HAL_OSPI_ENABLE(__HANDLE__) SET_BIT((__HANDLE__)->Instance->CR, OCTOSPI_CR_EN)
  575. /** @brief Disable the OSPI peripheral.
  576. * @param __HANDLE__: specifies the OSPI Handle.
  577. * @retval None
  578. */
  579. #define __HAL_OSPI_DISABLE(__HANDLE__) CLEAR_BIT((__HANDLE__)->Instance->CR, OCTOSPI_CR_EN)
  580. /** @brief Enable the specified OSPI interrupt.
  581. * @param __HANDLE__: specifies the OSPI Handle.
  582. * @param __INTERRUPT__: specifies the OSPI interrupt source to enable.
  583. * This parameter can be one of the following values:
  584. * @arg HAL_OSPI_IT_TO: OSPI Timeout interrupt
  585. * @arg HAL_OSPI_IT_SM: OSPI Status match interrupt
  586. * @arg HAL_OSPI_IT_FT: OSPI FIFO threshold interrupt
  587. * @arg HAL_OSPI_IT_TC: OSPI Transfer complete interrupt
  588. * @arg HAL_OSPI_IT_TE: OSPI Transfer error interrupt
  589. * @retval None
  590. */
  591. #define __HAL_OSPI_ENABLE_IT(__HANDLE__, __INTERRUPT__) SET_BIT((__HANDLE__)->Instance->CR, (__INTERRUPT__))
  592. /** @brief Disable the specified OSPI interrupt.
  593. * @param __HANDLE__: specifies the OSPI Handle.
  594. * @param __INTERRUPT__: specifies the OSPI interrupt source to disable.
  595. * This parameter can be one of the following values:
  596. * @arg HAL_OSPI_IT_TO: OSPI Timeout interrupt
  597. * @arg HAL_OSPI_IT_SM: OSPI Status match interrupt
  598. * @arg HAL_OSPI_IT_FT: OSPI FIFO threshold interrupt
  599. * @arg HAL_OSPI_IT_TC: OSPI Transfer complete interrupt
  600. * @arg HAL_OSPI_IT_TE: OSPI Transfer error interrupt
  601. * @retval None
  602. */
  603. #define __HAL_OSPI_DISABLE_IT(__HANDLE__, __INTERRUPT__) CLEAR_BIT((__HANDLE__)->Instance->CR, (__INTERRUPT__))
  604. /** @brief Check whether the specified OSPI interrupt source is enabled or not.
  605. * @param __HANDLE__: specifies the OSPI Handle.
  606. * @param __INTERRUPT__: specifies the OSPI interrupt source to check.
  607. * This parameter can be one of the following values:
  608. * @arg HAL_OSPI_IT_TO: OSPI Timeout interrupt
  609. * @arg HAL_OSPI_IT_SM: OSPI Status match interrupt
  610. * @arg HAL_OSPI_IT_FT: OSPI FIFO threshold interrupt
  611. * @arg HAL_OSPI_IT_TC: OSPI Transfer complete interrupt
  612. * @arg HAL_OSPI_IT_TE: OSPI Transfer error interrupt
  613. * @retval The new state of __INTERRUPT__ (TRUE or FALSE).
  614. */
  615. #define __HAL_OSPI_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (READ_BIT((__HANDLE__)->Instance->CR, (__INTERRUPT__)) == (__INTERRUPT__))
  616. /**
  617. * @brief Check whether the selected OSPI flag is set or not.
  618. * @param __HANDLE__: specifies the OSPI Handle.
  619. * @param __FLAG__: specifies the OSPI flag to check.
  620. * This parameter can be one of the following values:
  621. * @arg HAL_OSPI_FLAG_BUSY: OSPI Busy flag
  622. * @arg HAL_OSPI_FLAG_TO: OSPI Timeout flag
  623. * @arg HAL_OSPI_FLAG_SM: OSPI Status match flag
  624. * @arg HAL_OSPI_FLAG_FT: OSPI FIFO threshold flag
  625. * @arg HAL_OSPI_FLAG_TC: OSPI Transfer complete flag
  626. * @arg HAL_OSPI_FLAG_TE: OSPI Transfer error flag
  627. * @retval None
  628. */
  629. #define __HAL_OSPI_GET_FLAG(__HANDLE__, __FLAG__) ((READ_BIT((__HANDLE__)->Instance->SR, (__FLAG__)) != 0) ? SET : RESET)
  630. /** @brief Clears the specified OSPI's flag status.
  631. * @param __HANDLE__: specifies the OSPI Handle.
  632. * @param __FLAG__: specifies the OSPI clear register flag that needs to be set
  633. * This parameter can be one of the following values:
  634. * @arg HAL_OSPI_FLAG_TO: OSPI Timeout flag
  635. * @arg HAL_OSPI_FLAG_SM: OSPI Status match flag
  636. * @arg HAL_OSPI_FLAG_TC: OSPI Transfer complete flag
  637. * @arg HAL_OSPI_FLAG_TE: OSPI Transfer error flag
  638. * @retval None
  639. */
  640. #define __HAL_OSPI_CLEAR_FLAG(__HANDLE__, __FLAG__) WRITE_REG((__HANDLE__)->Instance->FCR, (__FLAG__))
  641. /**
  642. * @}
  643. */
  644. /* Exported functions --------------------------------------------------------*/
  645. /** @addtogroup OSPI_Exported_Functions
  646. * @{
  647. */
  648. /* Initialization/de-initialization functions ********************************/
  649. /** @addtogroup OSPI_Exported_Functions_Group1
  650. * @{
  651. */
  652. HAL_StatusTypeDef HAL_OSPI_Init (OSPI_HandleTypeDef *hospi);
  653. void HAL_OSPI_MspInit (OSPI_HandleTypeDef *hospi);
  654. HAL_StatusTypeDef HAL_OSPI_DeInit (OSPI_HandleTypeDef *hospi);
  655. void HAL_OSPI_MspDeInit (OSPI_HandleTypeDef *hospi);
  656. /**
  657. * @}
  658. */
  659. /* IO operation functions *****************************************************/
  660. /** @addtogroup OSPI_Exported_Functions_Group2
  661. * @{
  662. */
  663. /* OSPI IRQ handler function */
  664. void HAL_OSPI_IRQHandler (OSPI_HandleTypeDef *hospi);
  665. /* OSPI command configuration functions */
  666. HAL_StatusTypeDef HAL_OSPI_Command (OSPI_HandleTypeDef *hospi, OSPI_RegularCmdTypeDef *cmd, uint32_t Timeout);
  667. HAL_StatusTypeDef HAL_OSPI_Command_IT (OSPI_HandleTypeDef *hospi, OSPI_RegularCmdTypeDef *cmd);
  668. HAL_StatusTypeDef HAL_OSPI_HyperbusCfg (OSPI_HandleTypeDef *hospi, OSPI_HyperbusCfgTypeDef *cfg, uint32_t Timeout);
  669. HAL_StatusTypeDef HAL_OSPI_HyperbusCmd (OSPI_HandleTypeDef *hospi, OSPI_HyperbusCmdTypeDef *cmd, uint32_t Timeout);
  670. /* OSPI indirect mode functions */
  671. HAL_StatusTypeDef HAL_OSPI_Transmit (OSPI_HandleTypeDef *hospi, uint8_t *pData, uint32_t Timeout);
  672. HAL_StatusTypeDef HAL_OSPI_Receive (OSPI_HandleTypeDef *hospi, uint8_t *pData, uint32_t Timeout);
  673. HAL_StatusTypeDef HAL_OSPI_Transmit_IT (OSPI_HandleTypeDef *hospi, uint8_t *pData);
  674. HAL_StatusTypeDef HAL_OSPI_Receive_IT (OSPI_HandleTypeDef *hospi, uint8_t *pData);
  675. HAL_StatusTypeDef HAL_OSPI_Transmit_DMA (OSPI_HandleTypeDef *hospi, uint8_t *pData);
  676. HAL_StatusTypeDef HAL_OSPI_Receive_DMA (OSPI_HandleTypeDef *hospi, uint8_t *pData);
  677. /* OSPI status flag polling mode functions */
  678. HAL_StatusTypeDef HAL_OSPI_AutoPolling (OSPI_HandleTypeDef *hospi, OSPI_AutoPollingTypeDef *cfg, uint32_t Timeout);
  679. HAL_StatusTypeDef HAL_OSPI_AutoPolling_IT (OSPI_HandleTypeDef *hospi, OSPI_AutoPollingTypeDef *cfg);
  680. /* OSPI memory-mapped mode functions */
  681. HAL_StatusTypeDef HAL_OSPI_MemoryMapped (OSPI_HandleTypeDef *hospi, OSPI_MemoryMappedTypeDef *cfg);
  682. /* Callback functions in non-blocking modes ***********************************/
  683. void HAL_OSPI_ErrorCallback (OSPI_HandleTypeDef *hospi);
  684. void HAL_OSPI_AbortCpltCallback (OSPI_HandleTypeDef *hospi);
  685. void HAL_OSPI_FifoThresholdCallback(OSPI_HandleTypeDef *hospi);
  686. /* OSPI indirect mode functions */
  687. void HAL_OSPI_CmdCpltCallback (OSPI_HandleTypeDef *hospi);
  688. void HAL_OSPI_RxCpltCallback (OSPI_HandleTypeDef *hospi);
  689. void HAL_OSPI_TxCpltCallback (OSPI_HandleTypeDef *hospi);
  690. void HAL_OSPI_RxHalfCpltCallback (OSPI_HandleTypeDef *hospi);
  691. void HAL_OSPI_TxHalfCpltCallback (OSPI_HandleTypeDef *hospi);
  692. /* OSPI status flag polling mode functions */
  693. void HAL_OSPI_StatusMatchCallback (OSPI_HandleTypeDef *hospi);
  694. /* OSPI memory-mapped mode functions */
  695. void HAL_OSPI_TimeOutCallback (OSPI_HandleTypeDef *hospi);
  696. /**
  697. * @}
  698. */
  699. /* Peripheral Control and State functions ************************************/
  700. /** @addtogroup OSPI_Exported_Functions_Group3
  701. * @{
  702. */
  703. HAL_StatusTypeDef HAL_OSPI_Abort (OSPI_HandleTypeDef *hospi);
  704. HAL_StatusTypeDef HAL_OSPI_Abort_IT (OSPI_HandleTypeDef *hospi);
  705. HAL_StatusTypeDef HAL_OSPI_SetFifoThreshold (OSPI_HandleTypeDef *hospi, uint32_t Threshold);
  706. uint32_t HAL_OSPI_GetFifoThreshold (OSPI_HandleTypeDef *hospi);
  707. HAL_StatusTypeDef HAL_OSPI_SetTimeout (OSPI_HandleTypeDef *hospi, uint32_t Timeout);
  708. uint32_t HAL_OSPI_GetError (OSPI_HandleTypeDef *hospi);
  709. uint32_t HAL_OSPI_GetState (OSPI_HandleTypeDef *hospi);
  710. /**
  711. * @}
  712. */
  713. /* OSPI IO Manager configuration function ************************************/
  714. /** @addtogroup OSPI_Exported_Functions_Group4
  715. * @{
  716. */
  717. HAL_StatusTypeDef HAL_OSPIM_Config (OSPI_HandleTypeDef *hospi, OSPIM_CfgTypeDef *cfg, uint32_t Timeout);
  718. /**
  719. * @}
  720. */
  721. /**
  722. * @}
  723. */
  724. /* End of exported functions -------------------------------------------------*/
  725. /* Private macros ------------------------------------------------------------*/
  726. /**
  727. @cond 0
  728. */
  729. #define IS_OSPI_FIFO_THRESHOLD(THRESHOLD) (((THRESHOLD) >= 1) && ((THRESHOLD) <= 32))
  730. #define IS_OSPI_DUALQUAD_MODE(MODE) (((MODE) == HAL_OSPI_DUALQUAD_DISABLE) || \
  731. ((MODE) == HAL_OSPI_DUALQUAD_ENABLE))
  732. #define IS_OSPI_MEMORY_TYPE(TYPE) (((TYPE) == HAL_OSPI_MEMTYPE_MICRON) || \
  733. ((TYPE) == HAL_OSPI_MEMTYPE_MACRONIX) || \
  734. ((TYPE) == HAL_OSPI_MEMTYPE_HYPERBUS))
  735. #define IS_OSPI_DEVICE_SIZE(SIZE) (((SIZE) >= 1) && ((SIZE) <= 32))
  736. #define IS_OSPI_CS_HIGH_TIME(TIME) (((TIME) >= 1) && ((TIME) <= 8))
  737. #define IS_OSPI_FREE_RUN_CLK(CLK) (((CLK) == HAL_OSPI_FREERUNCLK_DISABLE) || \
  738. ((CLK) == HAL_OSPI_FREERUNCLK_ENABLE))
  739. #define IS_OSPI_CLOCK_MODE(MODE) (((MODE) == HAL_OSPI_CLOCK_MODE_0) || \
  740. ((MODE) == HAL_OSPI_CLOCK_MODE_3))
  741. #define IS_OSPI_WRAP_SIZE(SIZE) (((SIZE) == HAL_OSPI_WRAP_NOT_SUPPORTED) || \
  742. ((SIZE) == HAL_OSPI_WRAP_16_BYTES) || \
  743. ((SIZE) == HAL_OSPI_WRAP_32_BYTES) || \
  744. ((SIZE) == HAL_OSPI_WRAP_64_BYTES) || \
  745. ((SIZE) == HAL_OSPI_WRAP_128_BYTES))
  746. #define IS_OSPI_CLK_PRESCALER(PRESCALER) (((PRESCALER) >= 1) && ((PRESCALER) <= 256))
  747. #define IS_OSPI_SAMPLE_SHIFTING(CYCLE) (((CYCLE) == HAL_OSPI_SAMPLE_SHIFTING_NONE) || \
  748. ((CYCLE) == HAL_OSPI_SAMPLE_SHIFTING_HALFCYCLE))
  749. #define IS_OSPI_DHQC(CYCLE) (((CYCLE) == HAL_OSPI_DHQC_DISABLE) || \
  750. ((CYCLE) == HAL_OSPI_DHQC_ENABLE))
  751. #define IS_OSPI_OPERATION_TYPE(TYPE) (((TYPE) == HAL_OSPI_OPTYPE_COMMON_CFG) || \
  752. ((TYPE) == HAL_OSPI_OPTYPE_READ_CFG) || \
  753. ((TYPE) == HAL_OSPI_OPTYPE_WRITE_CFG))
  754. #define IS_OSPI_FLASH_ID(FLASH) (((FLASH) == HAL_OSPI_FLASH_ID_1) || \
  755. ((FLASH) == HAL_OSPI_FLASH_ID_2))
  756. #define IS_OSPI_INSTRUCTION_MODE(MODE) (((MODE) == HAL_OSPI_INSTRUCTION_NONE) || \
  757. ((MODE) == HAL_OSPI_INSTRUCTION_1_LINE) || \
  758. ((MODE) == HAL_OSPI_INSTRUCTION_2_LINES) || \
  759. ((MODE) == HAL_OSPI_INSTRUCTION_4_LINES) || \
  760. ((MODE) == HAL_OSPI_INSTRUCTION_8_LINES))
  761. #define IS_OSPI_INSTRUCTION_SIZE(SIZE) (((SIZE) == HAL_OSPI_INSTRUCTION_8_BITS) || \
  762. ((SIZE) == HAL_OSPI_INSTRUCTION_16_BITS) || \
  763. ((SIZE) == HAL_OSPI_INSTRUCTION_24_BITS) || \
  764. ((SIZE) == HAL_OSPI_INSTRUCTION_32_BITS))
  765. #define IS_OSPI_INSTRUCTION_DTR_MODE(MODE) (((MODE) == HAL_OSPI_INSTRUCTION_DTR_DISABLE) || \
  766. ((MODE) == HAL_OSPI_INSTRUCTION_DTR_ENABLE))
  767. #define IS_OSPI_ADDRESS_MODE(MODE) (((MODE) == HAL_OSPI_ADDRESS_NONE) || \
  768. ((MODE) == HAL_OSPI_ADDRESS_1_LINE) || \
  769. ((MODE) == HAL_OSPI_ADDRESS_2_LINES) || \
  770. ((MODE) == HAL_OSPI_ADDRESS_4_LINES) || \
  771. ((MODE) == HAL_OSPI_ADDRESS_8_LINES))
  772. #define IS_OSPI_ADDRESS_SIZE(SIZE) (((SIZE) == HAL_OSPI_ADDRESS_8_BITS) || \
  773. ((SIZE) == HAL_OSPI_ADDRESS_16_BITS) || \
  774. ((SIZE) == HAL_OSPI_ADDRESS_24_BITS) || \
  775. ((SIZE) == HAL_OSPI_ADDRESS_32_BITS))
  776. #define IS_OSPI_ADDRESS_DTR_MODE(MODE) (((MODE) == HAL_OSPI_ADDRESS_DTR_DISABLE) || \
  777. ((MODE) == HAL_OSPI_ADDRESS_DTR_ENABLE))
  778. #define IS_OSPI_ALT_BYTES_MODE(MODE) (((MODE) == HAL_OSPI_ALTERNATE_BYTES_NONE) || \
  779. ((MODE) == HAL_OSPI_ALTERNATE_BYTES_1_LINE) || \
  780. ((MODE) == HAL_OSPI_ALTERNATE_BYTES_2_LINES) || \
  781. ((MODE) == HAL_OSPI_ALTERNATE_BYTES_4_LINES) || \
  782. ((MODE) == HAL_OSPI_ALTERNATE_BYTES_8_LINES))
  783. #define IS_OSPI_ALT_BYTES_SIZE(SIZE) (((SIZE) == HAL_OSPI_ALTERNATE_BYTES_8_BITS) || \
  784. ((SIZE) == HAL_OSPI_ALTERNATE_BYTES_16_BITS) || \
  785. ((SIZE) == HAL_OSPI_ALTERNATE_BYTES_24_BITS) || \
  786. ((SIZE) == HAL_OSPI_ALTERNATE_BYTES_32_BITS))
  787. #define IS_OSPI_ALT_BYTES_DTR_MODE(MODE) (((MODE) == HAL_OSPI_ALTERNATE_BYTES_DTR_DISABLE) || \
  788. ((MODE) == HAL_OSPI_ALTERNATE_BYTES_DTR_ENABLE))
  789. #define IS_OSPI_DATA_MODE(MODE) (((MODE) == HAL_OSPI_DATA_NONE) || \
  790. ((MODE) == HAL_OSPI_DATA_1_LINE) || \
  791. ((MODE) == HAL_OSPI_DATA_2_LINES) || \
  792. ((MODE) == HAL_OSPI_DATA_4_LINES) || \
  793. ((MODE) == HAL_OSPI_DATA_8_LINES))
  794. #define IS_OSPI_NUMBER_DATA(NUMBER) ((NUMBER) >= 1)
  795. #define IS_OSPI_DATA_DTR_MODE(MODE) (((MODE) == HAL_OSPI_DATA_DTR_DISABLE) || \
  796. ((MODE) == HAL_OSPI_DATA_DTR_ENABLE))
  797. #define IS_OSPI_DUMMY_CYCLES(NUMBER) ((NUMBER) <= 31)
  798. #define IS_OSPI_DQS_MODE(MODE) (((MODE) == HAL_OSPI_DQS_DISABLE) || \
  799. ((MODE) == HAL_OSPI_DQS_ENABLE))
  800. #define IS_OSPI_SIOO_MODE(MODE) (((MODE) == HAL_OSPI_SIOO_INST_EVERY_CMD) || \
  801. ((MODE) == HAL_OSPI_SIOO_INST_ONLY_FIRST_CMD))
  802. #define IS_OSPI_RW_RECOVERY_TIME(NUMBER) ((NUMBER) <= 255)
  803. #define IS_OSPI_ACCESS_TIME(NUMBER) ((NUMBER) <= 255)
  804. #define IS_OSPI_WRITE_ZERO_LATENCY(MODE) (((MODE) == HAL_OSPI_LATENCY_ON_WRITE) || \
  805. ((MODE) == HAL_OSPI_NO_LATENCY_ON_WRITE))
  806. #define IS_OSPI_LATENCY_MODE(MODE) (((MODE) == HAL_OSPI_VARIABLE_LATENCY) || \
  807. ((MODE) == HAL_OSPI_FIXED_LATENCY))
  808. #define IS_OSPI_ADDRESS_SPACE(SPACE) (((SPACE) == HAL_OSPI_MEMORY_ADDRESS_SPACE) || \
  809. ((SPACE) == HAL_OSPI_REGISTER_ADDRESS_SPACE))
  810. #define IS_OSPI_MATCH_MODE(MODE) (((MODE) == HAL_OSPI_MATCH_MODE_AND) || \
  811. ((MODE) == HAL_OSPI_MATCH_MODE_OR))
  812. #define IS_OSPI_AUTOMATIC_STOP(MODE) (((MODE) == HAL_OSPI_AUTOMATIC_STOP_ENABLE) || \
  813. ((MODE) == HAL_OSPI_AUTOMATIC_STOP_DISABLE))
  814. #define IS_OSPI_INTERVAL(INTERVAL) ((INTERVAL) <= 0xFFFF)
  815. #define IS_OSPI_STATUS_BYTES_SIZE(SIZE) (((SIZE) >= 1) && ((SIZE) <= 4))
  816. #define IS_OSPI_TIMEOUT_ACTIVATION(MODE) (((MODE) == HAL_OSPI_TIMEOUT_COUNTER_DISABLE) || \
  817. ((MODE) == HAL_OSPI_TIMEOUT_COUNTER_ENABLE))
  818. #define IS_OSPI_TIMEOUT_PERIOD(PERIOD) ((PERIOD) <= 0xFFFF)
  819. #define IS_OSPI_CS_BOUNDARY(BOUNDARY) ((BOUNDARY) <= 31)
  820. #define IS_OSPIM_PORT(NUMBER) (((NUMBER) >= 1) && ((NUMBER) <= 2))
  821. #define IS_OSPIM_IO_PORT(PORT) (((PORT) == HAL_OSPIM_IOPORT_1_LOW) || \
  822. ((PORT) == HAL_OSPIM_IOPORT_1_HIGH) || \
  823. ((PORT) == HAL_OSPIM_IOPORT_2_LOW) || \
  824. ((PORT) == HAL_OSPIM_IOPORT_2_HIGH))
  825. /**
  826. @endcond
  827. */
  828. /* End of private macros -----------------------------------------------------*/
  829. /**
  830. * @}
  831. */
  832. /**
  833. * @}
  834. */
  835. #endif /* OCTOSPI || OCTOSPI1 || OCTOSPI2 */
  836. #ifdef __cplusplus
  837. }
  838. #endif
  839. #endif /* __STM32L4xx_HAL_OSPI_H */
  840. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/