1
0

stm32f1xx_ll_spi.h 62 KB

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