stm32f7xx_ll_spi.h 75 KB

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