STM32L4xx_HAL_Driver  1.14.0
Initialization and de-initialization functions

Functions

ErrorStatus LL_SPI_DeInit (SPI_TypeDef *SPIx)
 De-initialize the SPI registers to their default reset values. More...
 
ErrorStatus LL_SPI_Init (SPI_TypeDef *SPIx, LL_SPI_InitTypeDef *SPI_InitStruct)
 Initialize the SPI registers according to the specified parameters in SPI_InitStruct. More...
 
void LL_SPI_StructInit (LL_SPI_InitTypeDef *SPI_InitStruct)
 Set each LL_SPI_InitTypeDef field to default value. More...
 

Detailed Description

Function Documentation

◆ LL_SPI_DeInit()

ErrorStatus LL_SPI_DeInit ( SPI_TypeDef *  SPIx)

De-initialize the SPI registers to their default reset values.

Parameters
SPIxSPI Instance
Return values
AnErrorStatus enumeration value:
  • SUCCESS: SPI registers are de-initialized
  • ERROR: SPI registers are not de-initialized

Definition at line 133 of file stm32l4xx_ll_spi.c.

134 {
135  ErrorStatus status = ERROR;
136 
137  /* Check the parameters */
138  assert_param(IS_SPI_ALL_INSTANCE(SPIx));
139 
140 #if defined(SPI1)
141  if (SPIx == SPI1)
142  {
143  /* Force reset of SPI clock */
144  LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_SPI1);
145 
146  /* Release reset of SPI clock */
147  LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_SPI1);
148 
149  status = SUCCESS;
150  }
151 #endif /* SPI1 */
152 #if defined(SPI2)
153  if (SPIx == SPI2)
154  {
155  /* Force reset of SPI clock */
156  LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_SPI2);
157 
158  /* Release reset of SPI clock */
159  LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_SPI2);
160 
161  status = SUCCESS;
162  }
163 #endif /* SPI2 */
164 #if defined(SPI3)
165  if (SPIx == SPI3)
166  {
167  /* Force reset of SPI clock */
168  LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_SPI3);
169 
170  /* Release reset of SPI clock */
171  LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_SPI3);
172 
173  status = SUCCESS;
174  }
175 #endif /* SPI3 */
176 
177  return status;
178 }
__STATIC_INLINE void LL_APB2_GRP1_ReleaseReset(uint32_t Periphs)
Release APB2 peripherals reset. APB2RSTR SYSCFGRST LL_APB2_GRP1_ReleaseReset APB2RSTR SDMMC1RST LL_...
__STATIC_INLINE void LL_APB1_GRP1_ReleaseReset(uint32_t Periphs)
Release APB1 peripherals reset. APB1RSTR1 TIM2RST LL_APB1_GRP1_ReleaseReset APB1RSTR1 TIM3RST LL_AP...
__STATIC_INLINE void LL_APB2_GRP1_ForceReset(uint32_t Periphs)
Force APB2 peripherals reset. APB2RSTR SYSCFGRST LL_APB2_GRP1_ForceReset APB2RSTR SDMMC1RST LL_APB2...
__STATIC_INLINE void LL_APB1_GRP1_ForceReset(uint32_t Periphs)
Force APB1 peripherals reset. APB1RSTR1 TIM2RST LL_APB1_GRP1_ForceReset APB1RSTR1 TIM3RST LL_APB1_G...
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ LL_SPI_Init()

ErrorStatus LL_SPI_Init ( SPI_TypeDef *  SPIx,
LL_SPI_InitTypeDef SPI_InitStruct 
)

Initialize the SPI registers according to the specified parameters in SPI_InitStruct.

Note
As some bits in SPI configuration registers can only be written when the SPI is disabled (SPI_CR1_SPE bit =0), SPI peripheral should be in disabled state prior calling this function. Otherwise, ERROR result will be returned.
Parameters
SPIxSPI Instance
SPI_InitStructpointer to a LL_SPI_InitTypeDef structure
Return values
AnErrorStatus enumeration value. (Return always SUCCESS)

Definition at line 188 of file stm32l4xx_ll_spi.c.

