STM32L4xx_HAL_Driver  1.14.0

Functions

ErrorStatus LL_USART_DeInit (USART_TypeDef *USARTx)
 De-initialize USART registers (Registers restored to their default values). More...
 
ErrorStatus LL_USART_Init (USART_TypeDef *USARTx, LL_USART_InitTypeDef *USART_InitStruct)
 Initialize USART registers according to the specified parameters in USART_InitStruct. More...
 
void LL_USART_StructInit (LL_USART_InitTypeDef *USART_InitStruct)
 Set each LL_USART_InitTypeDef field to default value. More...
 
ErrorStatus LL_USART_ClockInit (USART_TypeDef *USARTx, LL_USART_ClockInitTypeDef *USART_ClockInitStruct)
 Initialize USART Clock related settings according to the specified parameters in the USART_ClockInitStruct. More...
 
void LL_USART_ClockStructInit (LL_USART_ClockInitTypeDef *USART_ClockInitStruct)
 Set each field of a LL_USART_ClockInitTypeDef type structure to default value. More...
 

Detailed Description

Function Documentation

◆ LL_USART_ClockInit()

ErrorStatus LL_USART_ClockInit ( USART_TypeDef *  USARTx,
LL_USART_ClockInitTypeDef USART_ClockInitStruct 
)

Initialize USART Clock related settings according to the specified parameters in the USART_ClockInitStruct.

Note
As some bits in USART configuration registers can only be written when the USART is disabled (USART_CR1_UE bit =0), USART Peripheral should be in disabled state prior calling this function. Otherwise, ERROR result will be returned.
Parameters
USARTxUSART Instance
USART_ClockInitStructpointer to a LL_USART_ClockInitTypeDef structure that contains the Clock configuration information for the specified USART peripheral.
Return values
AnErrorStatus enumeration value:
  • SUCCESS: USART registers related to Clock settings are initialized according to USART_ClockInitStruct content
  • ERROR: Problem occurred during USART Registers initialization

Definition at line 375 of file stm32l4xx_ll_usart.c.

376 {
377  ErrorStatus status = SUCCESS;
378 
379  /* Check USART Instance and Clock signal output parameters */
380  assert_param(IS_UART_INSTANCE(USARTx));
381  assert_param(IS_LL_USART_CLOCKOUTPUT(USART_ClockInitStruct->ClockOutput));
382 
383  /* USART needs to be in disabled state, in order to be able to configure some bits in
384  CRx registers */
385  if (LL_USART_IsEnabled(USARTx) == 0U)
386  {
387  /*---------------------------- USART CR2 Configuration -----------------------*/
388  /* If Clock signal has to be output */
389  if (USART_ClockInitStruct->ClockOutput == LL_USART_CLOCK_DISABLE)
390  {
391  /* Deactivate Clock signal delivery :
392  * - Disable Clock Output: USART_CR2_CLKEN cleared
393  */
395  }
396  else
397  {
398  /* Ensure USART instance is USART capable */
399  assert_param(IS_USART_INSTANCE(USARTx));
400 
401  /* Check clock related parameters */
402  assert_param(IS_LL_USART_CLOCKPOLARITY(USART_ClockInitStruct->ClockPolarity));
403  assert_param(IS_LL_USART_CLOCKPHASE(USART_ClockInitStruct->ClockPhase));
404  assert_param(IS_LL_USART_LASTBITCLKOUTPUT(USART_ClockInitStruct->LastBitClockPulse));
405 
406  /*---------------------------- USART CR2 Configuration -----------------------
407  * Configure USARTx CR2 (Clock signal related bits) with parameters:
408  * - Enable Clock Output: USART_CR2_CLKEN set
409  * - Clock Polarity: USART_CR2_CPOL bit according to USART_ClockInitStruct->ClockPolarity value
410  * - Clock Phase: USART_CR2_CPHA bit according to USART_ClockInitStruct->ClockPhase value
411  * - Last Bit Clock Pulse Output: USART_CR2_LBCL bit according to USART_ClockInitStruct->LastBitClockPulse value.
412  */
413  MODIFY_REG(USARTx->CR2,
414  USART_CR2_CLKEN | USART_CR2_CPHA | USART_CR2_CPOL | USART_CR2_LBCL,
415  USART_CR2_CLKEN | USART_ClockInitStruct->ClockPolarity |
416  USART_ClockInitStruct->ClockPhase | USART_ClockInitStruct->LastBitClockPulse);
417  }
418  }
419  /* Else (USART not in Disabled state => return ERROR */
420  else
421  {
422  status = ERROR;
423  }
424 
425  return (status);
426 }
__STATIC_INLINE void LL_USART_DisableSCLKOutput(USART_TypeDef *USARTx)
Disable Clock output on SCLK pin.
__STATIC_INLINE uint32_t LL_USART_IsEnabled(USART_TypeDef *USARTx)
Indicate if USART is enabled CR1 UE LL_USART_IsEnabled.
MODIFY_REG(hrtc->Instance->CR, RTC_CR_WUCKSEL,(uint32_t) WakeUpClock)
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ LL_USART_ClockStructInit()

