stm32g0xx_ll_spi.h 77 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284
  1. /**
  2. ******************************************************************************
  3. * @file stm32g0xx_ll_spi.h
  4. * @author MCD Application Team
  5. * @brief Header file of SPI LL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2018 STMicroelectronics.
  10. * All rights reserved.
  11. *
  12. * This software is licensed under terms that can be found in the LICENSE file
  13. * in the root directory of this software component.
  14. * If no LICENSE file comes with this software, it is provided AS-IS.
  15. *
  16. ******************************************************************************
  17. */
  18. /* Define to prevent recursive inclusion -------------------------------------*/
  19. #ifndef STM32G0xx_LL_SPI_H
  20. #define STM32G0xx_LL_SPI_H
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /* Includes ------------------------------------------------------------------*/
  25. #include "stm32g0xx.h"
  26. /** @addtogroup STM32G0xx_LL_Driver
  27. * @{
  28. */
  29. #if defined (SPI1) || defined (SPI2) || defined (SPI3)
  30. /** @defgroup SPI_LL SPI
  31. * @{
  32. */
  33. /* Private types -------------------------------------------------------------*/
  34. /* Private variables ---------------------------------------------------------*/
  35. /* Private macros ------------------------------------------------------------*/
  36. /* Exported types ------------------------------------------------------------*/
  37. #if defined(USE_FULL_LL_DRIVER)
  38. /** @defgroup SPI_LL_ES_INIT SPI Exported Init structure
  39. * @{
  40. */
  41. /**
  42. * @brief SPI Init structures definition
  43. */
  44. typedef struct
  45. {
  46. uint32_t TransferDirection; /*!< Specifies the SPI unidirectional or bidirectional data mode.
  47. This parameter can be a value of @ref SPI_LL_EC_TRANSFER_MODE.
  48. This feature can be modified afterwards using unitary function @ref LL_SPI_SetTransferDirection().*/
  49. uint32_t Mode; /*!< Specifies the SPI mode (Master/Slave).
  50. This parameter can be a value of @ref SPI_LL_EC_MODE.
  51. This feature can be modified afterwards using unitary function @ref LL_SPI_SetMode().*/
  52. uint32_t DataWidth; /*!< Specifies the SPI data width.
  53. This parameter can be a value of @ref SPI_LL_EC_DATAWIDTH.
  54. This feature can be modified afterwards using unitary function @ref LL_SPI_SetDataWidth().*/
  55. uint32_t ClockPolarity; /*!< Specifies the serial clock steady state.
  56. This parameter can be a value of @ref SPI_LL_EC_POLARITY.
  57. This feature can be modified afterwards using unitary function @ref LL_SPI_SetClockPolarity().*/
  58. uint32_t ClockPhase; /*!< Specifies the clock active edge for the bit capture.
  59. This parameter can be a value of @ref SPI_LL_EC_PHASE.
  60. This feature can be modified afterwards using unitary function @ref LL_SPI_SetClockPhase().*/
  61. uint32_t NSS; /*!< Specifies whether the NSS signal is managed by hardware (NSS pin) or by software using the SSI bit.
  62. This parameter can be a value of @ref SPI_LL_EC_NSS_MODE.
  63. This feature can be modified afterwards using unitary function @ref LL_SPI_SetNSSMode().*/
  64. uint32_t BaudRate; /*!< Specifies the BaudRate prescaler value which will be used to configure the transmit and receive SCK clock.
  65. This parameter can be a value of @ref SPI_LL_EC_BAUDRATEPRESCALER.
  66. @note The communication clock is derived from the master clock. The slave clock does not need to be set.
  67. This feature can be modified afterwards using unitary function @ref LL_SPI_SetBaudRatePrescaler().*/
  68. uint32_t BitOrder; /*!< Specifies whether data transfers start from MSB or LSB bit.
  69. This parameter can be a value of @ref SPI_LL_EC_BIT_ORDER.
  70. This feature can be modified afterwards using unitary function @ref LL_SPI_SetTransferBitOrder().*/
  71. uint32_t CRCCalculation; /*!< Specifies if the CRC calculation is enabled or not.
  72. This parameter can be a value of @ref SPI_LL_EC_CRC_CALCULATION.
  73. This feature can be modified afterwards using unitary functions @ref LL_SPI_EnableCRC() and @ref LL_SPI_DisableCRC().*/
  74. uint32_t CRCPoly; /*!< Specifies the polynomial used for the CRC calculation.
  75. This parameter must be a number between Min_Data = 0x00 and Max_Data = 0xFFFF.
  76. This feature can be modified afterwards using unitary function @ref LL_SPI_SetCRCPolynomial().*/
  77. } LL_SPI_InitTypeDef;
  78. /**
  79. * @}
  80. */
  81. #endif /* USE_FULL_LL_DRIVER */
  82. /* Exported constants --------------------------------------------------------*/
  83. /** @defgroup SPI_LL_Exported_Constants SPI Exported Constants
  84. * @{
  85. */
  86. /** @defgroup SPI_LL_EC_GET_FLAG Get Flags Defines
  87. * @brief Flags defines which can be used with LL_SPI_ReadReg function
  88. * @{
  89. */
  90. #define LL_SPI_SR_RXNE SPI_SR_RXNE /*!< Rx buffer not empty flag */
  91. #define LL_SPI_SR_TXE SPI_SR_TXE /*!< Tx buffer empty flag */
  92. #define LL_SPI_SR_BSY SPI_SR_BSY /*!< Busy flag */
  93. #define LL_SPI_SR_CRCERR SPI_SR_CRCERR /*!< CRC error flag */
  94. #define LL_SPI_SR_MODF SPI_SR_MODF /*!< Mode fault flag */
  95. #define LL_SPI_SR_OVR SPI_SR_OVR /*!< Overrun flag */
  96. #define LL_SPI_SR_FRE SPI_SR_FRE /*!< TI mode frame format error flag */
  97. /**
  98. * @}
  99. */
  100. /** @defgroup SPI_LL_EC_IT IT Defines
  101. * @brief IT defines which can be used with LL_SPI_ReadReg and LL_SPI_WriteReg functions
  102. * @{
  103. */
  104. #define LL_SPI_CR2_RXNEIE SPI_CR2_RXNEIE /*!< Rx buffer not empty interrupt enable */
  105. #define LL_SPI_CR2_TXEIE SPI_CR2_TXEIE /*!< Tx buffer empty interrupt enable */
  106. #define LL_SPI_CR2_ERRIE SPI_CR2_ERRIE /*!< Error interrupt enable */
  107. /**
  108. * @}
  109. */
  110. /** @defgroup SPI_LL_EC_MODE Operation Mode
  111. * @{
  112. */
  113. #define LL_SPI_MODE_MASTER (SPI_CR1_MSTR | SPI_CR1_SSI) /*!< Master configuration */
  114. #define LL_SPI_MODE_SLAVE 0x00000000U /*!< Slave configuration */
  115. /**
  116. * @}
  117. */
  118. /** @defgroup SPI_LL_EC_PROTOCOL Serial Protocol
  119. * @{
  120. */
  121. #define LL_SPI_PROTOCOL_MOTOROLA 0x00000000U /*!< Motorola mode. Used as default value */
  122. #define LL_SPI_PROTOCOL_TI (SPI_CR2_FRF) /*!< TI mode */
  123. /**
  124. * @}
  125. */
  126. /** @defgroup SPI_LL_EC_PHASE Clock Phase
  127. * @{
  128. */
  129. #define LL_SPI_PHASE_1EDGE 0x00000000U /*!< First clock transition is the first data capture edge */
  130. #define LL_SPI_PHASE_2EDGE (SPI_CR1_CPHA) /*!< Second clock transition is the first data capture edge */
  131. /**
  132. * @}
  133. */
  134. /** @defgroup SPI_LL_EC_POLARITY Clock Polarity
  135. * @{
  136. */
  137. #define LL_SPI_POLARITY_LOW 0x00000000U /*!< Clock to 0 when idle */
  138. #define LL_SPI_POLARITY_HIGH (SPI_CR1_CPOL) /*!< Clock to 1 when idle */
  139. /**
  140. * @}
  141. */
  142. /** @defgroup SPI_LL_EC_BAUDRATEPRESCALER Baud Rate Prescaler
  143. * @{
  144. */
  145. #define LL_SPI_BAUDRATEPRESCALER_DIV2 0x00000000U /*!< BaudRate control equal to fPCLK/2 */
  146. #define LL_SPI_BAUDRATEPRESCALER_DIV4 (SPI_CR1_BR_0) /*!< BaudRate control equal to fPCLK/4 */
  147. #define LL_SPI_BAUDRATEPRESCALER_DIV8 (SPI_CR1_BR_1) /*!< BaudRate control equal to fPCLK/8 */
  148. #define LL_SPI_BAUDRATEPRESCALER_DIV16 (SPI_CR1_BR_1 | SPI_CR1_BR_0) /*!< BaudRate control equal to fPCLK/16 */
  149. #define LL_SPI_BAUDRATEPRESCALER_DIV32 (SPI_CR1_BR_2) /*!< BaudRate control equal to fPCLK/32 */
  150. #define LL_SPI_BAUDRATEPRESCALER_DIV64 (SPI_CR1_BR_2 | SPI_CR1_BR_0) /*!< BaudRate control equal to fPCLK/64 */
  151. #define LL_SPI_BAUDRATEPRESCALER_DIV128 (SPI_CR1_BR_2 | SPI_CR1_BR_1) /*!< BaudRate control equal to fPCLK/128 */
  152. #define LL_SPI_BAUDRATEPRESCALER_DIV256 (SPI_CR1_BR_2 | SPI_CR1_BR_1 | SPI_CR1_BR_0) /*!< BaudRate control equal to fPCLK/256 */
  153. /**
  154. * @}
  155. */
  156. /** @defgroup SPI_LL_EC_BIT_ORDER Transmission Bit Order
  157. * @{
  158. */
  159. #define LL_SPI_LSB_FIRST (SPI_CR1_LSBFIRST) /*!< Data is transmitted/received with the LSB first */
  160. #define LL_SPI_MSB_FIRST 0x00000000U /*!< Data is transmitted/received with the MSB first */
  161. /**
  162. * @}
  163. */
  164. /** @defgroup SPI_LL_EC_TRANSFER_MODE Transfer Mode
  165. * @{
  166. */
  167. #define LL_SPI_FULL_DUPLEX 0x00000000U /*!< Full-Duplex mode. Rx and Tx transfer on 2 lines */
  168. #define LL_SPI_SIMPLEX_RX (SPI_CR1_RXONLY) /*!< Simplex Rx mode. Rx transfer only on 1 line */
  169. #define LL_SPI_HALF_DUPLEX_RX (SPI_CR1_BIDIMODE) /*!< Half-Duplex Rx mode. Rx transfer on 1 line */
  170. #define LL_SPI_HALF_DUPLEX_TX (SPI_CR1_BIDIMODE | SPI_CR1_BIDIOE) /*!< Half-Duplex Tx mode. Tx transfer on 1 line */
  171. /**
  172. * @}
  173. */
  174. /** @defgroup SPI_LL_EC_NSS_MODE Slave Select Pin Mode
  175. * @{
  176. */
  177. #define LL_SPI_NSS_SOFT (SPI_CR1_SSM) /*!< NSS managed internally. NSS pin not used and free */
  178. #define LL_SPI_NSS_HARD_INPUT 0x00000000U /*!< NSS pin used in Input. Only used in Master mode */
  179. #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 */
  180. /**
  181. * @}
  182. */
  183. /** @defgroup SPI_LL_EC_DATAWIDTH Datawidth
  184. * @{
  185. */
  186. #define LL_SPI_DATAWIDTH_4BIT (SPI_CR2_DS_0 | SPI_CR2_DS_1) /*!< Data length for SPI transfer: 4 bits */
  187. #define LL_SPI_DATAWIDTH_5BIT (SPI_CR2_DS_2) /*!< Data length for SPI transfer: 5 bits */
  188. #define LL_SPI_DATAWIDTH_6BIT (SPI_CR2_DS_2 | SPI_CR2_DS_0) /*!< Data length for SPI transfer: 6 bits */
  189. #define LL_SPI_DATAWIDTH_7BIT (SPI_CR2_DS_2 | SPI_CR2_DS_1) /*!< Data length for SPI transfer: 7 bits */
  190. #define LL_SPI_DATAWIDTH_8BIT (SPI_CR2_DS_2 | SPI_CR2_DS_1 | SPI_CR2_DS_0) /*!< Data length for SPI transfer: 8 bits */
  191. #define LL_SPI_DATAWIDTH_9BIT (SPI_CR2_DS_3) /*!< Data length for SPI transfer: 9 bits */
  192. #define LL_SPI_DATAWIDTH_10BIT (SPI_CR2_DS_3 | SPI_CR2_DS_0) /*!< Data length for SPI transfer: 10 bits */
  193. #define LL_SPI_DATAWIDTH_11BIT (SPI_CR2_DS_3 | SPI_CR2_DS_1) /*!< Data length for SPI transfer: 11 bits */
  194. #define LL_SPI_DATAWIDTH_12BIT (SPI_CR2_DS_3 | SPI_CR2_DS_1 | SPI_CR2_DS_0) /*!< Data length for SPI transfer: 12 bits */
  195. #define LL_SPI_DATAWIDTH_13BIT (SPI_CR2_DS_3 | SPI_CR2_DS_2) /*!< Data length for SPI transfer: 13 bits */
  196. #define LL_SPI_DATAWIDTH_14BIT (SPI_CR2_DS_3 | SPI_CR2_DS_2 | SPI_CR2_DS_0) /*!< Data length for SPI transfer: 14 bits */
  197. #define LL_SPI_DATAWIDTH_15BIT (SPI_CR2_DS_3 | SPI_CR2_DS_2 | SPI_CR2_DS_1) /*!< Data length for SPI transfer: 15 bits */
  198. #define LL_SPI_DATAWIDTH_16BIT (SPI_CR2_DS_3 | SPI_CR2_DS_2 | SPI_CR2_DS_1 | SPI_CR2_DS_0) /*!< Data length for SPI transfer: 16 bits */
  199. /**
  200. * @}
  201. */
  202. #if defined(USE_FULL_LL_DRIVER)
  203. /** @defgroup SPI_LL_EC_CRC_CALCULATION CRC Calculation
  204. * @{
  205. */
  206. #define LL_SPI_CRCCALCULATION_DISABLE 0x00000000U /*!< CRC calculation disabled */
  207. #define LL_SPI_CRCCALCULATION_ENABLE (SPI_CR1_CRCEN) /*!< CRC calculation enabled */
  208. /**
  209. * @}
  210. */
  211. #endif /* USE_FULL_LL_DRIVER */
  212. /** @defgroup SPI_LL_EC_CRC_LENGTH CRC Length
  213. * @{
  214. */
  215. #define LL_SPI_CRC_8BIT 0x00000000U /*!< 8-bit CRC length */
  216. #define LL_SPI_CRC_16BIT (SPI_CR1_CRCL) /*!< 16-bit CRC length */
  217. /**
  218. * @}
  219. */
  220. /** @defgroup SPI_LL_EC_RX_FIFO_TH RX FIFO Threshold
  221. * @{
  222. */
  223. #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) */
  224. #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) */
  225. /**
  226. * @}
  227. */
  228. /** @defgroup SPI_LL_EC_RX_FIFO RX FIFO Level
  229. * @{
  230. */
  231. #define LL_SPI_RX_FIFO_EMPTY 0x00000000U /*!< FIFO reception empty */
  232. #define LL_SPI_RX_FIFO_QUARTER_FULL (SPI_SR_FRLVL_0) /*!< FIFO reception 1/4 */
  233. #define LL_SPI_RX_FIFO_HALF_FULL (SPI_SR_FRLVL_1) /*!< FIFO reception 1/2 */
  234. #define LL_SPI_RX_FIFO_FULL (SPI_SR_FRLVL_1 | SPI_SR_FRLVL_0) /*!< FIFO reception full */
  235. /**
  236. * @}
  237. */
  238. /** @defgroup SPI_LL_EC_TX_FIFO TX FIFO Level
  239. * @{
  240. */
  241. #define LL_SPI_TX_FIFO_EMPTY 0x00000000U /*!< FIFO transmission empty */
  242. #define LL_SPI_TX_FIFO_QUARTER_FULL (SPI_SR_FTLVL_0) /*!< FIFO transmission 1/4 */
  243. #define LL_SPI_TX_FIFO_HALF_FULL (SPI_SR_FTLVL_1) /*!< FIFO transmission 1/2 */
  244. #define LL_SPI_TX_FIFO_FULL (SPI_SR_FTLVL_1 | SPI_SR_FTLVL_0) /*!< FIFO transmission full */
  245. /**
  246. * @}
  247. */
  248. /** @defgroup SPI_LL_EC_DMA_PARITY DMA Parity
  249. * @{
  250. */
  251. #define LL_SPI_DMA_PARITY_EVEN 0x00000000U /*!< Select DMA parity Even */
  252. #define LL_SPI_DMA_PARITY_ODD 0x00000001U /*!< Select DMA parity Odd */
  253. /**
  254. * @}
  255. */
  256. /**
  257. * @}
  258. */
  259. /* Exported macro ------------------------------------------------------------*/
  260. /** @defgroup SPI_LL_Exported_Macros SPI Exported Macros
  261. * @{
  262. */
  263. /** @defgroup SPI_LL_EM_WRITE_READ Common Write and read registers Macros
  264. * @{
  265. */
  266. /**
  267. * @brief Write a value in SPI register
  268. * @param __INSTANCE__ SPI Instance
  269. * @param __REG__ Register to be written
  270. * @param __VALUE__ Value to be written in the register
  271. * @retval None
  272. */
  273. #define LL_SPI_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
  274. /**
  275. * @brief Read a value in SPI register
  276. * @param __INSTANCE__ SPI Instance
  277. * @param __REG__ Register to be read
  278. * @retval Register value
  279. */
  280. #define LL_SPI_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
  281. /**
  282. * @}
  283. */
  284. /**
  285. * @}
  286. */
  287. /* Exported functions --------------------------------------------------------*/
  288. /** @defgroup SPI_LL_Exported_Functions SPI Exported Functions
  289. * @{
  290. */
  291. /** @defgroup SPI_LL_EF_Configuration Configuration
  292. * @{
  293. */
  294. /**
  295. * @brief Enable SPI peripheral
  296. * @rmtoll CR1 SPE LL_SPI_Enable
  297. * @param SPIx SPI Instance
  298. * @retval None
  299. */
  300. __STATIC_INLINE void LL_SPI_Enable(SPI_TypeDef *SPIx)
  301. {
  302. SET_BIT(SPIx->CR1, SPI_CR1_SPE);
  303. }
  304. /**
  305. * @brief Disable SPI peripheral
  306. * @note When disabling the SPI, follow the procedure described in the Reference Manual.
  307. * @rmtoll CR1 SPE LL_SPI_Disable
  308. * @param SPIx SPI Instance
  309. * @retval None
  310. */
  311. __STATIC_INLINE void LL_SPI_Disable(SPI_TypeDef *SPIx)
  312. {
  313. CLEAR_BIT(SPIx->CR1, SPI_CR1_SPE);
  314. }
  315. /**
  316. * @brief Check if SPI peripheral is enabled
  317. * @rmtoll CR1 SPE LL_SPI_IsEnabled
  318. * @param SPIx SPI Instance
  319. * @retval State of bit (1 or 0).
  320. */
  321. __STATIC_INLINE uint32_t LL_SPI_IsEnabled(SPI_TypeDef *SPIx)
  322. {
  323. return ((READ_BIT(SPIx->CR1, SPI_CR1_SPE) == (SPI_CR1_SPE)) ? 1UL : 0UL);
  324. }
  325. /**
  326. * @brief Set SPI operation mode to Master or Slave
  327. * @note This bit should not be changed when communication is ongoing.
  328. * @rmtoll CR1 MSTR LL_SPI_SetMode\n
  329. * CR1 SSI LL_SPI_SetMode
  330. * @param SPIx SPI Instance
  331. * @param Mode This parameter can be one of the following values:
  332. * @arg @ref LL_SPI_MODE_MASTER
  333. * @arg @ref LL_SPI_MODE_SLAVE
  334. * @retval None
  335. */
  336. __STATIC_INLINE void LL_SPI_SetMode(SPI_TypeDef *SPIx, uint32_t Mode)
  337. {
  338. MODIFY_REG(SPIx->CR1, SPI_CR1_MSTR | SPI_CR1_SSI, Mode);
  339. }
  340. /**
  341. * @brief Get SPI operation mode (Master or Slave)
  342. * @rmtoll CR1 MSTR LL_SPI_GetMode\n
  343. * CR1 SSI LL_SPI_GetMode
  344. * @param SPIx SPI Instance
  345. * @retval Returned value can be one of the following values:
  346. * @arg @ref LL_SPI_MODE_MASTER
  347. * @arg @ref LL_SPI_MODE_SLAVE
  348. */
  349. __STATIC_INLINE uint32_t LL_SPI_GetMode(SPI_TypeDef *SPIx)
  350. {
  351. return (uint32_t)(READ_BIT(SPIx->CR1, SPI_CR1_MSTR | SPI_CR1_SSI));
  352. }
  353. /**
  354. * @brief Set serial protocol used
  355. * @note This bit should be written only when SPI is disabled (SPE = 0) for correct operation.
  356. * @rmtoll CR2 FRF LL_SPI_SetStandard
  357. * @param SPIx SPI Instance
  358. * @param Standard This parameter can be one of the following values:
  359. * @arg @ref LL_SPI_PROTOCOL_MOTOROLA
  360. * @arg @ref LL_SPI_PROTOCOL_TI
  361. * @retval None
  362. */
  363. __STATIC_INLINE void LL_SPI_SetStandard(SPI_TypeDef *SPIx, uint32_t Standard)
  364. {
  365. MODIFY_REG(SPIx->CR2, SPI_CR2_FRF, Standard);
  366. }
  367. /**
  368. * @brief Get serial protocol used
  369. * @rmtoll CR2 FRF LL_SPI_GetStandard
  370. * @param SPIx SPI Instance
  371. * @retval Returned value can be one of the following values:
  372. * @arg @ref LL_SPI_PROTOCOL_MOTOROLA
  373. * @arg @ref LL_SPI_PROTOCOL_TI
  374. */
  375. __STATIC_INLINE uint32_t LL_SPI_GetStandard(SPI_TypeDef *SPIx)
  376. {
  377. return (uint32_t)(READ_BIT(SPIx->CR2, SPI_CR2_FRF));
  378. }
  379. /**
  380. * @brief Set clock phase
  381. * @note This bit should not be changed when communication is ongoing.
  382. * This bit is not used in SPI TI mode.
  383. * @rmtoll CR1 CPHA LL_SPI_SetClockPhase
  384. * @param SPIx SPI Instance
  385. * @param ClockPhase This parameter can be one of the following values:
  386. * @arg @ref LL_SPI_PHASE_1EDGE
  387. * @arg @ref LL_SPI_PHASE_2EDGE
  388. * @retval None
  389. */
  390. __STATIC_INLINE void LL_SPI_SetClockPhase(SPI_TypeDef *SPIx, uint32_t ClockPhase)
  391. {
  392. MODIFY_REG(SPIx->CR1, SPI_CR1_CPHA, ClockPhase);
  393. }
  394. /**
  395. * @brief Get clock phase
  396. * @rmtoll CR1 CPHA LL_SPI_GetClockPhase
  397. * @param SPIx SPI Instance
  398. * @retval Returned value can be one of the following values:
  399. * @arg @ref LL_SPI_PHASE_1EDGE
  400. * @arg @ref LL_SPI_PHASE_2EDGE
  401. */
  402. __STATIC_INLINE uint32_t LL_SPI_GetClockPhase(SPI_TypeDef *SPIx)
  403. {
  404. return (uint32_t)(READ_BIT(SPIx->CR1, SPI_CR1_CPHA));
  405. }
  406. /**
  407. * @brief Set clock polarity
  408. * @note This bit should not be changed when communication is ongoing.
  409. * This bit is not used in SPI TI mode.
  410. * @rmtoll CR1 CPOL LL_SPI_SetClockPolarity
  411. * @param SPIx SPI Instance
  412. * @param ClockPolarity This parameter can be one of the following values:
  413. * @arg @ref LL_SPI_POLARITY_LOW
  414. * @arg @ref LL_SPI_POLARITY_HIGH
  415. * @retval None
  416. */
  417. __STATIC_INLINE void LL_SPI_SetClockPolarity(SPI_TypeDef *SPIx, uint32_t ClockPolarity)
  418. {
  419. MODIFY_REG(SPIx->CR1, SPI_CR1_CPOL, ClockPolarity);
  420. }
  421. /**
  422. * @brief Get clock polarity
  423. * @rmtoll CR1 CPOL LL_SPI_GetClockPolarity
  424. * @param SPIx SPI Instance
  425. * @retval Returned value can be one of the following values:
  426. * @arg @ref LL_SPI_POLARITY_LOW
  427. * @arg @ref LL_SPI_POLARITY_HIGH
  428. */
  429. __STATIC_INLINE uint32_t LL_SPI_GetClockPolarity(SPI_TypeDef *SPIx)
  430. {
  431. return (uint32_t)(READ_BIT(SPIx->CR1, SPI_CR1_CPOL));
  432. }
  433. /**
  434. * @brief Set baud rate prescaler
  435. * @note These bits should not be changed when communication is ongoing. SPI BaudRate = fPCLK/Prescaler.
  436. * @rmtoll CR1 BR LL_SPI_SetBaudRatePrescaler
  437. * @param SPIx SPI Instance
  438. * @param BaudRate This parameter can be one of the following values:
  439. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV2
  440. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV4
  441. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV8
  442. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV16
  443. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV32
  444. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV64
  445. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV128
  446. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV256
  447. * @retval None
  448. */
  449. __STATIC_INLINE void LL_SPI_SetBaudRatePrescaler(SPI_TypeDef *SPIx, uint32_t BaudRate)
  450. {
  451. MODIFY_REG(SPIx->CR1, SPI_CR1_BR, BaudRate);
  452. }
  453. /**
  454. * @brief Get baud rate prescaler
  455. * @rmtoll CR1 BR LL_SPI_GetBaudRatePrescaler
  456. * @param SPIx SPI Instance
  457. * @retval Returned value can be one of the following values:
  458. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV2
  459. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV4
  460. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV8
  461. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV16
  462. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV32
  463. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV64
  464. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV128
  465. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV256
  466. */
  467. __STATIC_INLINE uint32_t LL_SPI_GetBaudRatePrescaler(SPI_TypeDef *SPIx)
  468. {
  469. return (uint32_t)(READ_BIT(SPIx->CR1, SPI_CR1_BR));
  470. }
  471. /**
  472. * @brief Set transfer bit order
  473. * @note This bit should not be changed when communication is ongoing. This bit is not used in SPI TI mode.
  474. * @rmtoll CR1 LSBFIRST LL_SPI_SetTransferBitOrder
  475. * @param SPIx SPI Instance
  476. * @param BitOrder This parameter can be one of the following values:
  477. * @arg @ref LL_SPI_LSB_FIRST
  478. * @arg @ref LL_SPI_MSB_FIRST
  479. * @retval None
  480. */
  481. __STATIC_INLINE void LL_SPI_SetTransferBitOrder(SPI_TypeDef *SPIx, uint32_t BitOrder)
  482. {
  483. MODIFY_REG(SPIx->CR1, SPI_CR1_LSBFIRST, BitOrder);
  484. }
  485. /**
  486. * @brief Get transfer bit order
  487. * @rmtoll CR1 LSBFIRST LL_SPI_GetTransferBitOrder
  488. * @param SPIx SPI Instance
  489. * @retval Returned value can be one of the following values:
  490. * @arg @ref LL_SPI_LSB_FIRST
  491. * @arg @ref LL_SPI_MSB_FIRST
  492. */
  493. __STATIC_INLINE uint32_t LL_SPI_GetTransferBitOrder(SPI_TypeDef *SPIx)
  494. {
  495. return (uint32_t)(READ_BIT(SPIx->CR1, SPI_CR1_LSBFIRST));
  496. }
  497. /**
  498. * @brief Set transfer direction mode
  499. * @note For Half-Duplex mode, Rx Direction is set by default.
  500. * In master mode, the MOSI pin is used and in slave mode, the MISO pin is used for Half-Duplex.
  501. * @rmtoll CR1 RXONLY LL_SPI_SetTransferDirection\n
  502. * CR1 BIDIMODE LL_SPI_SetTransferDirection\n
  503. * CR1 BIDIOE LL_SPI_SetTransferDirection
  504. * @param SPIx SPI Instance
  505. * @param TransferDirection This parameter can be one of the following values:
  506. * @arg @ref LL_SPI_FULL_DUPLEX
  507. * @arg @ref LL_SPI_SIMPLEX_RX
  508. * @arg @ref LL_SPI_HALF_DUPLEX_RX
  509. * @arg @ref LL_SPI_HALF_DUPLEX_TX
  510. * @retval None
  511. */
  512. __STATIC_INLINE void LL_SPI_SetTransferDirection(SPI_TypeDef *SPIx, uint32_t TransferDirection)
  513. {
  514. MODIFY_REG(SPIx->CR1, SPI_CR1_RXONLY | SPI_CR1_BIDIMODE | SPI_CR1_BIDIOE, TransferDirection);
  515. }
  516. /**
  517. * @brief Get transfer direction mode
  518. * @rmtoll CR1 RXONLY LL_SPI_GetTransferDirection\n
  519. * CR1 BIDIMODE LL_SPI_GetTransferDirection\n
  520. * CR1 BIDIOE LL_SPI_GetTransferDirection
  521. * @param SPIx SPI Instance
  522. * @retval Returned value can be one of the following values:
  523. * @arg @ref LL_SPI_FULL_DUPLEX
  524. * @arg @ref LL_SPI_SIMPLEX_RX
  525. * @arg @ref LL_SPI_HALF_DUPLEX_RX
  526. * @arg @ref LL_SPI_HALF_DUPLEX_TX
  527. */
  528. __STATIC_INLINE uint32_t LL_SPI_GetTransferDirection(SPI_TypeDef *SPIx)
  529. {
  530. return (uint32_t)(READ_BIT(SPIx->CR1, SPI_CR1_RXONLY | SPI_CR1_BIDIMODE | SPI_CR1_BIDIOE));
  531. }
  532. /**
  533. * @brief Set frame data width
  534. * @rmtoll CR2 DS LL_SPI_SetDataWidth
  535. * @param SPIx SPI Instance
  536. * @param DataWidth This parameter can be one of the following values:
  537. * @arg @ref LL_SPI_DATAWIDTH_4BIT
  538. * @arg @ref LL_SPI_DATAWIDTH_5BIT
  539. * @arg @ref LL_SPI_DATAWIDTH_6BIT
  540. * @arg @ref LL_SPI_DATAWIDTH_7BIT
  541. * @arg @ref LL_SPI_DATAWIDTH_8BIT
  542. * @arg @ref LL_SPI_DATAWIDTH_9BIT
  543. * @arg @ref LL_SPI_DATAWIDTH_10BIT
  544. * @arg @ref LL_SPI_DATAWIDTH_11BIT
  545. * @arg @ref LL_SPI_DATAWIDTH_12BIT
  546. * @arg @ref LL_SPI_DATAWIDTH_13BIT
  547. * @arg @ref LL_SPI_DATAWIDTH_14BIT
  548. * @arg @ref LL_SPI_DATAWIDTH_15BIT
  549. * @arg @ref LL_SPI_DATAWIDTH_16BIT
  550. * @retval None
  551. */
  552. __STATIC_INLINE void LL_SPI_SetDataWidth(SPI_TypeDef *SPIx, uint32_t DataWidth)
  553. {
  554. MODIFY_REG(SPIx->CR2, SPI_CR2_DS, DataWidth);
  555. }
  556. /**
  557. * @brief Get frame data width
  558. * @rmtoll CR2 DS LL_SPI_GetDataWidth
  559. * @param SPIx SPI Instance
  560. * @retval Returned value can be one of the following values:
  561. * @arg @ref LL_SPI_DATAWIDTH_4BIT
  562. * @arg @ref LL_SPI_DATAWIDTH_5BIT
  563. * @arg @ref LL_SPI_DATAWIDTH_6BIT
  564. * @arg @ref LL_SPI_DATAWIDTH_7BIT
  565. * @arg @ref LL_SPI_DATAWIDTH_8BIT
  566. * @arg @ref LL_SPI_DATAWIDTH_9BIT
  567. * @arg @ref LL_SPI_DATAWIDTH_10BIT
  568. * @arg @ref LL_SPI_DATAWIDTH_11BIT
  569. * @arg @ref LL_SPI_DATAWIDTH_12BIT
  570. * @arg @ref LL_SPI_DATAWIDTH_13BIT
  571. * @arg @ref LL_SPI_DATAWIDTH_14BIT
  572. * @arg @ref LL_SPI_DATAWIDTH_15BIT
  573. * @arg @ref LL_SPI_DATAWIDTH_16BIT
  574. */
  575. __STATIC_INLINE uint32_t LL_SPI_GetDataWidth(SPI_TypeDef *SPIx)
  576. {
  577. return (uint32_t)(READ_BIT(SPIx->CR2, SPI_CR2_DS));
  578. }
  579. /**
  580. * @brief Set threshold of RXFIFO that triggers an RXNE event
  581. * @rmtoll CR2 FRXTH LL_SPI_SetRxFIFOThreshold
  582. * @param SPIx SPI Instance
  583. * @param Threshold This parameter can be one of the following values:
  584. * @arg @ref LL_SPI_RX_FIFO_TH_HALF
  585. * @arg @ref LL_SPI_RX_FIFO_TH_QUARTER
  586. * @retval None
  587. */
  588. __STATIC_INLINE void LL_SPI_SetRxFIFOThreshold(SPI_TypeDef *SPIx, uint32_t Threshold)
  589. {
  590. MODIFY_REG(SPIx->CR2, SPI_CR2_FRXTH, Threshold);
  591. }
  592. /**
  593. * @brief Get threshold of RXFIFO that triggers an RXNE event
  594. * @rmtoll CR2 FRXTH LL_SPI_GetRxFIFOThreshold
  595. * @param SPIx SPI Instance
  596. * @retval Returned value can be one of the following values:
  597. * @arg @ref LL_SPI_RX_FIFO_TH_HALF
  598. * @arg @ref LL_SPI_RX_FIFO_TH_QUARTER
  599. */
  600. __STATIC_INLINE uint32_t LL_SPI_GetRxFIFOThreshold(SPI_TypeDef *SPIx)
  601. {
  602. return (uint32_t)(READ_BIT(SPIx->CR2, SPI_CR2_FRXTH));
  603. }
  604. /**
  605. * @}
  606. */
  607. /** @defgroup SPI_LL_EF_CRC_Management CRC Management
  608. * @{
  609. */
  610. /**
  611. * @brief Enable CRC
  612. * @note This bit should be written only when SPI is disabled (SPE = 0) for correct operation.
  613. * @rmtoll CR1 CRCEN LL_SPI_EnableCRC
  614. * @param SPIx SPI Instance
  615. * @retval None
  616. */
  617. __STATIC_INLINE void LL_SPI_EnableCRC(SPI_TypeDef *SPIx)
  618. {
  619. SET_BIT(SPIx->CR1, SPI_CR1_CRCEN);
  620. }
  621. /**
  622. * @brief Disable CRC
  623. * @note This bit should be written only when SPI is disabled (SPE = 0) for correct operation.
  624. * @rmtoll CR1 CRCEN LL_SPI_DisableCRC
  625. * @param SPIx SPI Instance
  626. * @retval None
  627. */
  628. __STATIC_INLINE void LL_SPI_DisableCRC(SPI_TypeDef *SPIx)
  629. {
  630. CLEAR_BIT(SPIx->CR1, SPI_CR1_CRCEN);
  631. }
  632. /**
  633. * @brief Check if CRC is enabled
  634. * @note This bit should be written only when SPI is disabled (SPE = 0) for correct operation.
  635. * @rmtoll CR1 CRCEN LL_SPI_IsEnabledCRC
  636. * @param SPIx SPI Instance
  637. * @retval State of bit (1 or 0).
  638. */
  639. __STATIC_INLINE uint32_t LL_SPI_IsEnabledCRC(SPI_TypeDef *SPIx)
  640. {
  641. return ((READ_BIT(SPIx->CR1, SPI_CR1_CRCEN) == (SPI_CR1_CRCEN)) ? 1UL : 0UL);
  642. }
  643. /**
  644. * @brief Set CRC Length
  645. * @note This bit should be written only when SPI is disabled (SPE = 0) for correct operation.
  646. * @rmtoll CR1 CRCL LL_SPI_SetCRCWidth
  647. * @param SPIx SPI Instance
  648. * @param CRCLength This parameter can be one of the following values:
  649. * @arg @ref LL_SPI_CRC_8BIT
  650. * @arg @ref LL_SPI_CRC_16BIT
  651. * @retval None
  652. */
  653. __STATIC_INLINE void LL_SPI_SetCRCWidth(SPI_TypeDef *SPIx, uint32_t CRCLength)
  654. {
  655. MODIFY_REG(SPIx->CR1, SPI_CR1_CRCL, CRCLength);
  656. }
  657. /**
  658. * @brief Get CRC Length
  659. * @rmtoll CR1 CRCL LL_SPI_GetCRCWidth
  660. * @param SPIx SPI Instance
  661. * @retval Returned value can be one of the following values:
  662. * @arg @ref LL_SPI_CRC_8BIT
  663. * @arg @ref LL_SPI_CRC_16BIT
  664. */
  665. __STATIC_INLINE uint32_t LL_SPI_GetCRCWidth(SPI_TypeDef *SPIx)
  666. {
  667. return (uint32_t)(READ_BIT(SPIx->CR1, SPI_CR1_CRCL));
  668. }
  669. /**
  670. * @brief Set CRCNext to transfer CRC on the line
  671. * @note This bit has to be written as soon as the last data is written in the SPIx_DR register.
  672. * @rmtoll CR1 CRCNEXT LL_SPI_SetCRCNext
  673. * @param SPIx SPI Instance
  674. * @retval None
  675. */
  676. __STATIC_INLINE void LL_SPI_SetCRCNext(SPI_TypeDef *SPIx)
  677. {
  678. SET_BIT(SPIx->CR1, SPI_CR1_CRCNEXT);
  679. }
  680. /**
  681. * @brief Set polynomial for CRC calculation
  682. * @rmtoll CRCPR CRCPOLY LL_SPI_SetCRCPolynomial
  683. * @param SPIx SPI Instance
  684. * @param CRCPoly This parameter must be a number between Min_Data = 0x00 and Max_Data = 0xFFFF
  685. * @retval None
  686. */
  687. __STATIC_INLINE void LL_SPI_SetCRCPolynomial(SPI_TypeDef *SPIx, uint32_t CRCPoly)
  688. {
  689. WRITE_REG(SPIx->CRCPR, (uint16_t)CRCPoly);
  690. }
  691. /**
  692. * @brief Get polynomial for CRC calculation
  693. * @rmtoll CRCPR CRCPOLY LL_SPI_GetCRCPolynomial
  694. * @param SPIx SPI Instance
  695. * @retval Returned value is a number between Min_Data = 0x00 and Max_Data = 0xFFFF
  696. */
  697. __STATIC_INLINE uint32_t LL_SPI_GetCRCPolynomial(SPI_TypeDef *SPIx)
  698. {
  699. return (uint32_t)(READ_REG(SPIx->CRCPR));
  700. }
  701. /**
  702. * @brief Get Rx CRC
  703. * @rmtoll RXCRCR RXCRC LL_SPI_GetRxCRC
  704. * @param SPIx SPI Instance
  705. * @retval Returned value is a number between Min_Data = 0x00 and Max_Data = 0xFFFF
  706. */
  707. __STATIC_INLINE uint32_t LL_SPI_GetRxCRC(SPI_TypeDef *SPIx)
  708. {
  709. return (uint32_t)(READ_REG(SPIx->RXCRCR));
  710. }
  711. /**
  712. * @brief Get Tx CRC
  713. * @rmtoll TXCRCR TXCRC LL_SPI_GetTxCRC
  714. * @param SPIx SPI Instance
  715. * @retval Returned value is a number between Min_Data = 0x00 and Max_Data = 0xFFFF
  716. */
  717. __STATIC_INLINE uint32_t LL_SPI_GetTxCRC(SPI_TypeDef *SPIx)
  718. {
  719. return (uint32_t)(READ_REG(SPIx->TXCRCR));
  720. }
  721. /**
  722. * @}
  723. */
  724. /** @defgroup SPI_LL_EF_NSS_Management Slave Select Pin Management
  725. * @{
  726. */
  727. /**
  728. * @brief Set NSS mode
  729. * @note LL_SPI_NSS_SOFT Mode is not used in SPI TI mode.
  730. * @rmtoll CR1 SSM LL_SPI_SetNSSMode\n
  731. * @rmtoll CR2 SSOE LL_SPI_SetNSSMode
  732. * @param SPIx SPI Instance
  733. * @param NSS This parameter can be one of the following values:
  734. * @arg @ref LL_SPI_NSS_SOFT
  735. * @arg @ref LL_SPI_NSS_HARD_INPUT
  736. * @arg @ref LL_SPI_NSS_HARD_OUTPUT
  737. * @retval None
  738. */
  739. __STATIC_INLINE void LL_SPI_SetNSSMode(SPI_TypeDef *SPIx, uint32_t NSS)
  740. {
  741. MODIFY_REG(SPIx->CR1, SPI_CR1_SSM, NSS);
  742. MODIFY_REG(SPIx->CR2, SPI_CR2_SSOE, ((uint32_t)(NSS >> 16U)));
  743. }
  744. /**
  745. * @brief Get NSS mode
  746. * @rmtoll CR1 SSM LL_SPI_GetNSSMode\n
  747. * @rmtoll CR2 SSOE LL_SPI_GetNSSMode
  748. * @param SPIx SPI Instance
  749. * @retval Returned value can be one of the following values:
  750. * @arg @ref LL_SPI_NSS_SOFT
  751. * @arg @ref LL_SPI_NSS_HARD_INPUT
  752. * @arg @ref LL_SPI_NSS_HARD_OUTPUT
  753. */
  754. __STATIC_INLINE uint32_t LL_SPI_GetNSSMode(SPI_TypeDef *SPIx)
  755. {
  756. uint32_t Ssm = (READ_BIT(SPIx->CR1, SPI_CR1_SSM));
  757. uint32_t Ssoe = (READ_BIT(SPIx->CR2, SPI_CR2_SSOE) << 16U);
  758. return (Ssm | Ssoe);
  759. }
  760. /**
  761. * @brief Enable NSS pulse management
  762. * @note This bit should not be changed when communication is ongoing. This bit is not used in SPI TI mode.
  763. * @rmtoll CR2 NSSP LL_SPI_EnableNSSPulseMgt
  764. * @param SPIx SPI Instance
  765. * @retval None
  766. */
  767. __STATIC_INLINE void LL_SPI_EnableNSSPulseMgt(SPI_TypeDef *SPIx)
  768. {
  769. SET_BIT(SPIx->CR2, SPI_CR2_NSSP);
  770. }
  771. /**
  772. * @brief Disable NSS pulse management
  773. * @note This bit should not be changed when communication is ongoing. This bit is not used in SPI TI mode.
  774. * @rmtoll CR2 NSSP LL_SPI_DisableNSSPulseMgt
  775. * @param SPIx SPI Instance
  776. * @retval None
  777. */
  778. __STATIC_INLINE void LL_SPI_DisableNSSPulseMgt(SPI_TypeDef *SPIx)
  779. {
  780. CLEAR_BIT(SPIx->CR2, SPI_CR2_NSSP);
  781. }
  782. /**
  783. * @brief Check if NSS pulse is enabled
  784. * @note This bit should not be changed when communication is ongoing. This bit is not used in SPI TI mode.
  785. * @rmtoll CR2 NSSP LL_SPI_IsEnabledNSSPulse
  786. * @param SPIx SPI Instance
  787. * @retval State of bit (1 or 0).
  788. */
  789. __STATIC_INLINE uint32_t LL_SPI_IsEnabledNSSPulse(SPI_TypeDef *SPIx)
  790. {
  791. return ((READ_BIT(SPIx->CR2, SPI_CR2_NSSP) == (SPI_CR2_NSSP)) ? 1UL : 0UL);
  792. }
  793. /**
  794. * @}
  795. */
  796. /** @defgroup SPI_LL_EF_FLAG_Management FLAG Management
  797. * @{
  798. */
  799. /**
  800. * @brief Check if Rx buffer is not empty
  801. * @rmtoll SR RXNE LL_SPI_IsActiveFlag_RXNE
  802. * @param SPIx SPI Instance
  803. * @retval State of bit (1 or 0).
  804. */
  805. __STATIC_INLINE uint32_t LL_SPI_IsActiveFlag_RXNE(SPI_TypeDef *SPIx)
  806. {
  807. return ((READ_BIT(SPIx->SR, SPI_SR_RXNE) == (SPI_SR_RXNE)) ? 1UL : 0UL);
  808. }
  809. /**
  810. * @brief Check if Tx buffer is empty
  811. * @rmtoll SR TXE LL_SPI_IsActiveFlag_TXE
  812. * @param SPIx SPI Instance
  813. * @retval State of bit (1 or 0).
  814. */
  815. __STATIC_INLINE uint32_t LL_SPI_IsActiveFlag_TXE(SPI_TypeDef *SPIx)
  816. {
  817. return ((READ_BIT(SPIx->SR, SPI_SR_TXE) == (SPI_SR_TXE)) ? 1UL : 0UL);
  818. }
  819. /**
  820. * @brief Get CRC error flag
  821. * @rmtoll SR CRCERR LL_SPI_IsActiveFlag_CRCERR
  822. * @param SPIx SPI Instance
  823. * @retval State of bit (1 or 0).
  824. */
  825. __STATIC_INLINE uint32_t LL_SPI_IsActiveFlag_CRCERR(SPI_TypeDef *SPIx)
  826. {
  827. return ((READ_BIT(SPIx->SR, SPI_SR_CRCERR) == (SPI_SR_CRCERR)) ? 1UL : 0UL);
  828. }
  829. /**
  830. * @brief Get mode fault error flag
  831. * @rmtoll SR MODF LL_SPI_IsActiveFlag_MODF
  832. * @param SPIx SPI Instance
  833. * @retval State of bit (1 or 0).
  834. */
  835. __STATIC_INLINE uint32_t LL_SPI_IsActiveFlag_MODF(SPI_TypeDef *SPIx)
  836. {
  837. return ((READ_BIT(SPIx->SR, SPI_SR_MODF) == (SPI_SR_MODF)) ? 1UL : 0UL);
  838. }
  839. /**
  840. * @brief Get overrun error flag
  841. * @rmtoll SR OVR LL_SPI_IsActiveFlag_OVR
  842. * @param SPIx SPI Instance
  843. * @retval State of bit (1 or 0).
  844. */
  845. __STATIC_INLINE uint32_t LL_SPI_IsActiveFlag_OVR(SPI_TypeDef *SPIx)
  846. {
  847. return ((READ_BIT(SPIx->SR, SPI_SR_OVR) == (SPI_SR_OVR)) ? 1UL : 0UL);
  848. }
  849. /**
  850. * @brief Get busy flag
  851. * @note The BSY flag is cleared under any one of the following conditions:
  852. * -When the SPI is correctly disabled
  853. * -When a fault is detected in Master mode (MODF bit set to 1)
  854. * -In Master mode, when it finishes a data transmission and no new data is ready to be
  855. * sent
  856. * -In Slave mode, when the BSY flag is set to '0' for at least one SPI clock cycle between
  857. * each data transfer.
  858. * @rmtoll SR BSY LL_SPI_IsActiveFlag_BSY
  859. * @param SPIx SPI Instance
  860. * @retval State of bit (1 or 0).
  861. */
  862. __STATIC_INLINE uint32_t LL_SPI_IsActiveFlag_BSY(SPI_TypeDef *SPIx)
  863. {
  864. return ((READ_BIT(SPIx->SR, SPI_SR_BSY) == (SPI_SR_BSY)) ? 1UL : 0UL);
  865. }
  866. /**
  867. * @brief Get frame format error flag
  868. * @rmtoll SR FRE LL_SPI_IsActiveFlag_FRE
  869. * @param SPIx SPI Instance
  870. * @retval State of bit (1 or 0).
  871. */
  872. __STATIC_INLINE uint32_t LL_SPI_IsActiveFlag_FRE(SPI_TypeDef *SPIx)
  873. {
  874. return ((READ_BIT(SPIx->SR, SPI_SR_FRE) == (SPI_SR_FRE)) ? 1UL : 0UL);
  875. }
  876. /**
  877. * @brief Get FIFO reception Level
  878. * @rmtoll SR FRLVL LL_SPI_GetRxFIFOLevel
  879. * @param SPIx SPI Instance
  880. * @retval Returned value can be one of the following values:
  881. * @arg @ref LL_SPI_RX_FIFO_EMPTY
  882. * @arg @ref LL_SPI_RX_FIFO_QUARTER_FULL
  883. * @arg @ref LL_SPI_RX_FIFO_HALF_FULL
  884. * @arg @ref LL_SPI_RX_FIFO_FULL
  885. */
  886. __STATIC_INLINE uint32_t LL_SPI_GetRxFIFOLevel(SPI_TypeDef *SPIx)
  887. {
  888. return (uint32_t)(READ_BIT(SPIx->SR, SPI_SR_FRLVL));
  889. }
  890. /**
  891. * @brief Get FIFO Transmission Level
  892. * @rmtoll SR FTLVL LL_SPI_GetTxFIFOLevel
  893. * @param SPIx SPI Instance
  894. * @retval Returned value can be one of the following values:
  895. * @arg @ref LL_SPI_TX_FIFO_EMPTY
  896. * @arg @ref LL_SPI_TX_FIFO_QUARTER_FULL
  897. * @arg @ref LL_SPI_TX_FIFO_HALF_FULL
  898. * @arg @ref LL_SPI_TX_FIFO_FULL
  899. */
  900. __STATIC_INLINE uint32_t LL_SPI_GetTxFIFOLevel(SPI_TypeDef *SPIx)
  901. {
  902. return (uint32_t)(READ_BIT(SPIx->SR, SPI_SR_FTLVL));
  903. }
  904. /**
  905. * @brief Clear CRC error flag
  906. * @rmtoll SR CRCERR LL_SPI_ClearFlag_CRCERR
  907. * @param SPIx SPI Instance
  908. * @retval None
  909. */
  910. __STATIC_INLINE void LL_SPI_ClearFlag_CRCERR(SPI_TypeDef *SPIx)
  911. {
  912. CLEAR_BIT(SPIx->SR, SPI_SR_CRCERR);
  913. }
  914. /**
  915. * @brief Clear mode fault error flag
  916. * @note Clearing this flag is done by a read access to the SPIx_SR
  917. * register followed by a write access to the SPIx_CR1 register
  918. * @rmtoll SR MODF LL_SPI_ClearFlag_MODF
  919. * @param SPIx SPI Instance
  920. * @retval None
  921. */
  922. __STATIC_INLINE void LL_SPI_ClearFlag_MODF(SPI_TypeDef *SPIx)
  923. {
  924. __IO uint32_t tmpreg_sr;
  925. tmpreg_sr = SPIx->SR;
  926. (void) tmpreg_sr;
  927. CLEAR_BIT(SPIx->CR1, SPI_CR1_SPE);
  928. }
  929. /**
  930. * @brief Clear overrun error flag
  931. * @note Clearing this flag is done by a read access to the SPIx_DR
  932. * register followed by a read access to the SPIx_SR register
  933. * @rmtoll SR OVR LL_SPI_ClearFlag_OVR
  934. * @param SPIx SPI Instance
  935. * @retval None
  936. */
  937. __STATIC_INLINE void LL_SPI_ClearFlag_OVR(SPI_TypeDef *SPIx)
  938. {
  939. __IO uint32_t tmpreg;
  940. tmpreg = SPIx->DR;
  941. (void) tmpreg;
  942. tmpreg = SPIx->SR;
  943. (void) tmpreg;
  944. }
  945. /**
  946. * @brief Clear frame format error flag
  947. * @note Clearing this flag is done by reading SPIx_SR register
  948. * @rmtoll SR FRE LL_SPI_ClearFlag_FRE
  949. * @param SPIx SPI Instance
  950. * @retval None
  951. */
  952. __STATIC_INLINE void LL_SPI_ClearFlag_FRE(SPI_TypeDef *SPIx)
  953. {
  954. __IO uint32_t tmpreg;
  955. tmpreg = SPIx->SR;
  956. (void) tmpreg;
  957. }
  958. /**
  959. * @}
  960. */
  961. /** @defgroup SPI_LL_EF_IT_Management Interrupt Management
  962. * @{
  963. */
  964. /**
  965. * @brief Enable error interrupt
  966. * @note This bit controls the generation of an interrupt when an error condition occurs (CRCERR, OVR, MODF in SPI mode, FRE at TI mode).
  967. * @rmtoll CR2 ERRIE LL_SPI_EnableIT_ERR
  968. * @param SPIx SPI Instance
  969. * @retval None
  970. */
  971. __STATIC_INLINE void LL_SPI_EnableIT_ERR(SPI_TypeDef *SPIx)
  972. {
  973. SET_BIT(SPIx->CR2, SPI_CR2_ERRIE);
  974. }
  975. /**
  976. * @brief Enable Rx buffer not empty interrupt
  977. * @rmtoll CR2 RXNEIE LL_SPI_EnableIT_RXNE
  978. * @param SPIx SPI Instance
  979. * @retval None
  980. */
  981. __STATIC_INLINE void LL_SPI_EnableIT_RXNE(SPI_TypeDef *SPIx)
  982. {
  983. SET_BIT(SPIx->CR2, SPI_CR2_RXNEIE);
  984. }
  985. /**
  986. * @brief Enable Tx buffer empty interrupt
  987. * @rmtoll CR2 TXEIE LL_SPI_EnableIT_TXE
  988. * @param SPIx SPI Instance
  989. * @retval None
  990. */
  991. __STATIC_INLINE void LL_SPI_EnableIT_TXE(SPI_TypeDef *SPIx)
  992. {
  993. SET_BIT(SPIx->CR2, SPI_CR2_TXEIE);
  994. }
  995. /**
  996. * @brief Disable error interrupt
  997. * @note This bit controls the generation of an interrupt when an error condition occurs (CRCERR, OVR, MODF in SPI mode, FRE at TI mode).
  998. * @rmtoll CR2 ERRIE LL_SPI_DisableIT_ERR
  999. * @param SPIx SPI Instance
  1000. * @retval None
  1001. */
  1002. __STATIC_INLINE void LL_SPI_DisableIT_ERR(SPI_TypeDef *SPIx)
  1003. {
  1004. CLEAR_BIT(SPIx->CR2, SPI_CR2_ERRIE);
  1005. }
  1006. /**
  1007. * @brief Disable Rx buffer not empty interrupt
  1008. * @rmtoll CR2 RXNEIE LL_SPI_DisableIT_RXNE
  1009. * @param SPIx SPI Instance
  1010. * @retval None
  1011. */
  1012. __STATIC_INLINE void LL_SPI_DisableIT_RXNE(SPI_TypeDef *SPIx)
  1013. {
  1014. CLEAR_BIT(SPIx->CR2, SPI_CR2_RXNEIE);
  1015. }
  1016. /**
  1017. * @brief Disable Tx buffer empty interrupt
  1018. * @rmtoll CR2 TXEIE LL_SPI_DisableIT_TXE
  1019. * @param SPIx SPI Instance
  1020. * @retval None
  1021. */
  1022. __STATIC_INLINE void LL_SPI_DisableIT_TXE(SPI_TypeDef *SPIx)
  1023. {
  1024. CLEAR_BIT(SPIx->CR2, SPI_CR2_TXEIE);
  1025. }
  1026. /**
  1027. * @brief Check if error interrupt is enabled
  1028. * @rmtoll CR2 ERRIE LL_SPI_IsEnabledIT_ERR
  1029. * @param SPIx SPI Instance
  1030. * @retval State of bit (1 or 0).
  1031. */
  1032. __STATIC_INLINE uint32_t LL_SPI_IsEnabledIT_ERR(SPI_TypeDef *SPIx)
  1033. {
  1034. return ((READ_BIT(SPIx->CR2, SPI_CR2_ERRIE) == (SPI_CR2_ERRIE)) ? 1UL : 0UL);
  1035. }
  1036. /**
  1037. * @brief Check if Rx buffer not empty interrupt is enabled
  1038. * @rmtoll CR2 RXNEIE LL_SPI_IsEnabledIT_RXNE
  1039. * @param SPIx SPI Instance
  1040. * @retval State of bit (1 or 0).
  1041. */
  1042. __STATIC_INLINE uint32_t LL_SPI_IsEnabledIT_RXNE(SPI_TypeDef *SPIx)
  1043. {
  1044. return ((READ_BIT(SPIx->CR2, SPI_CR2_RXNEIE) == (SPI_CR2_RXNEIE)) ? 1UL : 0UL);
  1045. }
  1046. /**
  1047. * @brief Check if Tx buffer empty interrupt
  1048. * @rmtoll CR2 TXEIE LL_SPI_IsEnabledIT_TXE
  1049. * @param SPIx SPI Instance
  1050. * @retval State of bit (1 or 0).
  1051. */
  1052. __STATIC_INLINE uint32_t LL_SPI_IsEnabledIT_TXE(SPI_TypeDef *SPIx)
  1053. {
  1054. return ((READ_BIT(SPIx->CR2, SPI_CR2_TXEIE) == (SPI_CR2_TXEIE)) ? 1UL : 0UL);
  1055. }
  1056. /**
  1057. * @}
  1058. */
  1059. /** @defgroup SPI_LL_EF_DMA_Management DMA Management
  1060. * @{
  1061. */
  1062. /**
  1063. * @brief Enable DMA Rx
  1064. * @rmtoll CR2 RXDMAEN LL_SPI_EnableDMAReq_RX
  1065. * @param SPIx SPI Instance
  1066. * @retval None
  1067. */
  1068. __STATIC_INLINE void LL_SPI_EnableDMAReq_RX(SPI_TypeDef *SPIx)
  1069. {
  1070. SET_BIT(SPIx->CR2, SPI_CR2_RXDMAEN);
  1071. }
  1072. /**
  1073. * @brief Disable DMA Rx
  1074. * @rmtoll CR2 RXDMAEN LL_SPI_DisableDMAReq_RX
  1075. * @param SPIx SPI Instance
  1076. * @retval None
  1077. */
  1078. __STATIC_INLINE void LL_SPI_DisableDMAReq_RX(SPI_TypeDef *SPIx)
  1079. {
  1080. CLEAR_BIT(SPIx->CR2, SPI_CR2_RXDMAEN);
  1081. }
  1082. /**
  1083. * @brief Check if DMA Rx is enabled
  1084. * @rmtoll CR2 RXDMAEN LL_SPI_IsEnabledDMAReq_RX
  1085. * @param SPIx SPI Instance
  1086. * @retval State of bit (1 or 0).
  1087. */
  1088. __STATIC_INLINE uint32_t LL_SPI_IsEnabledDMAReq_RX(SPI_TypeDef *SPIx)
  1089. {
  1090. return ((READ_BIT(SPIx->CR2, SPI_CR2_RXDMAEN) == (SPI_CR2_RXDMAEN)) ? 1UL : 0UL);
  1091. }
  1092. /**
  1093. * @brief Enable DMA Tx
  1094. * @rmtoll CR2 TXDMAEN LL_SPI_EnableDMAReq_TX
  1095. * @param SPIx SPI Instance
  1096. * @retval None
  1097. */
  1098. __STATIC_INLINE void LL_SPI_EnableDMAReq_TX(SPI_TypeDef *SPIx)
  1099. {
  1100. SET_BIT(SPIx->CR2, SPI_CR2_TXDMAEN);
  1101. }
  1102. /**
  1103. * @brief Disable DMA Tx
  1104. * @rmtoll CR2 TXDMAEN LL_SPI_DisableDMAReq_TX
  1105. * @param SPIx SPI Instance
  1106. * @retval None
  1107. */
  1108. __STATIC_INLINE void LL_SPI_DisableDMAReq_TX(SPI_TypeDef *SPIx)
  1109. {
  1110. CLEAR_BIT(SPIx->CR2, SPI_CR2_TXDMAEN);
  1111. }
  1112. /**
  1113. * @brief Check if DMA Tx is enabled
  1114. * @rmtoll CR2 TXDMAEN LL_SPI_IsEnabledDMAReq_TX
  1115. * @param SPIx SPI Instance
  1116. * @retval State of bit (1 or 0).
  1117. */
  1118. __STATIC_INLINE uint32_t LL_SPI_IsEnabledDMAReq_TX(SPI_TypeDef *SPIx)
  1119. {
  1120. return ((READ_BIT(SPIx->CR2, SPI_CR2_TXDMAEN) == (SPI_CR2_TXDMAEN)) ? 1UL : 0UL);
  1121. }
  1122. /**
  1123. * @brief Set parity of Last DMA reception
  1124. * @rmtoll CR2 LDMARX LL_SPI_SetDMAParity_RX
  1125. * @param SPIx SPI Instance
  1126. * @param Parity This parameter can be one of the following values:
  1127. * @arg @ref LL_SPI_DMA_PARITY_ODD
  1128. * @arg @ref LL_SPI_DMA_PARITY_EVEN
  1129. * @retval None
  1130. */
  1131. __STATIC_INLINE void LL_SPI_SetDMAParity_RX(SPI_TypeDef *SPIx, uint32_t Parity)
  1132. {
  1133. MODIFY_REG(SPIx->CR2, SPI_CR2_LDMARX, (Parity << SPI_CR2_LDMARX_Pos));
  1134. }
  1135. /**
  1136. * @brief Get parity configuration for Last DMA reception
  1137. * @rmtoll CR2 LDMARX LL_SPI_GetDMAParity_RX
  1138. * @param SPIx SPI Instance
  1139. * @retval Returned value can be one of the following values:
  1140. * @arg @ref LL_SPI_DMA_PARITY_ODD
  1141. * @arg @ref LL_SPI_DMA_PARITY_EVEN
  1142. */
  1143. __STATIC_INLINE uint32_t LL_SPI_GetDMAParity_RX(SPI_TypeDef *SPIx)
  1144. {
  1145. return (uint32_t)(READ_BIT(SPIx->CR2, SPI_CR2_LDMARX) >> SPI_CR2_LDMARX_Pos);
  1146. }
  1147. /**
  1148. * @brief Set parity of Last DMA transmission
  1149. * @rmtoll CR2 LDMATX LL_SPI_SetDMAParity_TX
  1150. * @param SPIx SPI Instance
  1151. * @param Parity This parameter can be one of the following values:
  1152. * @arg @ref LL_SPI_DMA_PARITY_ODD
  1153. * @arg @ref LL_SPI_DMA_PARITY_EVEN
  1154. * @retval None
  1155. */
  1156. __STATIC_INLINE void LL_SPI_SetDMAParity_TX(SPI_TypeDef *SPIx, uint32_t Parity)
  1157. {
  1158. MODIFY_REG(SPIx->CR2, SPI_CR2_LDMATX, (Parity << SPI_CR2_LDMATX_Pos));
  1159. }
  1160. /**
  1161. * @brief Get parity configuration for Last DMA transmission
  1162. * @rmtoll CR2 LDMATX LL_SPI_GetDMAParity_TX
  1163. * @param SPIx SPI Instance
  1164. * @retval Returned value can be one of the following values:
  1165. * @arg @ref LL_SPI_DMA_PARITY_ODD
  1166. * @arg @ref LL_SPI_DMA_PARITY_EVEN
  1167. */
  1168. __STATIC_INLINE uint32_t LL_SPI_GetDMAParity_TX(SPI_TypeDef *SPIx)
  1169. {
  1170. return (uint32_t)(READ_BIT(SPIx->CR2, SPI_CR2_LDMATX) >> SPI_CR2_LDMATX_Pos);
  1171. }
  1172. /**
  1173. * @brief Get the data register address used for DMA transfer
  1174. * @rmtoll DR DR LL_SPI_DMA_GetRegAddr
  1175. * @param SPIx SPI Instance
  1176. * @retval Address of data register
  1177. */
  1178. __STATIC_INLINE uint32_t LL_SPI_DMA_GetRegAddr(SPI_TypeDef *SPIx)
  1179. {
  1180. return (uint32_t) &(SPIx->DR);
  1181. }
  1182. /**
  1183. * @}
  1184. */
  1185. /** @defgroup SPI_LL_EF_DATA_Management DATA Management
  1186. * @{
  1187. */
  1188. /**
  1189. * @brief Read 8-Bits in the data register
  1190. * @rmtoll DR DR LL_SPI_ReceiveData8
  1191. * @param SPIx SPI Instance
  1192. * @retval RxData Value between Min_Data=0x00 and Max_Data=0xFF
  1193. */
  1194. __STATIC_INLINE uint8_t LL_SPI_ReceiveData8(SPI_TypeDef *SPIx)
  1195. {
  1196. return (*((__IO uint8_t *)&SPIx->DR));
  1197. }
  1198. /**
  1199. * @brief Read 16-Bits in the data register
  1200. * @rmtoll DR DR LL_SPI_ReceiveData16
  1201. * @param SPIx SPI Instance
  1202. * @retval RxData Value between Min_Data=0x00 and Max_Data=0xFFFF
  1203. */
  1204. __STATIC_INLINE uint16_t LL_SPI_ReceiveData16(SPI_TypeDef *SPIx)
  1205. {
  1206. return (uint16_t)(READ_REG(SPIx->DR));
  1207. }
  1208. /**
  1209. * @brief Write 8-Bits in the data register
  1210. * @rmtoll DR DR LL_SPI_TransmitData8
  1211. * @param SPIx SPI Instance
  1212. * @param TxData Value between Min_Data=0x00 and Max_Data=0xFF
  1213. * @retval None
  1214. */
  1215. __STATIC_INLINE void LL_SPI_TransmitData8(SPI_TypeDef *SPIx, uint8_t TxData)
  1216. {
  1217. #if defined (__GNUC__)
  1218. __IO uint8_t *spidr = ((__IO uint8_t *)&SPIx->DR);
  1219. *spidr = TxData;
  1220. #else
  1221. *((__IO uint8_t *)&SPIx->DR) = TxData;
  1222. #endif /* __GNUC__ */
  1223. }
  1224. /**
  1225. * @brief Write 16-Bits in the data register
  1226. * @rmtoll DR DR LL_SPI_TransmitData16
  1227. * @param SPIx SPI Instance
  1228. * @param TxData Value between Min_Data=0x00 and Max_Data=0xFFFF
  1229. * @retval None
  1230. */
  1231. __STATIC_INLINE void LL_SPI_TransmitData16(SPI_TypeDef *SPIx, uint16_t TxData)
  1232. {
  1233. #if defined (__GNUC__)
  1234. __IO uint16_t *spidr = ((__IO uint16_t *)&SPIx->DR);
  1235. *spidr = TxData;
  1236. #else
  1237. SPIx->DR = TxData;
  1238. #endif /* __GNUC__ */
  1239. }
  1240. /**
  1241. * @}
  1242. */
  1243. #if defined(USE_FULL_LL_DRIVER)
  1244. /** @defgroup SPI_LL_EF_Init Initialization and de-initialization functions
  1245. * @{
  1246. */
  1247. ErrorStatus LL_SPI_DeInit(SPI_TypeDef *SPIx);
  1248. ErrorStatus LL_SPI_Init(SPI_TypeDef *SPIx, LL_SPI_InitTypeDef *SPI_InitStruct);
  1249. void LL_SPI_StructInit(LL_SPI_InitTypeDef *SPI_InitStruct);
  1250. /**
  1251. * @}
  1252. */
  1253. #endif /* USE_FULL_LL_DRIVER */
  1254. /**
  1255. * @}
  1256. */
  1257. /**
  1258. * @}
  1259. */
  1260. #if defined(SPI_I2S_SUPPORT)
  1261. /** @defgroup I2S_LL I2S
  1262. * @{
  1263. */
  1264. /* Private variables ---------------------------------------------------------*/
  1265. /* Private constants ---------------------------------------------------------*/
  1266. /* Private macros ------------------------------------------------------------*/
  1267. /* Exported types ------------------------------------------------------------*/
  1268. #if defined(USE_FULL_LL_DRIVER)
  1269. /** @defgroup I2S_LL_ES_INIT I2S Exported Init structure
  1270. * @{
  1271. */
  1272. /**
  1273. * @brief I2S Init structure definition
  1274. */
  1275. typedef struct
  1276. {
  1277. uint32_t Mode; /*!< Specifies the I2S operating mode.
  1278. This parameter can be a value of @ref I2S_LL_EC_MODE
  1279. This feature can be modified afterwards using unitary function @ref LL_I2S_SetTransferMode().*/
  1280. uint32_t Standard; /*!< Specifies the standard used for the I2S communication.
  1281. This parameter can be a value of @ref I2S_LL_EC_STANDARD
  1282. This feature can be modified afterwards using unitary function @ref LL_I2S_SetStandard().*/
  1283. uint32_t DataFormat; /*!< Specifies the data format for the I2S communication.
  1284. This parameter can be a value of @ref I2S_LL_EC_DATA_FORMAT
  1285. This feature can be modified afterwards using unitary function @ref LL_I2S_SetDataFormat().*/
  1286. uint32_t MCLKOutput; /*!< Specifies whether the I2S MCLK output is enabled or not.
  1287. This parameter can be a value of @ref I2S_LL_EC_MCLK_OUTPUT
  1288. This feature can be modified afterwards using unitary functions @ref LL_I2S_EnableMasterClock() or @ref LL_I2S_DisableMasterClock.*/
  1289. uint32_t AudioFreq; /*!< Specifies the frequency selected for the I2S communication.
  1290. This parameter can be a value of @ref I2S_LL_EC_AUDIO_FREQ
  1291. Audio Frequency can be modified afterwards using Reference manual formulas to calculate Prescaler Linear, Parity
  1292. and unitary functions @ref LL_I2S_SetPrescalerLinear() and @ref LL_I2S_SetPrescalerParity() to set it.*/
  1293. uint32_t ClockPolarity; /*!< Specifies the idle state of the I2S clock.
  1294. This parameter can be a value of @ref I2S_LL_EC_POLARITY
  1295. This feature can be modified afterwards using unitary function @ref LL_I2S_SetClockPolarity().*/
  1296. } LL_I2S_InitTypeDef;
  1297. /**
  1298. * @}
  1299. */
  1300. #endif /*USE_FULL_LL_DRIVER*/
  1301. /* Exported constants --------------------------------------------------------*/
  1302. /** @defgroup I2S_LL_Exported_Constants I2S Exported Constants
  1303. * @{
  1304. */
  1305. /** @defgroup I2S_LL_EC_GET_FLAG Get Flags Defines
  1306. * @brief Flags defines which can be used with LL_I2S_ReadReg function
  1307. * @{
  1308. */
  1309. #define LL_I2S_SR_RXNE LL_SPI_SR_RXNE /*!< Rx buffer not empty flag */
  1310. #define LL_I2S_SR_TXE LL_SPI_SR_TXE /*!< Tx buffer empty flag */
  1311. #define LL_I2S_SR_BSY LL_SPI_SR_BSY /*!< Busy flag */
  1312. #define LL_I2S_SR_UDR SPI_SR_UDR /*!< Underrun flag */
  1313. #define LL_I2S_SR_OVR LL_SPI_SR_OVR /*!< Overrun flag */
  1314. #define LL_I2S_SR_FRE LL_SPI_SR_FRE /*!< TI mode frame format error flag */
  1315. /**
  1316. * @}
  1317. */
  1318. /** @defgroup SPI_LL_EC_IT IT Defines
  1319. * @brief IT defines which can be used with LL_SPI_ReadReg and LL_SPI_WriteReg functions
  1320. * @{
  1321. */
  1322. #define LL_I2S_CR2_RXNEIE LL_SPI_CR2_RXNEIE /*!< Rx buffer not empty interrupt enable */
  1323. #define LL_I2S_CR2_TXEIE LL_SPI_CR2_TXEIE /*!< Tx buffer empty interrupt enable */
  1324. #define LL_I2S_CR2_ERRIE LL_SPI_CR2_ERRIE /*!< Error interrupt enable */
  1325. /**
  1326. * @}
  1327. */
  1328. /** @defgroup I2S_LL_EC_DATA_FORMAT Data format
  1329. * @{
  1330. */
  1331. #define LL_I2S_DATAFORMAT_16B 0x00000000U /*!< Data length 16 bits, Channel length 16bit */
  1332. #define LL_I2S_DATAFORMAT_16B_EXTENDED (SPI_I2SCFGR_CHLEN) /*!< Data length 16 bits, Channel length 32bit */
  1333. #define LL_I2S_DATAFORMAT_24B (SPI_I2SCFGR_CHLEN | SPI_I2SCFGR_DATLEN_0) /*!< Data length 24 bits, Channel length 32bit */
  1334. #define LL_I2S_DATAFORMAT_32B (SPI_I2SCFGR_CHLEN | SPI_I2SCFGR_DATLEN_1) /*!< Data length 16 bits, Channel length 32bit */
  1335. /**
  1336. * @}
  1337. */
  1338. /** @defgroup I2S_LL_EC_POLARITY Clock Polarity
  1339. * @{
  1340. */
  1341. #define LL_I2S_POLARITY_LOW 0x00000000U /*!< Clock steady state is low level */
  1342. #define LL_I2S_POLARITY_HIGH (SPI_I2SCFGR_CKPOL) /*!< Clock steady state is high level */
  1343. /**
  1344. * @}
  1345. */
  1346. /** @defgroup I2S_LL_EC_STANDARD I2s Standard
  1347. * @{
  1348. */
  1349. #define LL_I2S_STANDARD_PHILIPS 0x00000000U /*!< I2S standard philips */
  1350. #define LL_I2S_STANDARD_MSB (SPI_I2SCFGR_I2SSTD_0) /*!< MSB justified standard (left justified) */
  1351. #define LL_I2S_STANDARD_LSB (SPI_I2SCFGR_I2SSTD_1) /*!< LSB justified standard (right justified) */
  1352. #define LL_I2S_STANDARD_PCM_SHORT (SPI_I2SCFGR_I2SSTD_0 | SPI_I2SCFGR_I2SSTD_1) /*!< PCM standard, short frame synchronization */
  1353. #define LL_I2S_STANDARD_PCM_LONG (SPI_I2SCFGR_I2SSTD_0 | SPI_I2SCFGR_I2SSTD_1 | SPI_I2SCFGR_PCMSYNC) /*!< PCM standard, long frame synchronization */
  1354. /**
  1355. * @}
  1356. */
  1357. /** @defgroup I2S_LL_EC_MODE Operation Mode
  1358. * @{
  1359. */
  1360. #define LL_I2S_MODE_SLAVE_TX 0x00000000U /*!< Slave Tx configuration */
  1361. #define LL_I2S_MODE_SLAVE_RX (SPI_I2SCFGR_I2SCFG_0) /*!< Slave Rx configuration */
  1362. #define LL_I2S_MODE_MASTER_TX (SPI_I2SCFGR_I2SCFG_1) /*!< Master Tx configuration */
  1363. #define LL_I2S_MODE_MASTER_RX (SPI_I2SCFGR_I2SCFG_0 | SPI_I2SCFGR_I2SCFG_1) /*!< Master Rx configuration */
  1364. /**
  1365. * @}
  1366. */
  1367. /** @defgroup I2S_LL_EC_PRESCALER_FACTOR Prescaler Factor
  1368. * @{
  1369. */
  1370. #define LL_I2S_PRESCALER_PARITY_EVEN 0x00000000U /*!< Odd factor: Real divider value is = I2SDIV * 2 */
  1371. #define LL_I2S_PRESCALER_PARITY_ODD (SPI_I2SPR_ODD >> 8U) /*!< Odd factor: Real divider value is = (I2SDIV * 2)+1 */
  1372. /**
  1373. * @}
  1374. */
  1375. #if defined(USE_FULL_LL_DRIVER)
  1376. /** @defgroup I2S_LL_EC_MCLK_OUTPUT MCLK Output
  1377. * @{
  1378. */
  1379. #define LL_I2S_MCLK_OUTPUT_DISABLE 0x00000000U /*!< Master clock output is disabled */
  1380. #define LL_I2S_MCLK_OUTPUT_ENABLE (SPI_I2SPR_MCKOE) /*!< Master clock output is enabled */
  1381. /**
  1382. * @}
  1383. */
  1384. /** @defgroup I2S_LL_EC_AUDIO_FREQ Audio Frequency
  1385. * @{
  1386. */
  1387. #define LL_I2S_AUDIOFREQ_192K 192000U /*!< Audio Frequency configuration 192000 Hz */
  1388. #define LL_I2S_AUDIOFREQ_96K 96000U /*!< Audio Frequency configuration 96000 Hz */
  1389. #define LL_I2S_AUDIOFREQ_48K 48000U /*!< Audio Frequency configuration 48000 Hz */
  1390. #define LL_I2S_AUDIOFREQ_44K 44100U /*!< Audio Frequency configuration 44100 Hz */
  1391. #define LL_I2S_AUDIOFREQ_32K 32000U /*!< Audio Frequency configuration 32000 Hz */
  1392. #define LL_I2S_AUDIOFREQ_22K 22050U /*!< Audio Frequency configuration 22050 Hz */
  1393. #define LL_I2S_AUDIOFREQ_16K 16000U /*!< Audio Frequency configuration 16000 Hz */
  1394. #define LL_I2S_AUDIOFREQ_11K 11025U /*!< Audio Frequency configuration 11025 Hz */
  1395. #define LL_I2S_AUDIOFREQ_8K 8000U /*!< Audio Frequency configuration 8000 Hz */
  1396. #define LL_I2S_AUDIOFREQ_DEFAULT 2U /*!< Audio Freq not specified. Register I2SDIV = 2 */
  1397. /**
  1398. * @}
  1399. */
  1400. #endif /* USE_FULL_LL_DRIVER */
  1401. /**
  1402. * @}
  1403. */
  1404. /* Exported macro ------------------------------------------------------------*/
  1405. /** @defgroup I2S_LL_Exported_Macros I2S Exported Macros
  1406. * @{
  1407. */
  1408. /** @defgroup I2S_LL_EM_WRITE_READ Common Write and read registers Macros
  1409. * @{
  1410. */
  1411. /**
  1412. * @brief Write a value in I2S register
  1413. * @param __INSTANCE__ I2S Instance
  1414. * @param __REG__ Register to be written
  1415. * @param __VALUE__ Value to be written in the register
  1416. * @retval None
  1417. */
  1418. #define LL_I2S_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
  1419. /**
  1420. * @brief Read a value in I2S register
  1421. * @param __INSTANCE__ I2S Instance
  1422. * @param __REG__ Register to be read
  1423. * @retval Register value
  1424. */
  1425. #define LL_I2S_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
  1426. /**
  1427. * @}
  1428. */
  1429. /**
  1430. * @}
  1431. */
  1432. /* Exported functions --------------------------------------------------------*/
  1433. /** @defgroup I2S_LL_Exported_Functions I2S Exported Functions
  1434. * @{
  1435. */
  1436. /** @defgroup I2S_LL_EF_Configuration Configuration
  1437. * @{
  1438. */
  1439. /**
  1440. * @brief Select I2S mode and Enable I2S peripheral
  1441. * @rmtoll I2SCFGR I2SMOD LL_I2S_Enable\n
  1442. * I2SCFGR I2SE LL_I2S_Enable
  1443. * @param SPIx SPI Instance
  1444. * @retval None
  1445. */
  1446. __STATIC_INLINE void LL_I2S_Enable(SPI_TypeDef *SPIx)
  1447. {
  1448. SET_BIT(SPIx->I2SCFGR, SPI_I2SCFGR_I2SMOD | SPI_I2SCFGR_I2SE);
  1449. }
  1450. /**
  1451. * @brief Disable I2S peripheral
  1452. * @rmtoll I2SCFGR I2SE LL_I2S_Disable
  1453. * @param SPIx SPI Instance
  1454. * @retval None
  1455. */
  1456. __STATIC_INLINE void LL_I2S_Disable(SPI_TypeDef *SPIx)
  1457. {
  1458. CLEAR_BIT(SPIx->I2SCFGR, SPI_I2SCFGR_I2SMOD | SPI_I2SCFGR_I2SE);
  1459. }
  1460. /**
  1461. * @brief Check if I2S peripheral is enabled
  1462. * @rmtoll I2SCFGR I2SE LL_I2S_IsEnabled
  1463. * @param SPIx SPI Instance
  1464. * @retval State of bit (1 or 0).
  1465. */
  1466. __STATIC_INLINE uint32_t LL_I2S_IsEnabled(SPI_TypeDef *SPIx)
  1467. {
  1468. return ((READ_BIT(SPIx->I2SCFGR, SPI_I2SCFGR_I2SE) == (SPI_I2SCFGR_I2SE)) ? 1UL : 0UL);
  1469. }
  1470. /**
  1471. * @brief Set I2S data frame length
  1472. * @rmtoll I2SCFGR DATLEN LL_I2S_SetDataFormat\n
  1473. * I2SCFGR CHLEN LL_I2S_SetDataFormat
  1474. * @param SPIx SPI Instance
  1475. * @param DataFormat This parameter can be one of the following values:
  1476. * @arg @ref LL_I2S_DATAFORMAT_16B
  1477. * @arg @ref LL_I2S_DATAFORMAT_16B_EXTENDED
  1478. * @arg @ref LL_I2S_DATAFORMAT_24B
  1479. * @arg @ref LL_I2S_DATAFORMAT_32B
  1480. * @retval None
  1481. */
  1482. __STATIC_INLINE void LL_I2S_SetDataFormat(SPI_TypeDef *SPIx, uint32_t DataFormat)
  1483. {
  1484. MODIFY_REG(SPIx->I2SCFGR, SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN, DataFormat);
  1485. }
  1486. /**
  1487. * @brief Get I2S data frame length
  1488. * @rmtoll I2SCFGR DATLEN LL_I2S_GetDataFormat\n
  1489. * I2SCFGR CHLEN LL_I2S_GetDataFormat
  1490. * @param SPIx SPI Instance
  1491. * @retval Returned value can be one of the following values:
  1492. * @arg @ref LL_I2S_DATAFORMAT_16B
  1493. * @arg @ref LL_I2S_DATAFORMAT_16B_EXTENDED
  1494. * @arg @ref LL_I2S_DATAFORMAT_24B
  1495. * @arg @ref LL_I2S_DATAFORMAT_32B
  1496. */
  1497. __STATIC_INLINE uint32_t LL_I2S_GetDataFormat(SPI_TypeDef *SPIx)
  1498. {
  1499. return (uint32_t)(READ_BIT(SPIx->I2SCFGR, SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN));
  1500. }
  1501. /**
  1502. * @brief Set I2S clock polarity
  1503. * @rmtoll I2SCFGR CKPOL LL_I2S_SetClockPolarity
  1504. * @param SPIx SPI Instance
  1505. * @param ClockPolarity This parameter can be one of the following values:
  1506. * @arg @ref LL_I2S_POLARITY_LOW
  1507. * @arg @ref LL_I2S_POLARITY_HIGH
  1508. * @retval None
  1509. */
  1510. __STATIC_INLINE void LL_I2S_SetClockPolarity(SPI_TypeDef *SPIx, uint32_t ClockPolarity)
  1511. {
  1512. SET_BIT(SPIx->I2SCFGR, ClockPolarity);
  1513. }
  1514. /**
  1515. * @brief Get I2S clock polarity
  1516. * @rmtoll I2SCFGR CKPOL LL_I2S_GetClockPolarity
  1517. * @param SPIx SPI Instance
  1518. * @retval Returned value can be one of the following values:
  1519. * @arg @ref LL_I2S_POLARITY_LOW
  1520. * @arg @ref LL_I2S_POLARITY_HIGH
  1521. */
  1522. __STATIC_INLINE uint32_t LL_I2S_GetClockPolarity(SPI_TypeDef *SPIx)
  1523. {
  1524. return (uint32_t)(READ_BIT(SPIx->I2SCFGR, SPI_I2SCFGR_CKPOL));
  1525. }
  1526. /**
  1527. * @brief Set I2S standard protocol
  1528. * @rmtoll I2SCFGR I2SSTD LL_I2S_SetStandard\n
  1529. * I2SCFGR PCMSYNC LL_I2S_SetStandard
  1530. * @param SPIx SPI Instance
  1531. * @param Standard This parameter can be one of the following values:
  1532. * @arg @ref LL_I2S_STANDARD_PHILIPS
  1533. * @arg @ref LL_I2S_STANDARD_MSB
  1534. * @arg @ref LL_I2S_STANDARD_LSB
  1535. * @arg @ref LL_I2S_STANDARD_PCM_SHORT
  1536. * @arg @ref LL_I2S_STANDARD_PCM_LONG
  1537. * @retval None
  1538. */
  1539. __STATIC_INLINE void LL_I2S_SetStandard(SPI_TypeDef *SPIx, uint32_t Standard)
  1540. {
  1541. MODIFY_REG(SPIx->I2SCFGR, SPI_I2SCFGR_I2SSTD | SPI_I2SCFGR_PCMSYNC, Standard);
  1542. }
  1543. /**
  1544. * @brief Get I2S standard protocol
  1545. * @rmtoll I2SCFGR I2SSTD LL_I2S_GetStandard\n
  1546. * I2SCFGR PCMSYNC LL_I2S_GetStandard
  1547. * @param SPIx SPI Instance
  1548. * @retval Returned value can be one of the following values:
  1549. * @arg @ref LL_I2S_STANDARD_PHILIPS
  1550. * @arg @ref LL_I2S_STANDARD_MSB
  1551. * @arg @ref LL_I2S_STANDARD_LSB
  1552. * @arg @ref LL_I2S_STANDARD_PCM_SHORT
  1553. * @arg @ref LL_I2S_STANDARD_PCM_LONG
  1554. */
  1555. __STATIC_INLINE uint32_t LL_I2S_GetStandard(SPI_TypeDef *SPIx)
  1556. {
  1557. return (uint32_t)(READ_BIT(SPIx->I2SCFGR, SPI_I2SCFGR_I2SSTD | SPI_I2SCFGR_PCMSYNC));
  1558. }
  1559. /**
  1560. * @brief Set I2S transfer mode
  1561. * @rmtoll I2SCFGR I2SCFG LL_I2S_SetTransferMode
  1562. * @param SPIx SPI Instance
  1563. * @param Mode This parameter can be one of the following values:
  1564. * @arg @ref LL_I2S_MODE_SLAVE_TX
  1565. * @arg @ref LL_I2S_MODE_SLAVE_RX
  1566. * @arg @ref LL_I2S_MODE_MASTER_TX
  1567. * @arg @ref LL_I2S_MODE_MASTER_RX
  1568. * @retval None
  1569. */
  1570. __STATIC_INLINE void LL_I2S_SetTransferMode(SPI_TypeDef *SPIx, uint32_t Mode)
  1571. {
  1572. MODIFY_REG(SPIx->I2SCFGR, SPI_I2SCFGR_I2SCFG, Mode);
  1573. }
  1574. /**
  1575. * @brief Get I2S transfer mode
  1576. * @rmtoll I2SCFGR I2SCFG LL_I2S_GetTransferMode
  1577. * @param SPIx SPI Instance
  1578. * @retval Returned value can be one of the following values:
  1579. * @arg @ref LL_I2S_MODE_SLAVE_TX
  1580. * @arg @ref LL_I2S_MODE_SLAVE_RX
  1581. * @arg @ref LL_I2S_MODE_MASTER_TX
  1582. * @arg @ref LL_I2S_MODE_MASTER_RX
  1583. */
  1584. __STATIC_INLINE uint32_t LL_I2S_GetTransferMode(SPI_TypeDef *SPIx)
  1585. {
  1586. return (uint32_t)(READ_BIT(SPIx->I2SCFGR, SPI_I2SCFGR_I2SCFG));
  1587. }
  1588. /**
  1589. * @brief Set I2S linear prescaler
  1590. * @rmtoll I2SPR I2SDIV LL_I2S_SetPrescalerLinear
  1591. * @param SPIx SPI Instance
  1592. * @param PrescalerLinear Value between Min_Data=0x02 and Max_Data=0xFF
  1593. * @retval None
  1594. */
  1595. __STATIC_INLINE void LL_I2S_SetPrescalerLinear(SPI_TypeDef *SPIx, uint8_t PrescalerLinear)
  1596. {
  1597. MODIFY_REG(SPIx->I2SPR, SPI_I2SPR_I2SDIV, PrescalerLinear);
  1598. }
  1599. /**
  1600. * @brief Get I2S linear prescaler
  1601. * @rmtoll I2SPR I2SDIV LL_I2S_GetPrescalerLinear
  1602. * @param SPIx SPI Instance
  1603. * @retval PrescalerLinear Value between Min_Data=0x02 and Max_Data=0xFF
  1604. */
  1605. __STATIC_INLINE uint32_t LL_I2S_GetPrescalerLinear(SPI_TypeDef *SPIx)
  1606. {
  1607. return (uint32_t)(READ_BIT(SPIx->I2SPR, SPI_I2SPR_I2SDIV));
  1608. }
  1609. /**
  1610. * @brief Set I2S parity prescaler
  1611. * @rmtoll I2SPR ODD LL_I2S_SetPrescalerParity
  1612. * @param SPIx SPI Instance
  1613. * @param PrescalerParity This parameter can be one of the following values:
  1614. * @arg @ref LL_I2S_PRESCALER_PARITY_EVEN
  1615. * @arg @ref LL_I2S_PRESCALER_PARITY_ODD
  1616. * @retval None
  1617. */
  1618. __STATIC_INLINE void LL_I2S_SetPrescalerParity(SPI_TypeDef *SPIx, uint32_t PrescalerParity)
  1619. {
  1620. MODIFY_REG(SPIx->I2SPR, SPI_I2SPR_ODD, PrescalerParity << 8U);
  1621. }
  1622. /**
  1623. * @brief Get I2S parity prescaler
  1624. * @rmtoll I2SPR ODD LL_I2S_GetPrescalerParity
  1625. * @param SPIx SPI Instance
  1626. * @retval Returned value can be one of the following values:
  1627. * @arg @ref LL_I2S_PRESCALER_PARITY_EVEN
  1628. * @arg @ref LL_I2S_PRESCALER_PARITY_ODD
  1629. */
  1630. __STATIC_INLINE uint32_t LL_I2S_GetPrescalerParity(SPI_TypeDef *SPIx)
  1631. {
  1632. return (uint32_t)(READ_BIT(SPIx->I2SPR, SPI_I2SPR_ODD) >> 8U);
  1633. }
  1634. /**
  1635. * @brief Enable the master clock output (Pin MCK)
  1636. * @rmtoll I2SPR MCKOE LL_I2S_EnableMasterClock
  1637. * @param SPIx SPI Instance
  1638. * @retval None
  1639. */
  1640. __STATIC_INLINE void LL_I2S_EnableMasterClock(SPI_TypeDef *SPIx)
  1641. {
  1642. SET_BIT(SPIx->I2SPR, SPI_I2SPR_MCKOE);
  1643. }
  1644. /**
  1645. * @brief Disable the master clock output (Pin MCK)
  1646. * @rmtoll I2SPR MCKOE LL_I2S_DisableMasterClock
  1647. * @param SPIx SPI Instance
  1648. * @retval None
  1649. */
  1650. __STATIC_INLINE void LL_I2S_DisableMasterClock(SPI_TypeDef *SPIx)
  1651. {
  1652. CLEAR_BIT(SPIx->I2SPR, SPI_I2SPR_MCKOE);
  1653. }
  1654. /**
  1655. * @brief Check if the master clock output (Pin MCK) is enabled
  1656. * @rmtoll I2SPR MCKOE LL_I2S_IsEnabledMasterClock
  1657. * @param SPIx SPI Instance
  1658. * @retval State of bit (1 or 0).
  1659. */
  1660. __STATIC_INLINE uint32_t LL_I2S_IsEnabledMasterClock(SPI_TypeDef *SPIx)
  1661. {
  1662. return ((READ_BIT(SPIx->I2SPR, SPI_I2SPR_MCKOE) == (SPI_I2SPR_MCKOE)) ? 1UL : 0UL);
  1663. }
  1664. #if defined(SPI_I2SCFGR_ASTRTEN)
  1665. /**
  1666. * @brief Enable asynchronous start
  1667. * @rmtoll I2SCFGR ASTRTEN LL_I2S_EnableAsyncStart
  1668. * @param SPIx SPI Instance
  1669. * @retval None
  1670. */
  1671. __STATIC_INLINE void LL_I2S_EnableAsyncStart(SPI_TypeDef *SPIx)
  1672. {
  1673. SET_BIT(SPIx->I2SCFGR, SPI_I2SCFGR_ASTRTEN);
  1674. }
  1675. /**
  1676. * @brief Disable asynchronous start
  1677. * @rmtoll I2SCFGR ASTRTEN LL_I2S_DisableAsyncStart
  1678. * @param SPIx SPI Instance
  1679. * @retval None
  1680. */
  1681. __STATIC_INLINE void LL_I2S_DisableAsyncStart(SPI_TypeDef *SPIx)
  1682. {
  1683. CLEAR_BIT(SPIx->I2SCFGR, SPI_I2SCFGR_ASTRTEN);
  1684. }
  1685. /**
  1686. * @brief Check if asynchronous start is enabled
  1687. * @rmtoll I2SCFGR ASTRTEN LL_I2S_IsEnabledAsyncStart
  1688. * @param SPIx SPI Instance
  1689. * @retval State of bit (1 or 0).
  1690. */
  1691. __STATIC_INLINE uint32_t LL_I2S_IsEnabledAsyncStart(SPI_TypeDef *SPIx)
  1692. {
  1693. return ((READ_BIT(SPIx->I2SCFGR, SPI_I2SCFGR_ASTRTEN) == (SPI_I2SCFGR_ASTRTEN)) ? 1UL : 0UL);
  1694. }
  1695. #endif /* SPI_I2SCFGR_ASTRTEN */
  1696. /**
  1697. * @}
  1698. */
  1699. /** @defgroup I2S_LL_EF_FLAG FLAG Management
  1700. * @{
  1701. */
  1702. /**
  1703. * @brief Check if Rx buffer is not empty
  1704. * @rmtoll SR RXNE LL_I2S_IsActiveFlag_RXNE
  1705. * @param SPIx SPI Instance
  1706. * @retval State of bit (1 or 0).
  1707. */
  1708. __STATIC_INLINE uint32_t LL_I2S_IsActiveFlag_RXNE(SPI_TypeDef *SPIx)
  1709. {
  1710. return LL_SPI_IsActiveFlag_RXNE(SPIx);
  1711. }
  1712. /**
  1713. * @brief Check if Tx buffer is empty
  1714. * @rmtoll SR TXE LL_I2S_IsActiveFlag_TXE
  1715. * @param SPIx SPI Instance
  1716. * @retval State of bit (1 or 0).
  1717. */
  1718. __STATIC_INLINE uint32_t LL_I2S_IsActiveFlag_TXE(SPI_TypeDef *SPIx)
  1719. {
  1720. return LL_SPI_IsActiveFlag_TXE(SPIx);
  1721. }
  1722. /**
  1723. * @brief Get busy flag
  1724. * @rmtoll SR BSY LL_I2S_IsActiveFlag_BSY
  1725. * @param SPIx SPI Instance
  1726. * @retval State of bit (1 or 0).
  1727. */
  1728. __STATIC_INLINE uint32_t LL_I2S_IsActiveFlag_BSY(SPI_TypeDef *SPIx)
  1729. {
  1730. return LL_SPI_IsActiveFlag_BSY(SPIx);
  1731. }
  1732. /**
  1733. * @brief Get overrun error flag
  1734. * @rmtoll SR OVR LL_I2S_IsActiveFlag_OVR
  1735. * @param SPIx SPI Instance
  1736. * @retval State of bit (1 or 0).
  1737. */
  1738. __STATIC_INLINE uint32_t LL_I2S_IsActiveFlag_OVR(SPI_TypeDef *SPIx)
  1739. {
  1740. return LL_SPI_IsActiveFlag_OVR(SPIx);
  1741. }
  1742. /**
  1743. * @brief Get underrun error flag
  1744. * @rmtoll SR UDR LL_I2S_IsActiveFlag_UDR
  1745. * @param SPIx SPI Instance
  1746. * @retval State of bit (1 or 0).
  1747. */
  1748. __STATIC_INLINE uint32_t LL_I2S_IsActiveFlag_UDR(SPI_TypeDef *SPIx)
  1749. {
  1750. return ((READ_BIT(SPIx->SR, SPI_SR_UDR) == (SPI_SR_UDR)) ? 1UL : 0UL);
  1751. }
  1752. /**
  1753. * @brief Get frame format error flag
  1754. * @rmtoll SR FRE LL_I2S_IsActiveFlag_FRE
  1755. * @param SPIx SPI Instance
  1756. * @retval State of bit (1 or 0).
  1757. */
  1758. __STATIC_INLINE uint32_t LL_I2S_IsActiveFlag_FRE(SPI_TypeDef *SPIx)
  1759. {
  1760. return LL_SPI_IsActiveFlag_FRE(SPIx);
  1761. }
  1762. /**
  1763. * @brief Get channel side flag.
  1764. * @note 0: Channel Left has to be transmitted or has been received\n
  1765. * 1: Channel Right has to be transmitted or has been received\n
  1766. * It has no significance in PCM mode.
  1767. * @rmtoll SR CHSIDE LL_I2S_IsActiveFlag_CHSIDE
  1768. * @param SPIx SPI Instance
  1769. * @retval State of bit (1 or 0).
  1770. */
  1771. __STATIC_INLINE uint32_t LL_I2S_IsActiveFlag_CHSIDE(SPI_TypeDef *SPIx)
  1772. {
  1773. return ((READ_BIT(SPIx->SR, SPI_SR_CHSIDE) == (SPI_SR_CHSIDE)) ? 1UL : 0UL);
  1774. }
  1775. /**
  1776. * @brief Clear overrun error flag
  1777. * @rmtoll SR OVR LL_I2S_ClearFlag_OVR
  1778. * @param SPIx SPI Instance
  1779. * @retval None
  1780. */
  1781. __STATIC_INLINE void LL_I2S_ClearFlag_OVR(SPI_TypeDef *SPIx)
  1782. {
  1783. LL_SPI_ClearFlag_OVR(SPIx);
  1784. }
  1785. /**
  1786. * @brief Clear underrun error flag
  1787. * @rmtoll SR UDR LL_I2S_ClearFlag_UDR
  1788. * @param SPIx SPI Instance
  1789. * @retval None
  1790. */
  1791. __STATIC_INLINE void LL_I2S_ClearFlag_UDR(SPI_TypeDef *SPIx)
  1792. {
  1793. __IO uint32_t tmpreg;
  1794. tmpreg = SPIx->SR;
  1795. (void)tmpreg;
  1796. }
  1797. /**
  1798. * @brief Clear frame format error flag
  1799. * @rmtoll SR FRE LL_I2S_ClearFlag_FRE
  1800. * @param SPIx SPI Instance
  1801. * @retval None
  1802. */
  1803. __STATIC_INLINE void LL_I2S_ClearFlag_FRE(SPI_TypeDef *SPIx)
  1804. {
  1805. LL_SPI_ClearFlag_FRE(SPIx);
  1806. }
  1807. /**
  1808. * @}
  1809. */
  1810. /** @defgroup I2S_LL_EF_IT Interrupt Management
  1811. * @{
  1812. */
  1813. /**
  1814. * @brief Enable error IT
  1815. * @note This bit controls the generation of an interrupt when an error condition occurs (OVR, UDR and FRE in I2S mode).
  1816. * @rmtoll CR2 ERRIE LL_I2S_EnableIT_ERR
  1817. * @param SPIx SPI Instance
  1818. * @retval None
  1819. */
  1820. __STATIC_INLINE void LL_I2S_EnableIT_ERR(SPI_TypeDef *SPIx)
  1821. {
  1822. LL_SPI_EnableIT_ERR(SPIx);
  1823. }
  1824. /**
  1825. * @brief Enable Rx buffer not empty IT
  1826. * @rmtoll CR2 RXNEIE LL_I2S_EnableIT_RXNE
  1827. * @param SPIx SPI Instance
  1828. * @retval None
  1829. */
  1830. __STATIC_INLINE void LL_I2S_EnableIT_RXNE(SPI_TypeDef *SPIx)
  1831. {
  1832. LL_SPI_EnableIT_RXNE(SPIx);
  1833. }
  1834. /**
  1835. * @brief Enable Tx buffer empty IT
  1836. * @rmtoll CR2 TXEIE LL_I2S_EnableIT_TXE
  1837. * @param SPIx SPI Instance
  1838. * @retval None
  1839. */
  1840. __STATIC_INLINE void LL_I2S_EnableIT_TXE(SPI_TypeDef *SPIx)
  1841. {
  1842. LL_SPI_EnableIT_TXE(SPIx);
  1843. }
  1844. /**
  1845. * @brief Disable error IT
  1846. * @note This bit controls the generation of an interrupt when an error condition occurs (OVR, UDR and FRE in I2S mode).
  1847. * @rmtoll CR2 ERRIE LL_I2S_DisableIT_ERR
  1848. * @param SPIx SPI Instance
  1849. * @retval None
  1850. */
  1851. __STATIC_INLINE void LL_I2S_DisableIT_ERR(SPI_TypeDef *SPIx)
  1852. {
  1853. LL_SPI_DisableIT_ERR(SPIx);
  1854. }
  1855. /**
  1856. * @brief Disable Rx buffer not empty IT
  1857. * @rmtoll CR2 RXNEIE LL_I2S_DisableIT_RXNE
  1858. * @param SPIx SPI Instance
  1859. * @retval None
  1860. */
  1861. __STATIC_INLINE void LL_I2S_DisableIT_RXNE(SPI_TypeDef *SPIx)
  1862. {
  1863. LL_SPI_DisableIT_RXNE(SPIx);
  1864. }
  1865. /**
  1866. * @brief Disable Tx buffer empty IT
  1867. * @rmtoll CR2 TXEIE LL_I2S_DisableIT_TXE
  1868. * @param SPIx SPI Instance
  1869. * @retval None
  1870. */
  1871. __STATIC_INLINE void LL_I2S_DisableIT_TXE(SPI_TypeDef *SPIx)
  1872. {
  1873. LL_SPI_DisableIT_TXE(SPIx);
  1874. }
  1875. /**
  1876. * @brief Check if ERR IT is enabled
  1877. * @rmtoll CR2 ERRIE LL_I2S_IsEnabledIT_ERR
  1878. * @param SPIx SPI Instance
  1879. * @retval State of bit (1 or 0).
  1880. */
  1881. __STATIC_INLINE uint32_t LL_I2S_IsEnabledIT_ERR(SPI_TypeDef *SPIx)
  1882. {
  1883. return LL_SPI_IsEnabledIT_ERR(SPIx);
  1884. }
  1885. /**
  1886. * @brief Check if RXNE IT is enabled
  1887. * @rmtoll CR2 RXNEIE LL_I2S_IsEnabledIT_RXNE
  1888. * @param SPIx SPI Instance
  1889. * @retval State of bit (1 or 0).
  1890. */
  1891. __STATIC_INLINE uint32_t LL_I2S_IsEnabledIT_RXNE(SPI_TypeDef *SPIx)
  1892. {
  1893. return LL_SPI_IsEnabledIT_RXNE(SPIx);
  1894. }
  1895. /**
  1896. * @brief Check if TXE IT is enabled
  1897. * @rmtoll CR2 TXEIE LL_I2S_IsEnabledIT_TXE
  1898. * @param SPIx SPI Instance
  1899. * @retval State of bit (1 or 0).
  1900. */
  1901. __STATIC_INLINE uint32_t LL_I2S_IsEnabledIT_TXE(SPI_TypeDef *SPIx)
  1902. {
  1903. return LL_SPI_IsEnabledIT_TXE(SPIx);
  1904. }
  1905. /**
  1906. * @}
  1907. */
  1908. /** @defgroup I2S_LL_EF_DMA DMA Management
  1909. * @{
  1910. */
  1911. /**
  1912. * @brief Enable DMA Rx
  1913. * @rmtoll CR2 RXDMAEN LL_I2S_EnableDMAReq_RX
  1914. * @param SPIx SPI Instance
  1915. * @retval None
  1916. */
  1917. __STATIC_INLINE void LL_I2S_EnableDMAReq_RX(SPI_TypeDef *SPIx)
  1918. {
  1919. LL_SPI_EnableDMAReq_RX(SPIx);
  1920. }
  1921. /**
  1922. * @brief Disable DMA Rx
  1923. * @rmtoll CR2 RXDMAEN LL_I2S_DisableDMAReq_RX
  1924. * @param SPIx SPI Instance
  1925. * @retval None
  1926. */
  1927. __STATIC_INLINE void LL_I2S_DisableDMAReq_RX(SPI_TypeDef *SPIx)
  1928. {
  1929. LL_SPI_DisableDMAReq_RX(SPIx);
  1930. }
  1931. /**
  1932. * @brief Check if DMA Rx is enabled
  1933. * @rmtoll CR2 RXDMAEN LL_I2S_IsEnabledDMAReq_RX
  1934. * @param SPIx SPI Instance
  1935. * @retval State of bit (1 or 0).
  1936. */
  1937. __STATIC_INLINE uint32_t LL_I2S_IsEnabledDMAReq_RX(SPI_TypeDef *SPIx)
  1938. {
  1939. return LL_SPI_IsEnabledDMAReq_RX(SPIx);
  1940. }
  1941. /**
  1942. * @brief Enable DMA Tx
  1943. * @rmtoll CR2 TXDMAEN LL_I2S_EnableDMAReq_TX
  1944. * @param SPIx SPI Instance
  1945. * @retval None
  1946. */
  1947. __STATIC_INLINE void LL_I2S_EnableDMAReq_TX(SPI_TypeDef *SPIx)
  1948. {
  1949. LL_SPI_EnableDMAReq_TX(SPIx);
  1950. }
  1951. /**
  1952. * @brief Disable DMA Tx
  1953. * @rmtoll CR2 TXDMAEN LL_I2S_DisableDMAReq_TX
  1954. * @param SPIx SPI Instance
  1955. * @retval None
  1956. */
  1957. __STATIC_INLINE void LL_I2S_DisableDMAReq_TX(SPI_TypeDef *SPIx)
  1958. {
  1959. LL_SPI_DisableDMAReq_TX(SPIx);
  1960. }
  1961. /**
  1962. * @brief Check if DMA Tx is enabled
  1963. * @rmtoll CR2 TXDMAEN LL_I2S_IsEnabledDMAReq_TX
  1964. * @param SPIx SPI Instance
  1965. * @retval State of bit (1 or 0).
  1966. */
  1967. __STATIC_INLINE uint32_t LL_I2S_IsEnabledDMAReq_TX(SPI_TypeDef *SPIx)
  1968. {
  1969. return LL_SPI_IsEnabledDMAReq_TX(SPIx);
  1970. }
  1971. /**
  1972. * @}
  1973. */
  1974. /** @defgroup I2S_LL_EF_DATA DATA Management
  1975. * @{
  1976. */
  1977. /**
  1978. * @brief Read 16-Bits in data register
  1979. * @rmtoll DR DR LL_I2S_ReceiveData16
  1980. * @param SPIx SPI Instance
  1981. * @retval RxData Value between Min_Data=0x0000 and Max_Data=0xFFFF
  1982. */
  1983. __STATIC_INLINE uint16_t LL_I2S_ReceiveData16(SPI_TypeDef *SPIx)
  1984. {
  1985. return LL_SPI_ReceiveData16(SPIx);
  1986. }
  1987. /**
  1988. * @brief Write 16-Bits in data register
  1989. * @rmtoll DR DR LL_I2S_TransmitData16
  1990. * @param SPIx SPI Instance
  1991. * @param TxData Value between Min_Data=0x0000 and Max_Data=0xFFFF
  1992. * @retval None
  1993. */
  1994. __STATIC_INLINE void LL_I2S_TransmitData16(SPI_TypeDef *SPIx, uint16_t TxData)
  1995. {
  1996. LL_SPI_TransmitData16(SPIx, TxData);
  1997. }
  1998. /**
  1999. * @}
  2000. */
  2001. #if defined(USE_FULL_LL_DRIVER)
  2002. /** @defgroup I2S_LL_EF_Init Initialization and de-initialization functions
  2003. * @{
  2004. */
  2005. ErrorStatus LL_I2S_DeInit(SPI_TypeDef *SPIx);
  2006. ErrorStatus LL_I2S_Init(SPI_TypeDef *SPIx, LL_I2S_InitTypeDef *I2S_InitStruct);
  2007. void LL_I2S_StructInit(LL_I2S_InitTypeDef *I2S_InitStruct);
  2008. void LL_I2S_ConfigPrescaler(SPI_TypeDef *SPIx, uint32_t PrescalerLinear, uint32_t PrescalerParity);
  2009. /**
  2010. * @}
  2011. */
  2012. #endif /* USE_FULL_LL_DRIVER */
  2013. /**
  2014. * @}
  2015. */
  2016. /**
  2017. * @}
  2018. */
  2019. #endif /* SPI_I2S_SUPPORT */
  2020. #endif /* defined (SPI1) || defined (SPI2) || defined (SPI3) */
  2021. /**
  2022. * @}
  2023. */
  2024. #ifdef __cplusplus
  2025. }
  2026. #endif
  2027. #endif /* STM32G0xx_LL_SPI_H */