stm32g4xx_ll_spi.h 75 KB

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