STM32L4xx_HAL_Driver  1.14.0
Initialization and de-initialization functions

Functions

ErrorStatus LL_LPUART_DeInit (USART_TypeDef *LPUARTx)
 De-initialize LPUART registers (Registers restored to their default values). More...
 
ErrorStatus LL_LPUART_Init (USART_TypeDef *LPUARTx, LL_LPUART_InitTypeDef *LPUART_InitStruct)
 Initialize LPUART registers according to the specified parameters in LPUART_InitStruct. More...
 
void LL_LPUART_StructInit (LL_LPUART_InitTypeDef *LPUART_InitStruct)
 Set each LL_LPUART_InitTypeDef field to default value. More...
 

Detailed Description

Function Documentation

◆ LL_LPUART_DeInit()

ErrorStatus LL_LPUART_DeInit ( USART_TypeDef *  LPUARTx)

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

Parameters
LPUARTxLPUART Instance
Return values
AnErrorStatus enumeration value:
  • SUCCESS: LPUART registers are de-initialized
  • ERROR: not applicable

Definition at line 132 of file stm32l4xx_ll_lpuart.c.

133 {
134  ErrorStatus status = SUCCESS;
135 
136  /* Check the parameters */
137  assert_param(IS_LPUART_INSTANCE(LPUARTx));
138 
139  if (LPUARTx == LPUART1)
140  {
141  /* Force reset of LPUART peripheral */
142  LL_APB1_GRP2_ForceReset(LL_APB1_GRP2_PERIPH_LPUART1);
143 
144  /* Release reset of LPUART peripheral */
145  LL_APB1_GRP2_ReleaseReset(LL_APB1_GRP2_PERIPH_LPUART1);
146  }
147  else
148  {
149  status = ERROR;
150  }
151 
152  return (status);
153 }
__STATIC_INLINE void LL_APB1_GRP2_ForceReset(uint32_t Periphs)
Force APB1 peripherals reset. APB1RSTR2 LPUART1RST LL_APB1_GRP2_ForceReset APB1RSTR2 I2C4RST LL_APB...
__STATIC_INLINE void LL_APB1_GRP2_ReleaseReset(uint32_t Periphs)
Release APB1 peripherals reset. APB1RSTR2 LPUART1RST LL_APB1_GRP2_ReleaseReset APB1RSTR2 I2C4RST LL...
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ LL_LPUART_Init()

ErrorStatus LL_LPUART_Init ( USART_TypeDef *  LPUARTx,
LL_LPUART_InitTypeDef LPUART_InitStruct 
)

Initialize LPUART registers according to the specified parameters in LPUART_InitStruct.

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

Definition at line 168 of file stm32l4xx_ll_lpuart.c.