void LL_USART_ClockStructInit ( LL_USART_ClockInitTypeDef USART_ClockInitStruct)

Set each field of a LL_USART_ClockInitTypeDef type structure to default value.

Parameters
USART_ClockInitStructpointer to a LL_USART_ClockInitTypeDef structure whose fields will be set to default values.
Return values
None

Definition at line 434 of file stm32l4xx_ll_usart.c.

435 {
436  /* Set LL_USART_ClockInitStruct fields with default values */
437  USART_ClockInitStruct->ClockOutput = LL_USART_CLOCK_DISABLE;
438  USART_ClockInitStruct->ClockPolarity = LL_USART_POLARITY_LOW; /* Not relevant when ClockOutput = LL_USART_CLOCK_DISABLE */
439  USART_ClockInitStruct->ClockPhase = LL_USART_PHASE_1EDGE; /* Not relevant when ClockOutput = LL_USART_CLOCK_DISABLE */
440  USART_ClockInitStruct->LastBitClockPulse = LL_USART_LASTCLKPULSE_NO_OUTPUT; /* Not relevant when ClockOutput = LL_USART_CLOCK_DISABLE */
441 }

◆ LL_USART_DeInit()

ErrorStatus LL_USART_DeInit ( USART_TypeDef *  USARTx)

De-initialize USART registers (Registers restored to their default values).

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

Definition at line 146 of file stm32l4xx_ll_usart.c.

147 {
148  ErrorStatus status = SUCCESS;
149 
150  /* Check the parameters */
151  assert_param(IS_UART_INSTANCE(USARTx));
152 
153  if (USARTx == USART1)
154  {
155  /* Force reset of USART clock */
156  LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_USART1);
157 
158  /* Release reset of USART clock */
159  LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_USART1);
160  }
161  else if (USARTx == USART2)
162  {
163  /* Force reset of USART clock */
164  LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_USART2);
165 
166  /* Release reset of USART clock */
167  LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_USART2);
168  }
169 #if defined(USART3)
170  else if (USARTx == USART3)
171  {
172  /* Force reset of USART clock */
173  LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_USART3);
174 
175  /* Release reset of USART clock */
176  LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_USART3);
177  }
178 #endif /* USART3 */
179 #if defined(UART4)
180  else if (USARTx == UART4)
181  {
182  /* Force reset of UART clock */
183  LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_UART4);
184 
185  /* Release reset of UART clock */
186  LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_UART4);
187  }
188 #endif /* UART4 */
189 #if defined(UART5)
190  else if (USARTx == UART5)
191  {
192  /* Force reset of UART clock */
193  LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_UART5);
194 
195  /* Release reset of UART clock */
196  LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_UART5);
197  }
198 #endif /* UART5 */
199  else
200  {
201  status = ERROR;
202  }
203 
204  return (status);
205 }
__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_USART_Init()

ErrorStatus LL_USART_Init ( USART_TypeDef *  USARTx,
LL_USART_InitTypeDef USART_InitStruct 
)

Initialize USART registers according to the specified parameters in USART_InitStruct.

Note
As some bits in USART configuration registers can only be written when the USART is disabled (USART_CR1_UE bit =0), USART Peripheral should be in disabled state prior calling this function. Otherwise, ERROR result will be returned.
Baud rate value stored in USART_InitStruct BaudRate field, should be valid (different from 0).
Parameters
USARTxUSART Instance
USART_InitStructpointer to a LL_USART_InitTypeDef structure that contains the configuration information for the specified USART peripheral.
Return values
AnErrorStatus enumeration value:
  • SUCCESS: USART registers are initialized according to USART_InitStruct content
  • ERROR: Problem occurred during USART Registers initialization

Definition at line 220 of file stm32l4xx_ll_usart.c.

