py32f0xx_ll_spi.h 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185
  1. /**
  2. ******************************************************************************
  3. * @file py32f0xx_ll_spi.h
  4. * @author MCU Application Team
  5. * @brief Header file of SPI LL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2023 Puya Semiconductor Co.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by Puya under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. * @attention
  19. *
  20. * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
  21. * All rights reserved.</center></h2>
  22. *
  23. * This software component is licensed by ST under BSD 3-Clause license,
  24. * the "License"; You may not use this file except in compliance with the
  25. * License. You may obtain a copy of the License at:
  26. * opensource.org/licenses/BSD-3-Clause
  27. *
  28. ******************************************************************************
  29. */
  30. /* Define to prevent recursive inclusion -------------------------------------*/
  31. #ifndef PY32F0xx_LL_SPI_H
  32. #define PY32F0xx_LL_SPI_H
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. /* Includes ------------------------------------------------------------------*/
  37. #include "py32f0xx.h"
  38. /** @addtogroup PY32F0xx_LL_Driver
  39. * @{
  40. */
  41. #if defined (SPI1) || defined (SPI2)
  42. /** @defgroup SPI_LL SPI
  43. * @{
  44. */
  45. /* Private types -------------------------------------------------------------*/
  46. /* Private variables ---------------------------------------------------------*/
  47. /* Private macros ------------------------------------------------------------*/
  48. /* Exported types ------------------------------------------------------------*/
  49. #if defined(USE_FULL_LL_DRIVER)
  50. /** @defgroup SPI_LL_ES_INIT SPI Exported Init structure
  51. * @{
  52. */
  53. /**
  54. * @brief SPI Init structures definition
  55. */
  56. typedef struct
  57. {
  58. uint32_t TransferDirection; /*!< Specifies the SPI unidirectional or bidirectional data mode.
  59. This parameter can be a value of @ref SPI_LL_EC_TRANSFER_MODE.
  60. This feature can be modified afterwards using unitary function @ref LL_SPI_SetTransferDirection().*/
  61. uint32_t Mode; /*!< Specifies the SPI mode (Master/Slave).
  62. This parameter can be a value of @ref SPI_LL_EC_MODE.
  63. This feature can be modified afterwards using unitary function @ref LL_SPI_SetMode().*/
  64. uint32_t DataWidth; /*!< Specifies the SPI data width.
  65. This parameter can be a value of @ref SPI_LL_EC_DATAWIDTH.
  66. This feature can be modified afterwards using unitary function @ref LL_SPI_SetDataWidth().*/
  67. uint32_t ClockPolarity; /*!< Specifies the serial clock steady state.
  68. This parameter can be a value of @ref SPI_LL_EC_POLARITY.
  69. This feature can be modified afterwards using unitary function @ref LL_SPI_SetClockPolarity().*/
  70. uint32_t ClockPhase; /*!< Specifies the clock active edge for the bit capture.
  71. This parameter can be a value of @ref SPI_LL_EC_PHASE.
  72. This feature can be modified afterwards using unitary function @ref LL_SPI_SetClockPhase().*/
  73. uint32_t NSS; /*!< Specifies whether the NSS signal is managed by hardware (NSS pin) or by software using the SSI bit.
  74. This parameter can be a value of @ref SPI_LL_EC_NSS_MODE.
  75. This feature can be modified afterwards using unitary function @ref LL_SPI_SetNSSMode().*/
  76. uint32_t BaudRate; /*!< Specifies the BaudRate prescaler value which will be used to configure the transmit and receive SCK clock.
  77. This parameter can be a value of @ref SPI_LL_EC_BAUDRATEPRESCALER.
  78. @note The communication clock is derived from the master clock. The slave clock does not need to be set.
  79. This feature can be modified afterwards using unitary function @ref LL_SPI_SetBaudRatePrescaler().*/
  80. uint32_t BitOrder; /*!< Specifies whether data transfers start from MSB or LSB bit.
  81. This parameter can be a value of @ref SPI_LL_EC_BIT_ORDER.
  82. This feature can be modified afterwards using unitary function @ref LL_SPI_SetTransferBitOrder().*/
  83. uint32_t SlaveSpeedMode; /*!< Specifies the Slave speed mode.
  84. This parameter can be a value of @ref SPI_LL_EC_SLAVE_SPEED_MODE */
  85. } LL_SPI_InitTypeDef;
  86. /**
  87. * @}
  88. */
  89. #endif /* USE_FULL_LL_DRIVER */
  90. /* Exported constants --------------------------------------------------------*/
  91. /** @defgroup SPI_LL_Exported_Constants SPI Exported Constants
  92. * @{
  93. */
  94. /** @defgroup SPI_LL_EC_GET_FLAG Get Flags Defines
  95. * @brief Flags defines which can be used with LL_SPI_ReadReg function
  96. * @{
  97. */
  98. #define LL_SPI_SR_RXNE SPI_SR_RXNE /*!< Rx buffer not empty flag */
  99. #define LL_SPI_SR_TXE SPI_SR_TXE /*!< Tx buffer empty flag */
  100. #define LL_SPI_SR_BSY SPI_SR_BSY /*!< Busy flag */
  101. #define LL_SPI_SR_MODF SPI_SR_MODF /*!< Mode fault flag */
  102. #define LL_SPI_SR_OVR SPI_SR_OVR /*!< Overrun flag */
  103. /**
  104. * @}
  105. */
  106. /** @defgroup SPI_LL_EC_IT IT Defines
  107. * @brief IT defines which can be used with LL_SPI_ReadReg and LL_SPI_WriteReg functions
  108. * @{
  109. */
  110. #define LL_SPI_CR2_RXNEIE SPI_CR2_RXNEIE /*!< Rx buffer not empty interrupt enable */
  111. #define LL_SPI_CR2_TXEIE SPI_CR2_TXEIE /*!< Tx buffer empty interrupt enable */
  112. #define LL_SPI_CR2_ERRIE SPI_CR2_ERRIE /*!< Error interrupt enable */
  113. /**
  114. * @}
  115. */
  116. /** @defgroup SPI_LL_EC_MODE Operation Mode
  117. * @{
  118. */
  119. #define LL_SPI_MODE_MASTER (SPI_CR1_MSTR | SPI_CR1_SSI) /*!< Master configuration */
  120. #define LL_SPI_MODE_SLAVE 0x00000000U /*!< Slave configuration */
  121. /**
  122. * @}
  123. */
  124. /** @defgroup SPI_LL_EC_PHASE Clock Phase
  125. * @{
  126. */
  127. #define LL_SPI_PHASE_1EDGE 0x00000000U /*!< First clock transition is the first data capture edge */
  128. #define LL_SPI_PHASE_2EDGE (SPI_CR1_CPHA) /*!< Second clock transition is the first data capture edge */
  129. /**
  130. * @}
  131. */
  132. /** @defgroup SPI_LL_EC_POLARITY Clock Polarity
  133. * @{
  134. */
  135. #define LL_SPI_POLARITY_LOW 0x00000000U /*!< Clock to 0 when idle */
  136. #define LL_SPI_POLARITY_HIGH (SPI_CR1_CPOL) /*!< Clock to 1 when idle */
  137. /**
  138. * @}
  139. */
  140. /** @defgroup SPI_LL_EC_BAUDRATEPRESCALER Baud Rate Prescaler
  141. * @{
  142. */
  143. #define LL_SPI_BAUDRATEPRESCALER_DIV2 0x00000000U /*!< BaudRate control equal to fPCLK/2 */
  144. #define LL_SPI_BAUDRATEPRESCALER_DIV4 (SPI_CR1_BR_0) /*!< BaudRate control equal to fPCLK/4 */
  145. #define LL_SPI_BAUDRATEPRESCALER_DIV8 (SPI_CR1_BR_1) /*!< BaudRate control equal to fPCLK/8 */
  146. #define LL_SPI_BAUDRATEPRESCALER_DIV16 (SPI_CR1_BR_1 | SPI_CR1_BR_0) /*!< BaudRate control equal to fPCLK/16 */
  147. #define LL_SPI_BAUDRATEPRESCALER_DIV32 (SPI_CR1_BR_2) /*!< BaudRate control equal to fPCLK/32 */
  148. #define LL_SPI_BAUDRATEPRESCALER_DIV64 (SPI_CR1_BR_2 | SPI_CR1_BR_0) /*!< BaudRate control equal to fPCLK/64 */
  149. #define LL_SPI_BAUDRATEPRESCALER_DIV128 (SPI_CR1_BR_2 | SPI_CR1_BR_1) /*!< BaudRate control equal to fPCLK/128 */
  150. #define LL_SPI_BAUDRATEPRESCALER_DIV256 (SPI_CR1_BR_2 | SPI_CR1_BR_1 | SPI_CR1_BR_0) /*!< BaudRate control equal to fPCLK/256 */
  151. /**
  152. * @}
  153. */
  154. /** @defgroup SPI_LL_EC_BIT_ORDER Transmission Bit Order
  155. * @{
  156. */
  157. #define LL_SPI_LSB_FIRST (SPI_CR1_LSBFIRST) /*!< Data is transmitted/received with the LSB first */
  158. #define LL_SPI_MSB_FIRST 0x00000000U /*!< Data is transmitted/received with the MSB first */
  159. /**
  160. * @}
  161. */
  162. /** @defgroup SPI_LL_EC_TRANSFER_MODE Transfer Mode
  163. * @{
  164. */
  165. #define LL_SPI_FULL_DUPLEX 0x00000000U /*!< Full-duplex communication or Simplex communication Transmit-only mode */
  166. #define LL_SPI_SIMPLEX_RX (SPI_CR1_RXONLY) /*!< Simplex communication Receive-only mode */
  167. #define LL_SPI_HALF_DUPLEX_RX (SPI_CR1_BIDIMODE) /*!< Half-duplex communication Rx mode */
  168. #define LL_SPI_HALF_DUPLEX_TX (SPI_CR1_BIDIMODE | SPI_CR1_BIDIOE) /*!< Half-duplex communication Tx mode */
  169. /**
  170. * @}
  171. */
  172. /** @defgroup SPI_LL_EC_NSS_MODE Slave Select Pin Mode
  173. * @{
  174. */
  175. #define LL_SPI_NSS_SOFT (SPI_CR1_SSM) /*!< NSS managed internally. NSS pin not used and free */
  176. #define LL_SPI_NSS_HARD_INPUT 0x00000000U /*!< NSS pin used in Input. Only used in Master mode */
  177. #define LL_SPI_NSS_HARD_OUTPUT (((uint32_t)SPI_CR2_SSOE << 16U)) /*!< NSS pin used in Output. Only used in Slave mode as chip select */
  178. /**
  179. * @}
  180. */
  181. /** @defgroup SPI_LL_EC_DATAWIDTH Datawidth
  182. * @{
  183. */
  184. #define LL_SPI_DATAWIDTH_8BIT 0x0 /*!< Data length for SPI transfer: 8 bits */
  185. #define LL_SPI_DATAWIDTH_16BIT (SPI_CR2_DS) /*!< Data length for SPI transfer: 16 bits */
  186. /**
  187. * @}
  188. */
  189. #if defined(USE_FULL_LL_DRIVER)
  190. #endif /* USE_FULL_LL_DRIVER */
  191. /** @defgroup SPI_LL_EC_RX_FIFO_TH RX FIFO Threshold
  192. * @{
  193. */
  194. #define LL_SPI_RX_FIFO_TH_HALF 0x00000000U /*!< RXNE event is generated if FIFO level is greater than or equal to 1/2 (16-bit) */
  195. #define LL_SPI_RX_FIFO_TH_QUARTER (SPI_CR2_FRXTH) /*!< RXNE event is generated if FIFO level is greater than or equal to 1/4 (8-bit) */
  196. /**
  197. * @}
  198. */
  199. /** @defgroup SPI_LL_EC_RX_FIFO RX FIFO Level
  200. * @{
  201. */
  202. #define LL_SPI_RX_FIFO_EMPTY 0x00000000U /*!< FIFO reception empty */
  203. #define LL_SPI_RX_FIFO_QUARTER_FULL (SPI_SR_FRLVL_0) /*!< FIFO reception 1/4 */
  204. #define LL_SPI_RX_FIFO_HALF_FULL (SPI_SR_FRLVL_1) /*!< FIFO reception 1/2 */
  205. #define LL_SPI_RX_FIFO_FULL (SPI_SR_FRLVL_1 | SPI_SR_FRLVL_0) /*!< FIFO reception full */
  206. /**
  207. * @}
  208. */
  209. /** @defgroup SPI_LL_EC_TX_FIFO TX FIFO Level
  210. * @{
  211. */
  212. #define LL_SPI_TX_FIFO_EMPTY 0x00000000U /*!< FIFO transmission empty */
  213. #define LL_SPI_TX_FIFO_QUARTER_FULL (SPI_SR_FTLVL_0) /*!< FIFO transmission 1/4 */
  214. #define LL_SPI_TX_FIFO_HALF_FULL (SPI_SR_FTLVL_1) /*!< FIFO transmission 1/2 */
  215. #define LL_SPI_TX_FIFO_FULL (SPI_SR_FTLVL_1 | SPI_SR_FTLVL_0) /*!< FIFO transmission full */
  216. /**
  217. * @}
  218. */
  219. #if (defined(DMA1) || defined(DMA))
  220. /** @defgroup SPI_LL_EC_DMA_PARITY DMA Parity
  221. * @{
  222. */
  223. #define LL_SPI_DMA_PARITY_EVEN 0x00000000U /*!< Select DMA parity Even */
  224. #define LL_SPI_DMA_PARITY_ODD 0x00000001U /*!< Select DMA parity Odd */
  225. /**
  226. * @}
  227. */
  228. #endif /* DMA1 or DMA */
  229. /** @defgroup SPI_LL_EC_SLAVE_SPEED_MODE SLAVE SPEED MODE
  230. * @{
  231. */
  232. #define LL_SPI_SLAVE_SPEED_NORMAL 0x00000000U /* Slave normal mode */
  233. #define LL_SPI_SLAVE_SPEED_FAST SPI_CR2_SLVFM /* Slave fast mode */
  234. /**
  235. * @}
  236. */
  237. /**
  238. * @}
  239. */
  240. /* Exported macro ------------------------------------------------------------*/
  241. /** @defgroup SPI_LL_Exported_Macros SPI Exported Macros
  242. * @{
  243. */
  244. /** @defgroup SPI_LL_EM_WRITE_READ Common Write and read registers Macros
  245. * @{
  246. */
  247. /**
  248. * @brief Write a value in SPI register
  249. * @param __INSTANCE__ SPI Instance
  250. * @param __REG__ Register to be written
  251. * @param __VALUE__ Value to be written in the register
  252. * @retval None
  253. */
  254. #define LL_SPI_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
  255. /**
  256. * @brief Read a value in SPI register
  257. * @param __INSTANCE__ SPI Instance
  258. * @param __REG__ Register to be read
  259. * @retval Register value
  260. */
  261. #define LL_SPI_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
  262. /**
  263. * @}
  264. */
  265. /**
  266. * @}
  267. */
  268. /* Exported functions --------------------------------------------------------*/
  269. /** @defgroup SPI_LL_Exported_Functions SPI Exported Functions
  270. * @{
  271. */
  272. /** @defgroup SPI_LL_EF_Configuration Configuration
  273. * @{
  274. */
  275. /**
  276. * @brief Enable SPI peripheral
  277. * @rmtoll CR1 SPE LL_SPI_Enable
  278. * @param SPIx SPI Instance
  279. * @retval None
  280. */
  281. __STATIC_INLINE void LL_SPI_Enable(SPI_TypeDef *SPIx)
  282. {
  283. SET_BIT(SPIx->CR1, SPI_CR1_SPE);
  284. }
  285. /**
  286. * @brief Disable SPI peripheral
  287. * @note When disabling the SPI, follow the procedure described in the Reference Manual.
  288. * @rmtoll CR1 SPE LL_SPI_Disable
  289. * @param SPIx SPI Instance
  290. * @retval None
  291. */
  292. __STATIC_INLINE void LL_SPI_Disable(SPI_TypeDef *SPIx)
  293. {
  294. CLEAR_BIT(SPIx->CR1, SPI_CR1_SPE);
  295. }
  296. /**
  297. * @brief Check if SPI peripheral is enabled
  298. * @rmtoll CR1 SPE LL_SPI_IsEnabled
  299. * @param SPIx SPI Instance
  300. * @retval State of bit (1 or 0).
  301. */
  302. __STATIC_INLINE uint32_t LL_SPI_IsEnabled(SPI_TypeDef *SPIx)
  303. {
  304. return ((READ_BIT(SPIx->CR1, SPI_CR1_SPE) == (SPI_CR1_SPE)) ? 1UL : 0UL);
  305. }
  306. /**
  307. * @brief Set SPI operation mode to Master or Slave
  308. * @note This bit should not be changed when communication is ongoing.
  309. * @rmtoll CR1 MSTR LL_SPI_SetMode\n
  310. * CR1 SSI LL_SPI_SetMode
  311. * @param SPIx SPI Instance
  312. * @param Mode This parameter can be one of the following values:
  313. * @arg @ref LL_SPI_MODE_MASTER
  314. * @arg @ref LL_SPI_MODE_SLAVE
  315. * @retval None
  316. */
  317. __STATIC_INLINE void LL_SPI_SetMode(SPI_TypeDef *SPIx, uint32_t Mode)
  318. {
  319. MODIFY_REG(SPIx->CR1, SPI_CR1_MSTR | SPI_CR1_SSI, Mode);
  320. }
  321. /**
  322. * @brief Get SPI operation mode (Master or Slave)
  323. * @rmtoll CR1 MSTR LL_SPI_GetMode\n
  324. * CR1 SSI LL_SPI_GetMode
  325. * @param SPIx SPI Instance
  326. * @retval Returned value can be one of the following values:
  327. * @arg @ref LL_SPI_MODE_MASTER
  328. * @arg @ref LL_SPI_MODE_SLAVE
  329. */
  330. __STATIC_INLINE uint32_t LL_SPI_GetMode(SPI_TypeDef *SPIx)
  331. {
  332. return (uint32_t)(READ_BIT(SPIx->CR1, SPI_CR1_MSTR | SPI_CR1_SSI));
  333. }
  334. /**
  335. * @brief Set clock phase
  336. * @note This bit should not be changed when communication is ongoing.
  337. * This bit is not used in SPI TI mode.
  338. * @rmtoll CR1 CPHA LL_SPI_SetClockPhase
  339. * @param SPIx SPI Instance
  340. * @param ClockPhase This parameter can be one of the following values:
  341. * @arg @ref LL_SPI_PHASE_1EDGE
  342. * @arg @ref LL_SPI_PHASE_2EDGE
  343. * @retval None
  344. */
  345. __STATIC_INLINE void LL_SPI_SetClockPhase(SPI_TypeDef *SPIx, uint32_t ClockPhase)
  346. {
  347. MODIFY_REG(SPIx->CR1, SPI_CR1_CPHA, ClockPhase);
  348. }
  349. /**
  350. * @brief Get clock phase
  351. * @rmtoll CR1 CPHA LL_SPI_GetClockPhase
  352. * @param SPIx SPI Instance
  353. * @retval Returned value can be one of the following values:
  354. * @arg @ref LL_SPI_PHASE_1EDGE
  355. * @arg @ref LL_SPI_PHASE_2EDGE
  356. */
  357. __STATIC_INLINE uint32_t LL_SPI_GetClockPhase(SPI_TypeDef *SPIx)
  358. {
  359. return (uint32_t)(READ_BIT(SPIx->CR1, SPI_CR1_CPHA));
  360. }
  361. /**
  362. * @brief Set clock polarity
  363. * @note This bit should not be changed when communication is ongoing.
  364. * This bit is not used in SPI TI mode.
  365. * @rmtoll CR1 CPOL LL_SPI_SetClockPolarity
  366. * @param SPIx SPI Instance
  367. * @param ClockPolarity This parameter can be one of the following values:
  368. * @arg @ref LL_SPI_POLARITY_LOW
  369. * @arg @ref LL_SPI_POLARITY_HIGH
  370. * @retval None
  371. */
  372. __STATIC_INLINE void LL_SPI_SetClockPolarity(SPI_TypeDef *SPIx, uint32_t ClockPolarity)
  373. {
  374. MODIFY_REG(SPIx->CR1, SPI_CR1_CPOL, ClockPolarity);
  375. }
  376. /**
  377. * @brief Get clock polarity
  378. * @rmtoll CR1 CPOL LL_SPI_GetClockPolarity
  379. * @param SPIx SPI Instance
  380. * @retval Returned value can be one of the following values:
  381. * @arg @ref LL_SPI_POLARITY_LOW
  382. * @arg @ref LL_SPI_POLARITY_HIGH
  383. */
  384. __STATIC_INLINE uint32_t LL_SPI_GetClockPolarity(SPI_TypeDef *SPIx)
  385. {
  386. return (uint32_t)(READ_BIT(SPIx->CR1, SPI_CR1_CPOL));
  387. }
  388. /**
  389. * @brief Set baud rate prescaler
  390. * @note These bits should not be changed when communication is ongoing. SPI BaudRate = fPCLK/Prescaler.
  391. * @rmtoll CR1 BR LL_SPI_SetBaudRatePrescaler
  392. * @param SPIx SPI Instance
  393. * @param BaudRate This parameter can be one of the following values:
  394. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV2
  395. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV4
  396. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV8
  397. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV16
  398. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV32
  399. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV64
  400. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV128
  401. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV256
  402. * @retval None
  403. */
  404. __STATIC_INLINE void LL_SPI_SetBaudRatePrescaler(SPI_TypeDef *SPIx, uint32_t BaudRate)
  405. {
  406. MODIFY_REG(SPIx->CR1, SPI_CR1_BR, BaudRate);
  407. }
  408. /**
  409. * @brief Get baud rate prescaler
  410. * @rmtoll CR1 BR LL_SPI_GetBaudRatePrescaler
  411. * @param SPIx SPI Instance
  412. * @retval Returned value can be one of the following values:
  413. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV2
  414. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV4
  415. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV8
  416. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV16
  417. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV32
  418. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV64
  419. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV128
  420. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV256
  421. */
  422. __STATIC_INLINE uint32_t LL_SPI_GetBaudRatePrescaler(SPI_TypeDef *SPIx)
  423. {
  424. return (uint32_t)(READ_BIT(SPIx->CR1, SPI_CR1_BR));
  425. }
  426. /**
  427. * @brief Set transfer bit order
  428. * @note This bit should not be changed when communication is ongoing. This bit is not used in SPI TI mode.
  429. * @rmtoll CR1 LSBFIRST LL_SPI_SetTransferBitOrder
  430. * @param SPIx SPI Instance
  431. * @param BitOrder This parameter can be one of the following values:
  432. * @arg @ref LL_SPI_LSB_FIRST
  433. * @arg @ref LL_SPI_MSB_FIRST
  434. * @retval None
  435. */
  436. __STATIC_INLINE void LL_SPI_SetTransferBitOrder(SPI_TypeDef *SPIx, uint32_t BitOrder)
  437. {
  438. MODIFY_REG(SPIx->CR1, SPI_CR1_LSBFIRST, BitOrder);
  439. }
  440. /**
  441. * @brief Get transfer bit order
  442. * @rmtoll CR1 LSBFIRST LL_SPI_GetTransferBitOrder
  443. * @param SPIx SPI Instance
  444. * @retval Returned value can be one of the following values:
  445. * @arg @ref LL_SPI_LSB_FIRST
  446. * @arg @ref LL_SPI_MSB_FIRST
  447. */
  448. __STATIC_INLINE uint32_t LL_SPI_GetTransferBitOrder(SPI_TypeDef *SPIx)
  449. {
  450. return (uint32_t)(READ_BIT(SPIx->CR1, SPI_CR1_LSBFIRST));
  451. }
  452. /**
  453. * @brief Set transfer direction mode
  454. * @note For Half-Duplex mode, Rx Direction is set by default.
  455. * In master mode, the MOSI pin is used and in slave mode, the MISO pin is used for Half-Duplex.
  456. * @rmtoll CR1 RXONLY LL_SPI_SetTransferDirection\n
  457. * CR1 BIDIMODE LL_SPI_SetTransferDirection\n
  458. * CR1 BIDIOE LL_SPI_SetTransferDirection
  459. * @param SPIx SPI Instance
  460. * @param TransferDirection This parameter can be one of the following values:
  461. * @arg @ref LL_SPI_FULL_DUPLEX
  462. * @arg @ref LL_SPI_SIMPLEX_RX
  463. * @arg @ref LL_SPI_HALF_DUPLEX_RX
  464. * @arg @ref LL_SPI_HALF_DUPLEX_TX
  465. * @retval None
  466. */
  467. __STATIC_INLINE void LL_SPI_SetTransferDirection(SPI_TypeDef *SPIx, uint32_t TransferDirection)
  468. {
  469. MODIFY_REG(SPIx->CR1, SPI_CR1_RXONLY | SPI_CR1_BIDIMODE | SPI_CR1_BIDIOE, TransferDirection);
  470. }
  471. /**
  472. * @brief Get transfer direction mode
  473. * @rmtoll CR1 RXONLY LL_SPI_GetTransferDirection\n
  474. * CR1 BIDIMODE LL_SPI_GetTransferDirection\n
  475. * CR1 BIDIOE LL_SPI_GetTransferDirection
  476. * @param SPIx SPI Instance
  477. * @retval Returned value can be one of the following values:
  478. * @arg @ref LL_SPI_FULL_DUPLEX
  479. * @arg @ref LL_SPI_SIMPLEX_RX
  480. * @arg @ref LL_SPI_HALF_DUPLEX_RX
  481. * @arg @ref LL_SPI_HALF_DUPLEX_TX
  482. */
  483. __STATIC_INLINE uint32_t LL_SPI_GetTransferDirection(SPI_TypeDef *SPIx)
  484. {
  485. return (uint32_t)(READ_BIT(SPIx->CR1, SPI_CR1_RXONLY | SPI_CR1_BIDIMODE | SPI_CR1_BIDIOE));
  486. }
  487. /**
  488. * @brief Set frame data width
  489. * @rmtoll CR2 DS LL_SPI_SetDataWidth
  490. * @param SPIx SPI Instance
  491. * @param DataWidth This parameter can be one of the following values:
  492. * @arg @ref LL_SPI_DATAWIDTH_8BIT
  493. * @arg @ref LL_SPI_DATAWIDTH_16BIT
  494. * @retval None
  495. */
  496. __STATIC_INLINE void LL_SPI_SetDataWidth(SPI_TypeDef *SPIx, uint32_t DataWidth)
  497. {
  498. MODIFY_REG(SPIx->CR2, SPI_CR2_DS, DataWidth);
  499. }
  500. /**
  501. * @brief Get frame data width
  502. * @rmtoll CR2 DS LL_SPI_GetDataWidth
  503. * @param SPIx SPI Instance
  504. * @retval Returned value can be one of the following values:
  505. * @arg @ref LL_SPI_DATAWIDTH_8BIT
  506. * @arg @ref LL_SPI_DATAWIDTH_16BIT
  507. */
  508. __STATIC_INLINE uint32_t LL_SPI_GetDataWidth(SPI_TypeDef *SPIx)
  509. {
  510. return (uint32_t)(READ_BIT(SPIx->CR2, SPI_CR2_DS));
  511. }
  512. /**
  513. * @brief Set threshold of RXFIFO that triggers an RXNE event
  514. * @rmtoll CR2 FRXTH LL_SPI_SetRxFIFOThreshold
  515. * @param SPIx SPI Instance
  516. * @param Threshold This parameter can be one of the following values:
  517. * @arg @ref LL_SPI_RX_FIFO_TH_HALF
  518. * @arg @ref LL_SPI_RX_FIFO_TH_QUARTER
  519. * @retval None
  520. */
  521. __STATIC_INLINE void LL_SPI_SetRxFIFOThreshold(SPI_TypeDef *SPIx, uint32_t Threshold)
  522. {
  523. MODIFY_REG(SPIx->CR2, SPI_CR2_FRXTH, Threshold);
  524. }
  525. /**
  526. * @brief Get threshold of RXFIFO that triggers an RXNE event
  527. * @rmtoll CR2 FRXTH LL_SPI_GetRxFIFOThreshold
  528. * @param SPIx SPI Instance
  529. * @retval Returned value can be one of the following values:
  530. * @arg @ref LL_SPI_RX_FIFO_TH_HALF
  531. * @arg @ref LL_SPI_RX_FIFO_TH_QUARTER
  532. */
  533. __STATIC_INLINE uint32_t LL_SPI_GetRxFIFOThreshold(SPI_TypeDef *SPIx)
  534. {
  535. return (uint32_t)(READ_BIT(SPIx->CR2, SPI_CR2_FRXTH));
  536. }
  537. /**
  538. * @}
  539. */
  540. /** @defgroup SPI_LL_EF_NSS_Management Slave Select Pin Management
  541. * @{
  542. */
  543. /**
  544. * @brief Set NSS mode
  545. * @rmtoll CR1 SSM LL_SPI_SetNSSMode\n
  546. * @rmtoll CR2 SSOE LL_SPI_SetNSSMode
  547. * @param SPIx SPI Instance
  548. * @param NSS This parameter can be one of the following values:
  549. * @arg @ref LL_SPI_NSS_SOFT
  550. * @arg @ref LL_SPI_NSS_HARD_INPUT
  551. * @arg @ref LL_SPI_NSS_HARD_OUTPUT
  552. * @retval None
  553. */
  554. __STATIC_INLINE void LL_SPI_SetNSSMode(SPI_TypeDef *SPIx, uint32_t NSS)
  555. {
  556. MODIFY_REG(SPIx->CR1, SPI_CR1_SSM, NSS);
  557. MODIFY_REG(SPIx->CR2, SPI_CR2_SSOE, ((uint32_t)(NSS >> 16U)));
  558. }
  559. /**
  560. * @brief Get NSS mode
  561. * @rmtoll CR1 SSM LL_SPI_GetNSSMode\n
  562. * @rmtoll CR2 SSOE LL_SPI_GetNSSMode
  563. * @param SPIx SPI Instance
  564. * @retval Returned value can be one of the following values:
  565. * @arg @ref LL_SPI_NSS_SOFT
  566. * @arg @ref LL_SPI_NSS_HARD_INPUT
  567. * @arg @ref LL_SPI_NSS_HARD_OUTPUT
  568. */
  569. __STATIC_INLINE uint32_t LL_SPI_GetNSSMode(SPI_TypeDef *SPIx)
  570. {
  571. uint32_t Ssm = (READ_BIT(SPIx->CR1, SPI_CR1_SSM));
  572. uint32_t Ssoe = (READ_BIT(SPIx->CR2, SPI_CR2_SSOE) << 16U);
  573. return (Ssm | Ssoe);
  574. }
  575. /**
  576. * @}
  577. */
  578. /** @defgroup SPI_LL_EF_FLAG_Management FLAG Management
  579. * @{
  580. */
  581. /**
  582. * @brief Check if Rx buffer is not empty
  583. * @rmtoll SR RXNE LL_SPI_IsActiveFlag_RXNE
  584. * @param SPIx SPI Instance
  585. * @retval State of bit (1 or 0).
  586. */
  587. __STATIC_INLINE uint32_t LL_SPI_IsActiveFlag_RXNE(SPI_TypeDef *SPIx)
  588. {
  589. return ((READ_BIT(SPIx->SR, SPI_SR_RXNE) == (SPI_SR_RXNE)) ? 1UL : 0UL);
  590. }
  591. /**
  592. * @brief Check if Tx buffer is empty
  593. * @rmtoll SR TXE LL_SPI_IsActiveFlag_TXE
  594. * @param SPIx SPI Instance
  595. * @retval State of bit (1 or 0).
  596. */
  597. __STATIC_INLINE uint32_t LL_SPI_IsActiveFlag_TXE(SPI_TypeDef *SPIx)
  598. {
  599. return ((READ_BIT(SPIx->SR, SPI_SR_TXE) == (SPI_SR_TXE)) ? 1UL : 0UL);
  600. }
  601. /**
  602. * @brief Get mode fault error flag
  603. * @rmtoll SR MODF LL_SPI_IsActiveFlag_MODF
  604. * @param SPIx SPI Instance
  605. * @retval State of bit (1 or 0).
  606. */
  607. __STATIC_INLINE uint32_t LL_SPI_IsActiveFlag_MODF(SPI_TypeDef *SPIx)
  608. {
  609. return ((READ_BIT(SPIx->SR, SPI_SR_MODF) == (SPI_SR_MODF)) ? 1UL : 0UL);
  610. }
  611. /**
  612. * @brief Get overrun error flag
  613. * @rmtoll SR OVR LL_SPI_IsActiveFlag_OVR
  614. * @param SPIx SPI Instance
  615. * @retval State of bit (1 or 0).
  616. */
  617. __STATIC_INLINE uint32_t LL_SPI_IsActiveFlag_OVR(SPI_TypeDef *SPIx)
  618. {
  619. return ((READ_BIT(SPIx->SR, SPI_SR_OVR) == (SPI_SR_OVR)) ? 1UL : 0UL);
  620. }
  621. /**
  622. * @brief Get busy flag
  623. * @note The BSY flag is cleared under any one of the following conditions:
  624. * -When the SPI is correctly disabled
  625. * -When a fault is detected in Master mode (MODF bit set to 1)
  626. * -In Master mode, when it finishes a data transmission and no new data is ready to be
  627. * sent
  628. * -In Slave mode, when the BSY flag is set to '0' for at least one SPI clock cycle between
  629. * each data transfer.
  630. * @rmtoll SR BSY LL_SPI_IsActiveFlag_BSY
  631. * @param SPIx SPI Instance
  632. * @retval State of bit (1 or 0).
  633. */
  634. __STATIC_INLINE uint32_t LL_SPI_IsActiveFlag_BSY(SPI_TypeDef *SPIx)
  635. {
  636. return ((READ_BIT(SPIx->SR, SPI_SR_BSY) == (SPI_SR_BSY)) ? 1UL : 0UL);
  637. }
  638. /**
  639. * @brief Get FIFO reception Level
  640. * @rmtoll SR FRLVL LL_SPI_GetRxFIFOLevel
  641. * @param SPIx SPI Instance
  642. * @retval Returned value can be one of the following values:
  643. * @arg @ref LL_SPI_RX_FIFO_EMPTY
  644. * @arg @ref LL_SPI_RX_FIFO_QUARTER_FULL
  645. * @arg @ref LL_SPI_RX_FIFO_HALF_FULL
  646. * @arg @ref LL_SPI_RX_FIFO_FULL
  647. */
  648. __STATIC_INLINE uint32_t LL_SPI_GetRxFIFOLevel(SPI_TypeDef *SPIx)
  649. {
  650. return (uint32_t)(READ_BIT(SPIx->SR, SPI_SR_FRLVL));
  651. }
  652. /**
  653. * @brief Get FIFO Transmission Level
  654. * @rmtoll SR FTLVL LL_SPI_GetTxFIFOLevel
  655. * @param SPIx SPI Instance
  656. * @retval Returned value can be one of the following values:
  657. * @arg @ref LL_SPI_TX_FIFO_EMPTY
  658. * @arg @ref LL_SPI_TX_FIFO_QUARTER_FULL
  659. * @arg @ref LL_SPI_TX_FIFO_HALF_FULL
  660. * @arg @ref LL_SPI_TX_FIFO_FULL
  661. */
  662. __STATIC_INLINE uint32_t LL_SPI_GetTxFIFOLevel(SPI_TypeDef *SPIx)
  663. {
  664. return (uint32_t)(READ_BIT(SPIx->SR, SPI_SR_FTLVL));
  665. }
  666. /**
  667. * @brief Clear mode fault error flag
  668. * @note Clearing this flag is done by a read access to the SPIx_SR
  669. * register followed by a write access to the SPIx_CR1 register
  670. * @rmtoll SR MODF LL_SPI_ClearFlag_MODF
  671. * @param SPIx SPI Instance
  672. * @retval None
  673. */
  674. __STATIC_INLINE void LL_SPI_ClearFlag_MODF(SPI_TypeDef *SPIx)
  675. {
  676. __IO uint32_t tmpreg_sr;
  677. tmpreg_sr = SPIx->SR;
  678. (void) tmpreg_sr;
  679. CLEAR_BIT(SPIx->CR1, SPI_CR1_SPE);
  680. }
  681. /**
  682. * @brief Clear overrun error flag
  683. * @note Clearing this flag is done by a read access to the SPIx_DR
  684. * register followed by a read access to the SPIx_SR register
  685. * @rmtoll SR OVR LL_SPI_ClearFlag_OVR
  686. * @param SPIx SPI Instance
  687. * @retval None
  688. */
  689. __STATIC_INLINE void LL_SPI_ClearFlag_OVR(SPI_TypeDef *SPIx)
  690. {
  691. __IO uint32_t tmpreg;
  692. tmpreg = SPIx->DR;
  693. (void) tmpreg;
  694. tmpreg = SPIx->SR;
  695. (void) tmpreg;
  696. }
  697. /**
  698. * @}
  699. */
  700. /** @defgroup SPI_LL_EF_IT_Management Interrupt Management
  701. * @{
  702. */
  703. /**
  704. * @brief Enable error interrupt
  705. * @note This bit controls the generation of an interrupt when an error condition occurs (CRCERR, OVR, MODF in SPI mode, FRE at TI mode).
  706. * @rmtoll CR2 ERRIE LL_SPI_EnableIT_ERR
  707. * @param SPIx SPI Instance
  708. * @retval None
  709. */
  710. __STATIC_INLINE void LL_SPI_EnableIT_ERR(SPI_TypeDef *SPIx)
  711. {
  712. SET_BIT(SPIx->CR2, SPI_CR2_ERRIE);
  713. }
  714. /**
  715. * @brief Enable Rx buffer not empty interrupt
  716. * @rmtoll CR2 RXNEIE LL_SPI_EnableIT_RXNE
  717. * @param SPIx SPI Instance
  718. * @retval None
  719. */
  720. __STATIC_INLINE void LL_SPI_EnableIT_RXNE(SPI_TypeDef *SPIx)
  721. {
  722. SET_BIT(SPIx->CR2, SPI_CR2_RXNEIE);
  723. }
  724. /**
  725. * @brief Enable Tx buffer empty interrupt
  726. * @rmtoll CR2 TXEIE LL_SPI_EnableIT_TXE
  727. * @param SPIx SPI Instance
  728. * @retval None
  729. */
  730. __STATIC_INLINE void LL_SPI_EnableIT_TXE(SPI_TypeDef *SPIx)
  731. {
  732. SET_BIT(SPIx->CR2, SPI_CR2_TXEIE);
  733. }
  734. /**
  735. * @brief Disable error interrupt
  736. * @note This bit controls the generation of an interrupt when an error condition occurs (CRCERR, OVR, MODF in SPI mode, FRE at TI mode).
  737. * @rmtoll CR2 ERRIE LL_SPI_DisableIT_ERR
  738. * @param SPIx SPI Instance
  739. * @retval None
  740. */
  741. __STATIC_INLINE void LL_SPI_DisableIT_ERR(SPI_TypeDef *SPIx)
  742. {
  743. CLEAR_BIT(SPIx->CR2, SPI_CR2_ERRIE);
  744. }
  745. /**
  746. * @brief Disable Rx buffer not empty interrupt
  747. * @rmtoll CR2 RXNEIE LL_SPI_DisableIT_RXNE
  748. * @param SPIx SPI Instance
  749. * @retval None
  750. */
  751. __STATIC_INLINE void LL_SPI_DisableIT_RXNE(SPI_TypeDef *SPIx)
  752. {
  753. CLEAR_BIT(SPIx->CR2, SPI_CR2_RXNEIE);
  754. }
  755. /**
  756. * @brief Disable Tx buffer empty interrupt
  757. * @rmtoll CR2 TXEIE LL_SPI_DisableIT_TXE
  758. * @param SPIx SPI Instance
  759. * @retval None
  760. */
  761. __STATIC_INLINE void LL_SPI_DisableIT_TXE(SPI_TypeDef *SPIx)
  762. {
  763. CLEAR_BIT(SPIx->CR2, SPI_CR2_TXEIE);
  764. }
  765. /**
  766. * @brief Check if error interrupt is enabled
  767. * @rmtoll CR2 ERRIE LL_SPI_IsEnabledIT_ERR
  768. * @param SPIx SPI Instance
  769. * @retval State of bit (1 or 0).
  770. */
  771. __STATIC_INLINE uint32_t LL_SPI_IsEnabledIT_ERR(SPI_TypeDef *SPIx)
  772. {
  773. return ((READ_BIT(SPIx->CR2, SPI_CR2_ERRIE) == (SPI_CR2_ERRIE)) ? 1UL : 0UL);
  774. }
  775. /**
  776. * @brief Check if Rx buffer not empty interrupt is enabled
  777. * @rmtoll CR2 RXNEIE LL_SPI_IsEnabledIT_RXNE
  778. * @param SPIx SPI Instance
  779. * @retval State of bit (1 or 0).
  780. */
  781. __STATIC_INLINE uint32_t LL_SPI_IsEnabledIT_RXNE(SPI_TypeDef *SPIx)
  782. {
  783. return ((READ_BIT(SPIx->CR2, SPI_CR2_RXNEIE) == (SPI_CR2_RXNEIE)) ? 1UL : 0UL);
  784. }
  785. /**
  786. * @brief Check if Tx buffer empty interrupt
  787. * @rmtoll CR2 TXEIE LL_SPI_IsEnabledIT_TXE
  788. * @param SPIx SPI Instance
  789. * @retval State of bit (1 or 0).
  790. */
  791. __STATIC_INLINE uint32_t LL_SPI_IsEnabledIT_TXE(SPI_TypeDef *SPIx)
  792. {
  793. return ((READ_BIT(SPIx->CR2, SPI_CR2_TXEIE) == (SPI_CR2_TXEIE)) ? 1UL : 0UL);
  794. }
  795. /**
  796. * @}
  797. */
  798. #if (defined(DMA1) || defined(DMA))
  799. /** @defgroup SPI_LL_EF_DMA_Management DMA Management
  800. * @{
  801. */
  802. /**
  803. * @brief Enable DMA Rx
  804. * @note Depending on devices and packages, DMA may not be available.
  805. * Refer to device datasheet for DMA availability.
  806. * @rmtoll CR2 RXDMAEN LL_SPI_EnableDMAReq_RX
  807. * @param SPIx SPI Instance
  808. * @retval None
  809. */
  810. __STATIC_INLINE void LL_SPI_EnableDMAReq_RX(SPI_TypeDef *SPIx)
  811. {
  812. SET_BIT(SPIx->CR2, SPI_CR2_RXDMAEN);
  813. }
  814. /**
  815. * @brief Disable DMA Rx
  816. * @note Depending on devices and packages, DMA may not be available.
  817. * Refer to device datasheet for DMA availability.
  818. * @rmtoll CR2 RXDMAEN LL_SPI_DisableDMAReq_RX
  819. * @param SPIx SPI Instance
  820. * @retval None
  821. */
  822. __STATIC_INLINE void LL_SPI_DisableDMAReq_RX(SPI_TypeDef *SPIx)
  823. {
  824. CLEAR_BIT(SPIx->CR2, SPI_CR2_RXDMAEN);
  825. }
  826. /**
  827. * @brief Check if DMA Rx is enabled
  828. * @note Depending on devices and packages, DMA may not be available.
  829. * Refer to device datasheet for DMA availability.
  830. * @rmtoll CR2 RXDMAEN LL_SPI_IsEnabledDMAReq_RX
  831. * @param SPIx SPI Instance
  832. * @retval State of bit (1 or 0).
  833. */
  834. __STATIC_INLINE uint32_t LL_SPI_IsEnabledDMAReq_RX(SPI_TypeDef *SPIx)
  835. {
  836. return ((READ_BIT(SPIx->CR2, SPI_CR2_RXDMAEN) == (SPI_CR2_RXDMAEN)) ? 1UL : 0UL);
  837. }
  838. /**
  839. * @brief Enable DMA Tx
  840. * @note Depending on devices and packages, DMA may not be available.
  841. * Refer to device datasheet for DMA availability.
  842. * @rmtoll CR2 TXDMAEN LL_SPI_EnableDMAReq_TX
  843. * @param SPIx SPI Instance
  844. * @retval None
  845. */
  846. __STATIC_INLINE void LL_SPI_EnableDMAReq_TX(SPI_TypeDef *SPIx)
  847. {
  848. SET_BIT(SPIx->CR2, SPI_CR2_TXDMAEN);
  849. }
  850. /**
  851. * @brief Disable DMA Tx
  852. * @note Depending on devices and packages, DMA may not be available.
  853. * Refer to device datasheet for DMA availability.
  854. * @rmtoll CR2 TXDMAEN LL_SPI_DisableDMAReq_TX
  855. * @param SPIx SPI Instance
  856. * @retval None
  857. */
  858. __STATIC_INLINE void LL_SPI_DisableDMAReq_TX(SPI_TypeDef *SPIx)
  859. {
  860. CLEAR_BIT(SPIx->CR2, SPI_CR2_TXDMAEN);
  861. }
  862. /**
  863. * @brief Check if DMA Tx is enabled
  864. * @note Depending on devices and packages, DMA may not be available.
  865. * Refer to device datasheet for DMA availability.
  866. * @rmtoll CR2 TXDMAEN LL_SPI_IsEnabledDMAReq_TX
  867. * @param SPIx SPI Instance
  868. * @retval State of bit (1 or 0).
  869. */
  870. __STATIC_INLINE uint32_t LL_SPI_IsEnabledDMAReq_TX(SPI_TypeDef *SPIx)
  871. {
  872. return ((READ_BIT(SPIx->CR2, SPI_CR2_TXDMAEN) == (SPI_CR2_TXDMAEN)) ? 1UL : 0UL);
  873. }
  874. /**
  875. * @brief Set parity of Last DMA reception
  876. * @note Depending on devices and packages, DMA may not be available.
  877. * Refer to device datasheet for DMA availability.
  878. * @rmtoll CR2 LDMARX LL_SPI_SetDMAParity_RX
  879. * @param SPIx SPI Instance
  880. * @param Parity This parameter can be one of the following values:
  881. * @arg @ref LL_SPI_DMA_PARITY_ODD
  882. * @arg @ref LL_SPI_DMA_PARITY_EVEN
  883. * @retval None
  884. */
  885. __STATIC_INLINE void LL_SPI_SetDMAParity_RX(SPI_TypeDef *SPIx, uint32_t Parity)
  886. {
  887. MODIFY_REG(SPIx->CR2, SPI_CR2_LDMA_RX, (Parity << SPI_CR2_LDMA_RX_Pos));
  888. }
  889. /**
  890. * @brief Get parity configuration for Last DMA reception
  891. * @note Depending on devices and packages, DMA may not be available.
  892. * Refer to device datasheet for DMA availability.
  893. * @rmtoll CR2 LDMARX LL_SPI_GetDMAParity_RX
  894. * @param SPIx SPI Instance
  895. * @retval Returned value can be one of the following values:
  896. * @arg @ref LL_SPI_DMA_PARITY_ODD
  897. * @arg @ref LL_SPI_DMA_PARITY_EVEN
  898. */
  899. __STATIC_INLINE uint32_t LL_SPI_GetDMAParity_RX(SPI_TypeDef *SPIx)
  900. {
  901. return (uint32_t)(READ_BIT(SPIx->CR2, SPI_CR2_LDMA_RX) >> SPI_CR2_LDMA_RX_Pos);
  902. }
  903. /**
  904. * @brief Set parity of Last DMA transmission
  905. * @note Depending on devices and packages, DMA may not be available.
  906. * Refer to device datasheet for DMA availability.
  907. * @rmtoll CR2 LDMATX LL_SPI_SetDMAParity_TX
  908. * @param SPIx SPI Instance
  909. * @param Parity This parameter can be one of the following values:
  910. * @arg @ref LL_SPI_DMA_PARITY_ODD
  911. * @arg @ref LL_SPI_DMA_PARITY_EVEN
  912. * @retval None
  913. */
  914. __STATIC_INLINE void LL_SPI_SetDMAParity_TX(SPI_TypeDef *SPIx, uint32_t Parity)
  915. {
  916. MODIFY_REG(SPIx->CR2, SPI_CR2_LDMA_TX, (Parity << SPI_CR2_LDMA_TX_Pos));
  917. }
  918. /**
  919. * @brief Get parity configuration for Last DMA transmission
  920. * @note Depending on devices and packages, DMA may not be available.
  921. * Refer to device datasheet for DMA availability.
  922. * @rmtoll CR2 LDMATX LL_SPI_GetDMAParity_TX
  923. * @param SPIx SPI Instance
  924. * @retval Returned value can be one of the following values:
  925. * @arg @ref LL_SPI_DMA_PARITY_ODD
  926. * @arg @ref LL_SPI_DMA_PARITY_EVEN
  927. */
  928. __STATIC_INLINE uint32_t LL_SPI_GetDMAParity_TX(SPI_TypeDef *SPIx)
  929. {
  930. return (uint32_t)(READ_BIT(SPIx->CR2, SPI_CR2_LDMA_TX) >> SPI_CR2_LDMA_TX_Pos);
  931. }
  932. /**
  933. * @brief Get the data register address used for DMA transfer
  934. * @note Depending on devices and packages, DMA may not be available.
  935. * Refer to device datasheet for DMA availability.
  936. * @rmtoll DR DR LL_SPI_DMA_GetRegAddr
  937. * @param SPIx SPI Instance
  938. * @retval Address of data register
  939. */
  940. __STATIC_INLINE uint32_t LL_SPI_DMA_GetRegAddr(SPI_TypeDef *SPIx)
  941. {
  942. return (uint32_t) & (SPIx->DR);
  943. }
  944. /**
  945. * @}
  946. */
  947. #endif /* DMA1 or DMA */
  948. /** @defgroup SPI_LL_EF_DATA_Management DATA Management
  949. * @{
  950. */
  951. /**
  952. * @brief Read 8-Bits in the data register
  953. * @rmtoll DR DR LL_SPI_ReceiveData8
  954. * @param SPIx SPI Instance
  955. * @retval RxData Value between Min_Data=0x00 and Max_Data=0xFF
  956. */
  957. __STATIC_INLINE uint8_t LL_SPI_ReceiveData8(SPI_TypeDef *SPIx)
  958. {
  959. return (*((__IO uint8_t *)&SPIx->DR));
  960. }
  961. /**
  962. * @brief Read 16-Bits in the data register
  963. * @rmtoll DR DR LL_SPI_ReceiveData16
  964. * @param SPIx SPI Instance
  965. * @retval RxData Value between Min_Data=0x00 and Max_Data=0xFFFF
  966. */
  967. __STATIC_INLINE uint16_t LL_SPI_ReceiveData16(SPI_TypeDef *SPIx)
  968. {
  969. return (uint16_t)(READ_REG(SPIx->DR));
  970. }
  971. /**
  972. * @brief Write 8-Bits in the data register
  973. * @rmtoll DR DR LL_SPI_TransmitData8
  974. * @param SPIx SPI Instance
  975. * @param TxData Value between Min_Data=0x00 and Max_Data=0xFF
  976. * @retval None
  977. */
  978. __STATIC_INLINE void LL_SPI_TransmitData8(SPI_TypeDef *SPIx, uint8_t TxData)
  979. {
  980. #if defined (__GNUC__)
  981. __IO uint8_t *spidr = ((__IO uint8_t *)&SPIx->DR);
  982. *spidr = TxData;
  983. #else
  984. *((__IO uint8_t *)&SPIx->DR) = TxData;
  985. #endif /* __GNUC__ */
  986. }
  987. /**
  988. * @brief Write 16-Bits in the data register
  989. * @rmtoll DR DR LL_SPI_TransmitData16
  990. * @param SPIx SPI Instance
  991. * @param TxData Value between Min_Data=0x00 and Max_Data=0xFFFF
  992. * @retval None
  993. */
  994. __STATIC_INLINE void LL_SPI_TransmitData16(SPI_TypeDef *SPIx, uint16_t TxData)
  995. {
  996. #if defined (__GNUC__)
  997. __IO uint16_t *spidr = ((__IO uint16_t *)&SPIx->DR);
  998. *spidr = TxData;
  999. #else
  1000. SPIx->DR = TxData;
  1001. #endif /* __GNUC__ */
  1002. }
  1003. /**
  1004. * @brief Set Slave Speed Mode
  1005. * @rmtoll CR2 SLVFM LL_SPI_SetSlaveSpeedMode
  1006. * @param SPIx SPI Instance
  1007. * @param SlaveSpeedMode This parameter can be one of the following values:
  1008. * @arg @ref LL_SPI_SLAVE_SPEED_NORMAL
  1009. * @arg @ref LL_SPI_SLAVE_SPEED_FAST
  1010. * @retval None
  1011. */
  1012. __STATIC_INLINE void LL_SPI_SetSlaveSpeedMode(SPI_TypeDef *SPIx, uint32_t SlaveSpeedMode)
  1013. {
  1014. MODIFY_REG(SPIx->CR2, SPI_CR2_SLVFM, SlaveSpeedMode);
  1015. }
  1016. /**
  1017. * @brief Get Slave Speed Mode
  1018. * @rmtoll CR2 SLVFM LL_SPI_GetSlaveSpeedMode
  1019. * @param SPIx SPI Instance
  1020. * @retval Returned value can be one of the following values:
  1021. * @arg @ref LL_SPI_SLAVE_SPEED_NORMAL
  1022. * @arg @ref LL_SPI_SLAVE_SPEED_FAST
  1023. */
  1024. __STATIC_INLINE uint32_t LL_SPI_GetSlaveSpeedMode(SPI_TypeDef *SPIx)
  1025. {
  1026. return (uint32_t)(READ_BIT(SPIx->CR2, SPI_CR2_SLVFM));
  1027. }
  1028. /**
  1029. * @}
  1030. */
  1031. #if defined(USE_FULL_LL_DRIVER)
  1032. /** @defgroup SPI_LL_EF_Init Initialization and de-initialization functions
  1033. * @{
  1034. */
  1035. ErrorStatus LL_SPI_DeInit(SPI_TypeDef *SPIx);
  1036. ErrorStatus LL_SPI_Init(SPI_TypeDef *SPIx, LL_SPI_InitTypeDef *SPI_InitStruct);
  1037. void LL_SPI_StructInit(LL_SPI_InitTypeDef *SPI_InitStruct);
  1038. /**
  1039. * @}
  1040. */
  1041. #endif /* USE_FULL_LL_DRIVER */
  1042. /**
  1043. * @}
  1044. */
  1045. /**
  1046. * @}
  1047. */
  1048. #endif /* defined (SPI1) || defined (SPI2) */
  1049. /**
  1050. * @}
  1051. */
  1052. #ifdef __cplusplus
  1053. }
  1054. #endif
  1055. #endif /* PY32F0xx_LL_SPI_H */
  1056. /************************ (C) COPYRIGHT Puya *****END OF FILE****/