189 {
190  ErrorStatus status = ERROR;
191 
192  /* Check the SPI Instance SPIx*/
193  assert_param(IS_SPI_ALL_INSTANCE(SPIx));
194 
195  /* Check the SPI parameters from SPI_InitStruct*/
196  assert_param(IS_LL_SPI_TRANSFER_DIRECTION(SPI_InitStruct->TransferDirection));
197  assert_param(IS_LL_SPI_MODE(SPI_InitStruct->Mode));
198  assert_param(IS_LL_SPI_DATAWIDTH(SPI_InitStruct->DataWidth));
199  assert_param(IS_LL_SPI_POLARITY(SPI_InitStruct->ClockPolarity));
200  assert_param(IS_LL_SPI_PHASE(SPI_InitStruct->ClockPhase));
201  assert_param(IS_LL_SPI_NSS(SPI_InitStruct->NSS));
202  assert_param(IS_LL_SPI_BAUDRATE(SPI_InitStruct->BaudRate));
203  assert_param(IS_LL_SPI_BITORDER(SPI_InitStruct->BitOrder));
204  assert_param(IS_LL_SPI_CRCCALCULATION(SPI_InitStruct->CRCCalculation));
205 
206  if (LL_SPI_IsEnabled(SPIx) == 0x00000000U)
207  {
208  /*---------------------------- SPIx CR1 Configuration ------------------------
209  * Configure SPIx CR1 with parameters:
210  * - TransferDirection: SPI_CR1_BIDIMODE, SPI_CR1_BIDIOE and SPI_CR1_RXONLY bits
211  * - Master/Slave Mode: SPI_CR1_MSTR bit
212  * - ClockPolarity: SPI_CR1_CPOL bit
213  * - ClockPhase: SPI_CR1_CPHA bit
214  * - NSS management: SPI_CR1_SSM bit
215  * - BaudRate prescaler: SPI_CR1_BR[2:0] bits
216  * - BitOrder: SPI_CR1_LSBFIRST bit
217  * - CRCCalculation: SPI_CR1_CRCEN bit
218  */
219  MODIFY_REG(SPIx->CR1,
220  SPI_CR1_CLEAR_MASK,
221  SPI_InitStruct->TransferDirection | SPI_InitStruct->Mode |
222  SPI_InitStruct->ClockPolarity | SPI_InitStruct->ClockPhase |
223  SPI_InitStruct->NSS | SPI_InitStruct->BaudRate |
224  SPI_InitStruct->BitOrder | SPI_InitStruct->CRCCalculation);
225 
226  /*---------------------------- SPIx CR2 Configuration ------------------------
227  * Configure SPIx CR2 with parameters:
228  * - DataWidth: DS[3:0] bits
229  * - NSS management: SSOE bit
230  */
231  MODIFY_REG(SPIx->CR2,
232  SPI_CR2_DS | SPI_CR2_SSOE,
233  SPI_InitStruct->DataWidth | (SPI_InitStruct->NSS >> 16U));
234 
235  /*---------------------------- SPIx CRCPR Configuration ----------------------
236  * Configure SPIx CRCPR with parameters:
237  * - CRCPoly: CRCPOLY[15:0] bits
238  */
239  if (SPI_InitStruct->CRCCalculation == LL_SPI_CRCCALCULATION_ENABLE)
240  {
241  assert_param(IS_LL_SPI_CRC_POLYNOMIAL(SPI_InitStruct->CRCPoly));
242  LL_SPI_SetCRCPolynomial(SPIx, SPI_InitStruct->CRCPoly);
243  }
244  status = SUCCESS;
245  }
246 
247  return status;
248 }
__STATIC_INLINE uint32_t LL_SPI_IsEnabled(SPI_TypeDef *SPIx)
Check if SPI peripheral is enabled CR1 SPE LL_SPI_IsEnabled.
__STATIC_INLINE void LL_SPI_SetCRCPolynomial(SPI_TypeDef *SPIx, uint32_t CRCPoly)
Set polynomial for CRC calculation CRCPR CRCPOLY LL_SPI_SetCRCPolynomial.
MODIFY_REG(hrtc->Instance->CR, RTC_CR_WUCKSEL,(uint32_t) WakeUpClock)
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ LL_SPI_StructInit()

void LL_SPI_StructInit ( LL_SPI_InitTypeDef SPI_InitStruct)

Set each LL_SPI_InitTypeDef field to default value.

Parameters
SPI_InitStructpointer to a LL_SPI_InitTypeDef structure whose fields will be set to default values.
Return values
None

Definition at line 256 of file stm32l4xx_ll_spi.c.

257 {
258  /* Set SPI_InitStruct fields to default values */
259  SPI_InitStruct->TransferDirection = LL_SPI_FULL_DUPLEX;
260  SPI_InitStruct->Mode = LL_SPI_MODE_SLAVE;
261  SPI_InitStruct->DataWidth = LL_SPI_DATAWIDTH_8BIT;
262  SPI_InitStruct->ClockPolarity = LL_SPI_POLARITY_LOW;
263  SPI_InitStruct->ClockPhase = LL_SPI_PHASE_1EDGE;
264  SPI_InitStruct->NSS = LL_SPI_NSS_HARD_INPUT;
265  SPI_InitStruct->BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV2;
266  SPI_InitStruct->BitOrder = LL_SPI_MSB_FIRST;
267  SPI_InitStruct->CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE;
268  SPI_InitStruct->CRCPoly = 7U;
269 }