169 {
170  ErrorStatus status = ERROR;
171  uint32_t periphclk;
172 
173  /* Check the parameters */
174  assert_param(IS_LPUART_INSTANCE(LPUARTx));
175 #if defined(USART_PRESC_PRESCALER)
176  assert_param(IS_LL_LPUART_PRESCALER(LPUART_InitStruct->PrescalerValue));
177 #endif /* USART_PRESC_PRESCALER */
178  assert_param(IS_LL_LPUART_BAUDRATE(LPUART_InitStruct->BaudRate));
179  assert_param(IS_LL_LPUART_DATAWIDTH(LPUART_InitStruct->DataWidth));
180  assert_param(IS_LL_LPUART_STOPBITS(LPUART_InitStruct->StopBits));
181  assert_param(IS_LL_LPUART_PARITY(LPUART_InitStruct->Parity));
182  assert_param(IS_LL_LPUART_DIRECTION(LPUART_InitStruct->TransferDirection));
183  assert_param(IS_LL_LPUART_HWCONTROL(LPUART_InitStruct->HardwareFlowControl));
184 
185  /* LPUART needs to be in disabled state, in order to be able to configure some bits in
186  CRx registers. Otherwise (LPUART not in Disabled state) => return ERROR */
187  if (LL_LPUART_IsEnabled(LPUARTx) == 0U)
188  {
189  /*---------------------------- LPUART CR1 Configuration -----------------------
190  * Configure LPUARTx CR1 (LPUART Word Length, Parity and Transfer Direction bits) with parameters:
191  * - DataWidth: USART_CR1_M bits according to LPUART_InitStruct->DataWidth value
192  * - Parity: USART_CR1_PCE, USART_CR1_PS bits according to LPUART_InitStruct->Parity value
193  * - TransferDirection: USART_CR1_TE, USART_CR1_RE bits according to LPUART_InitStruct->TransferDirection value
194  */
195  MODIFY_REG(LPUARTx->CR1,
196  (USART_CR1_M | USART_CR1_PCE | USART_CR1_PS | USART_CR1_TE | USART_CR1_RE),
197  (LPUART_InitStruct->DataWidth | LPUART_InitStruct->Parity | LPUART_InitStruct->TransferDirection));
198 
199  /*---------------------------- LPUART CR2 Configuration -----------------------
200  * Configure LPUARTx CR2 (Stop bits) with parameters:
201  * - Stop Bits: USART_CR2_STOP bits according to LPUART_InitStruct->StopBits value.
202  */
203  LL_LPUART_SetStopBitsLength(LPUARTx, LPUART_InitStruct->StopBits);
204 
205  /*---------------------------- LPUART CR3 Configuration -----------------------
206  * Configure LPUARTx CR3 (Hardware Flow Control) with parameters:
207  * - HardwareFlowControl: USART_CR3_RTSE, USART_CR3_CTSE bits according to LPUART_InitStruct->HardwareFlowControl value.
208  */
209  LL_LPUART_SetHWFlowCtrl(LPUARTx, LPUART_InitStruct->HardwareFlowControl);
210 
211  /*---------------------------- LPUART BRR Configuration -----------------------
212  * Retrieve Clock frequency used for LPUART Peripheral
213  */
214  periphclk = LL_RCC_GetLPUARTClockFreq(LL_RCC_LPUART1_CLKSOURCE);
215 
216  /* Configure the LPUART Baud Rate :
217  #if defined(USART_PRESC_PRESCALER)
218  - prescaler value is required
219  #endif
220  - valid baud rate value (different from 0) is required
221  - Peripheral clock as returned by RCC service, should be valid (different from 0).
222  */
223  if ((periphclk != LL_RCC_PERIPH_FREQUENCY_NO)
224  && (LPUART_InitStruct->BaudRate != 0U))
225  {
226  status = SUCCESS;
227  LL_LPUART_SetBaudRate(LPUARTx,
228  periphclk,
229 #if defined(USART_PRESC_PRESCALER)
230  LPUART_InitStruct->PrescalerValue,
231 #endif /* USART_PRESC_PRESCALER */
232  LPUART_InitStruct->BaudRate);
233 
234  /* Check BRR is greater than or equal to 0x300 */
235  assert_param(IS_LL_LPUART_BRR_MIN(LPUARTx->BRR));
236 
237  /* Check BRR is lower than or equal to 0xFFFFF */
238  assert_param(IS_LL_LPUART_BRR_MAX(LPUARTx->BRR));
239  }
240 
241 #if defined(USART_PRESC_PRESCALER)
242  /*---------------------------- LPUART PRESC Configuration -----------------------
243  * Configure LPUARTx PRESC (Prescaler) with parameters:
244  * - PrescalerValue: LPUART_PRESC_PRESCALER bits according to LPUART_InitStruct->PrescalerValue value.
245  */
246  LL_LPUART_SetPrescaler(LPUARTx, LPUART_InitStruct->PrescalerValue);
247 #endif /* USART_PRESC_PRESCALER */
248  }
249 
250  return (status);
251 }
__STATIC_INLINE void LL_LPUART_SetHWFlowCtrl(USART_TypeDef *LPUARTx, uint32_t HardwareFlowControl)
Configure HW Flow Control mode (both CTS and RTS) CR3 RTSE LL_LPUART_SetHWFlowCtrl CR3 CTSE LL_LPUA...
__STATIC_INLINE void LL_LPUART_SetBaudRate(USART_TypeDef *LPUARTx, uint32_t PeriphClk, uint32_t PrescalerValue, uint32_t BaudRate) __STATIC_INLINE void LL_LPUART_SetBaudRate(USART_TypeDef *LPUARTx
Configure LPUART BRR register for achieving expected Baud Rate value.
__STATIC_INLINE void LL_LPUART_SetStopBitsLength(USART_TypeDef *LPUARTx, uint32_t StopBits)
Set the length of the stop bits CR2 STOP LL_LPUART_SetStopBitsLength.
__STATIC_INLINE uint32_t LL_LPUART_IsEnabled(USART_TypeDef *LPUARTx)
Indicate if LPUART is enabled CR1 UE LL_LPUART_IsEnabled.
uint32_t LL_RCC_GetLPUARTClockFreq(uint32_t LPUARTxSource)
Return LPUARTx clock frequency.
__STATIC_INLINE void LL_LPUART_SetPrescaler(USART_TypeDef *LPUARTx, uint32_t PrescalerValue)
Configure Clock source prescaler for baudrate generator and oversampling PRESC PRESCALER LL_LPUART_S...
ADC handle Structure definition.
MODIFY_REG(hrtc->Instance->CR, RTC_CR_WUCKSEL,(uint32_t) WakeUpClock)
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ LL_LPUART_StructInit()

void LL_LPUART_StructInit ( LL_LPUART_InitTypeDef LPUART_InitStruct)

Set each LL_LPUART_InitTypeDef field to default value.

Parameters
LPUART_InitStructpointer to a LL_LPUART_InitTypeDef structure whose fields will be set to default values.
Return values
None

Definition at line 260 of file stm32l4xx_ll_lpuart.c.

261 {
262  /* Set LPUART_InitStruct fields to default values */
263 #if defined(USART_PRESC_PRESCALER)
264  LPUART_InitStruct->PrescalerValue = LL_LPUART_PRESCALER_DIV1;
265 #endif /* USART_PRESC_PRESCALER */
266  LPUART_InitStruct->BaudRate = 9600U;
267  LPUART_InitStruct->DataWidth = LL_LPUART_DATAWIDTH_8B;
268  LPUART_InitStruct->StopBits = LL_LPUART_STOPBITS_1;
269  LPUART_InitStruct->Parity = LL_LPUART_PARITY_NONE ;
270  LPUART_InitStruct->TransferDirection = LL_LPUART_DIRECTION_TX_RX;
271  LPUART_InitStruct->HardwareFlowControl = LL_LPUART_HWCONTROL_NONE;
272 }