221 {
222  ErrorStatus status = ERROR;
223  uint32_t periphclk = LL_RCC_PERIPH_FREQUENCY_NO;
224 
225  /* Check the parameters */
226  assert_param(IS_UART_INSTANCE(USARTx));
227 #if defined(USART_PRESC_PRESCALER)
228  assert_param(IS_LL_USART_PRESCALER(USART_InitStruct->PrescalerValue));
229 #endif /* USART_PRESC_PRESCALER */
230  assert_param(IS_LL_USART_BAUDRATE(USART_InitStruct->BaudRate));
231  assert_param(IS_LL_USART_DATAWIDTH(USART_InitStruct->DataWidth));
232  assert_param(IS_LL_USART_STOPBITS(USART_InitStruct->StopBits));
233  assert_param(IS_LL_USART_PARITY(USART_InitStruct->Parity));
234  assert_param(IS_LL_USART_DIRECTION(USART_InitStruct->TransferDirection));
235  assert_param(IS_LL_USART_HWCONTROL(USART_InitStruct->HardwareFlowControl));
236  assert_param(IS_LL_USART_OVERSAMPLING(USART_InitStruct->OverSampling));
237 
238  /* USART needs to be in disabled state, in order to be able to configure some bits in
239  CRx registers */
240  if (LL_USART_IsEnabled(USARTx) == 0U)
241  {
242  /*---------------------------- USART CR1 Configuration ---------------------
243  * Configure USARTx CR1 (USART Word Length, Parity, Mode and Oversampling bits) with parameters:
244  * - DataWidth: USART_CR1_M bits according to USART_InitStruct->DataWidth value
245  * - Parity: USART_CR1_PCE, USART_CR1_PS bits according to USART_InitStruct->Parity value
246  * - TransferDirection: USART_CR1_TE, USART_CR1_RE bits according to USART_InitStruct->TransferDirection value
247  * - Oversampling: USART_CR1_OVER8 bit according to USART_InitStruct->OverSampling value.
248  */
249  MODIFY_REG(USARTx->CR1,
250  (USART_CR1_M | USART_CR1_PCE | USART_CR1_PS |
251  USART_CR1_TE | USART_CR1_RE | USART_CR1_OVER8),
252  (USART_InitStruct->DataWidth | USART_InitStruct->Parity |
253  USART_InitStruct->TransferDirection | USART_InitStruct->OverSampling));
254 
255  /*---------------------------- USART CR2 Configuration ---------------------
256  * Configure USARTx CR2 (Stop bits) with parameters:
257  * - Stop Bits: USART_CR2_STOP bits according to USART_InitStruct->StopBits value.
258  * - CLKEN, CPOL, CPHA and LBCL bits are to be configured using LL_USART_ClockInit().
259  */
260  LL_USART_SetStopBitsLength(USARTx, USART_InitStruct->StopBits);
261 
262  /*---------------------------- USART CR3 Configuration ---------------------
263  * Configure USARTx CR3 (Hardware Flow Control) with parameters:
264  * - HardwareFlowControl: USART_CR3_RTSE, USART_CR3_CTSE bits according to USART_InitStruct->HardwareFlowControl value.
265  */
266  LL_USART_SetHWFlowCtrl(USARTx, USART_InitStruct->HardwareFlowControl);
267 
268  /*---------------------------- USART BRR Configuration ---------------------
269  * Retrieve Clock frequency used for USART Peripheral
270  */
271  if (USARTx == USART1)
272  {
273  periphclk = LL_RCC_GetUSARTClockFreq(LL_RCC_USART1_CLKSOURCE);
274  }
275  else if (USARTx == USART2)
276  {
277  periphclk = LL_RCC_GetUSARTClockFreq(LL_RCC_USART2_CLKSOURCE);
278  }
279 #if defined(USART3)
280  else if (USARTx == USART3)
281  {
282  periphclk = LL_RCC_GetUSARTClockFreq(LL_RCC_USART3_CLKSOURCE);
283  }
284 #endif /* USART3 */
285 #if defined(UART4)
286  else if (USARTx == UART4)
287  {
288  periphclk = LL_RCC_GetUARTClockFreq(LL_RCC_UART4_CLKSOURCE);
289  }
290 #endif /* UART4 */
291 #if defined(UART5)
292  else if (USARTx == UART5)
293  {
294  periphclk = LL_RCC_GetUARTClockFreq(LL_RCC_UART5_CLKSOURCE);
295  }
296 #endif /* UART5 */
297  else
298  {
299  /* Nothing to do, as error code is already assigned to ERROR value */
300  }
301 
302  /* Configure the USART Baud Rate :
303  #if defined(USART_PRESC_PRESCALER)
304  - prescaler value is required
305  #endif
306  - valid baud rate value (different from 0) is required
307  - Peripheral clock as returned by RCC service, should be valid (different from 0).
308  */
309  if ((periphclk != LL_RCC_PERIPH_FREQUENCY_NO)
310  && (USART_InitStruct->BaudRate != 0U))
311  {
312  status = SUCCESS;
313  LL_USART_SetBaudRate(USARTx,
314  periphclk,
315 #if defined(USART_PRESC_PRESCALER)
316  USART_InitStruct->PrescalerValue,
317 #endif /* USART_PRESC_PRESCALER */
318  USART_InitStruct->OverSampling,
319  USART_InitStruct->BaudRate);
320 
321  /* Check BRR is greater than or equal to 16d */
322  assert_param(IS_LL_USART_BRR_MIN(USARTx->BRR));
323 
324  /* Check BRR is lower than or equal to 0xFFFF */
325  assert_param(IS_LL_USART_BRR_MAX(USARTx->BRR));
326  }
327 #if defined(USART_PRESC_PRESCALER)
328 
329  /*---------------------------- USART PRESC Configuration -----------------------
330  * Configure USARTx PRESC (Prescaler) with parameters:
331  * - PrescalerValue: USART_PRESC_PRESCALER bits according to USART_InitStruct->PrescalerValue value.
332  */
333  LL_USART_SetPrescaler(USARTx, USART_InitStruct->PrescalerValue);
334 #endif /* USART_PRESC_PRESCALER */
335  }
336  /* Endif (=> USART not in Disabled state => return ERROR) */
337 
338  return (status);
339 }
__STATIC_INLINE void LL_USART_SetPrescaler(USART_TypeDef *USARTx, uint32_t PrescalerValue)
Configure Clock source prescaler for baudrate generator and oversampling.
uint32_t LL_RCC_GetUARTClockFreq(uint32_t UARTxSource)
Return UARTx clock frequency.
__STATIC_INLINE void LL_USART_SetStopBitsLength(USART_TypeDef *USARTx, uint32_t StopBits)
Set the length of the stop bits CR2 STOP LL_USART_SetStopBitsLength.
uint32_t LL_RCC_GetUSARTClockFreq(uint32_t USARTxSource)
Return USARTx clock frequency.
__STATIC_INLINE uint32_t LL_USART_IsEnabled(USART_TypeDef *USARTx)
Indicate if USART is enabled CR1 UE LL_USART_IsEnabled.
__STATIC_INLINE void LL_USART_SetHWFlowCtrl(USART_TypeDef *USARTx, uint32_t HardwareFlowControl)
Configure HW Flow Control mode (both CTS and RTS)
__STATIC_INLINE void LL_USART_SetBaudRate(USART_TypeDef *USARTx, uint32_t PeriphClk, uint32_t PrescalerValue, uint32_t OverSampling, uint32_t BaudRate) __STATIC_INLINE void LL_USART_SetBaudRate(USART_TypeDef *USARTx
Configure USART BRR register for achieving expected Baud Rate value.
ADC handle Structure definition.
MODIFY_REG(hrtc->Instance->CR, RTC_CR_WUCKSEL,(uint32_t) WakeUpClock)
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ LL_USART_StructInit()

void LL_USART_StructInit ( LL_USART_InitTypeDef USART_InitStruct)

Set each LL_USART_InitTypeDef field to default value.

Parameters
USART_InitStructpointer to a LL_USART_InitTypeDef structure whose fields will be set to default values.
Return values
None

Definition at line 348 of file stm32l4xx_ll_usart.c.

349 {
350  /* Set USART_InitStruct fields to default values */
351 #if defined(USART_PRESC_PRESCALER)
352  USART_InitStruct->PrescalerValue = LL_USART_PRESCALER_DIV1;
353 #endif /* USART_PRESC_PRESCALER */
354  USART_InitStruct->BaudRate = 9600U;
355  USART_InitStruct->DataWidth = LL_USART_DATAWIDTH_8B;
356  USART_InitStruct->StopBits = LL_USART_STOPBITS_1;
357  USART_InitStruct->Parity = LL_USART_PARITY_NONE ;
358  USART_InitStruct->TransferDirection = LL_USART_DIRECTION_TX_RX;
359  USART_InitStruct->HardwareFlowControl = LL_USART_HWCONTROL_NONE;
360  USART_InitStruct->OverSampling = LL_USART_OVERSAMPLING_16;
361 }