STM32L4xx_HAL_Driver  1.14.0
Peripheral Control functions

Extended Peripheral Control functions. More...

Functions

HAL_StatusTypeDef HAL_UARTEx_StopModeWakeUpSourceConfig (UART_HandleTypeDef *huart, UART_WakeUpTypeDef WakeUpSelection)
 Set Wakeup from Stop mode interrupt flag selection. More...
 
HAL_StatusTypeDef HAL_UARTEx_EnableStopMode (UART_HandleTypeDef *huart)
 Enable UART Stop Mode. More...
 
HAL_StatusTypeDef HAL_UARTEx_DisableStopMode (UART_HandleTypeDef *huart)
 Disable UART Stop Mode. More...
 
HAL_StatusTypeDef HAL_UARTEx_EnableClockStopMode (UART_HandleTypeDef *huart)
 Keep UART Clock enabled when in Stop Mode. More...
 
HAL_StatusTypeDef HAL_UARTEx_DisableClockStopMode (UART_HandleTypeDef *huart)
 Disable UART Clock when in Stop Mode. More...
 
HAL_StatusTypeDef HAL_MultiProcessorEx_AddressLength_Set (UART_HandleTypeDef *huart, uint32_t AddressLength)
 By default in multiprocessor mode, when the wake up method is set to address mark, the UART handles only 4-bit long addresses detection; this API allows to enable longer addresses detection (6-, 7- or 8-bit long). More...
 
HAL_StatusTypeDef HAL_UARTEx_EnableFifoMode (UART_HandleTypeDef *huart)
 Enable the FIFO mode. More...
 
HAL_StatusTypeDef HAL_UARTEx_DisableFifoMode (UART_HandleTypeDef *huart)
 Disable the FIFO mode. More...
 
HAL_StatusTypeDef HAL_UARTEx_SetTxFifoThreshold (UART_HandleTypeDef *huart, uint32_t Threshold)
 Set the TXFIFO threshold. More...
 
HAL_StatusTypeDef HAL_UARTEx_SetRxFifoThreshold (UART_HandleTypeDef *huart, uint32_t Threshold)
 Set the RXFIFO threshold. More...
 

Detailed Description

Extended Peripheral Control functions.

 ===============================================================================
                      ##### Peripheral Control functions #####
 ===============================================================================
    [..] This section provides the following functions:
     (+) HAL_UARTEx_EnableClockStopMode() API enables the UART clock (HSI or LSE only) during stop mode
     (+) HAL_UARTEx_DisableClockStopMode() API disables the above functionality
     (+) HAL_MultiProcessorEx_AddressLength_Set() API optionally sets the UART node address
         detection length to more than 4 bits for multiprocessor address mark wake up.
     (+) HAL_UARTEx_StopModeWakeUpSourceConfig() API defines the wake-up from stop mode
         trigger: address match, Start Bit detection or RXNE bit status.
     (+) HAL_UARTEx_EnableStopMode() API enables the UART to wake up the MCU from stop mode
     (+) HAL_UARTEx_DisableStopMode() API disables the above functionality
     (+) HAL_UARTEx_EnableFifoMode() API enables the FIFO mode
     (+) HAL_UARTEx_DisableFifoMode() API disables the FIFO mode
     (+) HAL_UARTEx_SetTxFifoThreshold() API sets the TX FIFO threshold
     (+) HAL_UARTEx_SetRxFifoThreshold() API sets the RX FIFO threshold

Function Documentation

◆ HAL_MultiProcessorEx_AddressLength_Set()

HAL_StatusTypeDef HAL_MultiProcessorEx_AddressLength_Set ( UART_HandleTypeDef huart,
uint32_t  AddressLength 
)

By default in multiprocessor mode, when the wake up method is set to address mark, the UART handles only 4-bit long addresses detection; this API allows to enable longer addresses detection (6-, 7- or 8-bit long).

Note
Addresses detection lengths are: 6-bit address detection in 7-bit data mode, 7-bit address detection in 8-bit data mode, 8-bit address detection in 9-bit data mode.
Parameters
huartUART handle.
AddressLengthThis parameter can be one of the following values:
  • UART_ADDRESS_DETECT_4B 4-bit long address
  • UART_ADDRESS_DETECT_7B 6-, 7- or 8-bit long address
Return values
HALstatus

Definition at line 406 of file stm32l4xx_hal_uart_ex.c.

407 {
408  /* Check the UART handle allocation */
409  if (huart == NULL)
410  {
411  return HAL_ERROR;
412  }
413 
414  /* Check the address length parameter */
415  assert_param(IS_UART_ADDRESSLENGTH_DETECT(AddressLength));
416 
417  huart->gState = HAL_UART_STATE_BUSY;
418 
419  /* Disable the Peripheral */
420  __HAL_UART_DISABLE(huart);
421 
422  /* Set the address length */
423  MODIFY_REG(huart->Instance->CR2, USART_CR2_ADDM7, AddressLength);
424 
425  /* Enable the Peripheral */
426  __HAL_UART_ENABLE(huart);
427 
428  /* TEACK and/or REACK to check before moving huart->gState to Ready */
429  return (UART_CheckIdleState(huart));
430 }
HAL_StatusTypeDef UART_CheckIdleState(UART_HandleTypeDef *huart)
Check the UART Idle State.
USART_TypeDef * Instance
MODIFY_REG(hrtc->Instance->CR, RTC_CR_WUCKSEL,(uint32_t) WakeUpClock)
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))
__IO HAL_UART_StateTypeDef gState

◆ HAL_UARTEx_DisableClockStopMode()

HAL_StatusTypeDef HAL_UARTEx_DisableClockStopMode ( UART_HandleTypeDef huart)

Disable UART Clock when in Stop Mode.

Parameters
huartUART handle.
Return values
HALstatus

Definition at line 378 of file stm32l4xx_hal_uart_ex.c.

379 {
380  /* Process Locked */
381  __HAL_LOCK(huart);
382 
383  /* Clear UCESM bit */
384  CLEAR_BIT(huart->Instance->CR3, USART_CR3_UCESM);
385 
386  /* Process Unlocked */
387  __HAL_UNLOCK(huart);
388 
389  return HAL_OK;
390 }
__HAL_UNLOCK(hrtc)
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
__HAL_LOCK(hrtc)
return HAL_OK
USART_TypeDef * Instance

◆ HAL_UARTEx_DisableFifoMode()

HAL_StatusTypeDef HAL_UARTEx_DisableFifoMode ( UART_HandleTypeDef huart)

Disable the FIFO mode.

Parameters
huartUART handle.
Return values
HALstatus

Definition at line 579 of file stm32l4xx_hal_uart_ex.c.

580 {
581  uint32_t tmpcr1;
582 
583  /* Check parameters */
584  assert_param(IS_UART_FIFO_INSTANCE(huart->Instance));
585 
586  /* Process Locked */
587  __HAL_LOCK(huart);
588 
589  huart->gState = HAL_UART_STATE_BUSY;
590 
591  /* Save actual UART configuration */
592  tmpcr1 = READ_REG(huart->Instance->CR1);
593 
594  /* Disable UART */
595  __HAL_UART_DISABLE(huart);
596 
597  /* Enable FIFO mode */
598  CLEAR_BIT(tmpcr1, USART_CR1_FIFOEN);
599  huart->FifoMode = UART_FIFOMODE_DISABLE;
600 
601  /* Restore UART configuration */
602  WRITE_REG(huart->Instance->CR1, tmpcr1);
603 
604  huart->gState = HAL_UART_STATE_READY;
605 
606  /* Process Unlocked */
607  __HAL_UNLOCK(huart);
608 
609  return HAL_OK;
610 }
__HAL_UNLOCK(hrtc)
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
__HAL_LOCK(hrtc)
return HAL_OK
USART_TypeDef * Instance
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))
__IO HAL_UART_StateTypeDef gState

◆ HAL_UARTEx_DisableStopMode()

HAL_StatusTypeDef HAL_UARTEx_DisableStopMode ( UART_HandleTypeDef huart)

Disable UART Stop Mode.

Parameters
huartUART handle.
Return values
HALstatus

Definition at line 518 of file stm32l4xx_hal_uart_ex.c.

519 {
520  /* Process Locked */
521  __HAL_LOCK(huart);
522 
523  /* Clear UESM bit */
524  CLEAR_BIT(huart->Instance->CR1, USART_CR1_UESM);
525 
526  /* Process Unlocked */
527  __HAL_UNLOCK(huart);
528 
529  return HAL_OK;
530 }
__HAL_UNLOCK(hrtc)
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
__HAL_LOCK(hrtc)
return HAL_OK
USART_TypeDef * Instance

◆ HAL_UARTEx_EnableClockStopMode()

HAL_StatusTypeDef HAL_UARTEx_EnableClockStopMode ( UART_HandleTypeDef huart)

Keep UART Clock enabled when in Stop Mode.

Note
When the USART clock source is configured to be LSE or HSI, it is possible to keep enabled this clock during STOP mode by setting the UCESM bit in USART_CR3 control register.
When LPUART is used to wakeup from stop with LSE is selected as LPUART clock source, and desired baud rate is 9600 baud, the bit UCESM bit in LPUART_CR3 control register must be set.
Parameters
huartUART handle.
Return values
HALstatus

Definition at line 359 of file stm32l4xx_hal_uart_ex.c.

360 {
361  /* Process Locked */
362  __HAL_LOCK(huart);
363 
364  /* Set UCESM bit */
365  SET_BIT(huart->Instance->CR3, USART_CR3_UCESM);
366 
367  /* Process Unlocked */
368  __HAL_UNLOCK(huart);
369 
370  return HAL_OK;
371 }
__HAL_UNLOCK(hrtc)
__HAL_LOCK(hrtc)
return HAL_OK
USART_TypeDef * Instance

◆ HAL_UARTEx_EnableFifoMode()

HAL_StatusTypeDef HAL_UARTEx_EnableFifoMode ( UART_HandleTypeDef huart)

Enable the FIFO mode.

Parameters
huartUART handle.
Return values
HALstatus

Definition at line 538 of file stm32l4xx_hal_uart_ex.c.

539 {
540  uint32_t tmpcr1;
541 
542  /* Check parameters */
543  assert_param(IS_UART_FIFO_INSTANCE(huart->Instance));
544 
545  /* Process Locked */
546  __HAL_LOCK(huart);
547 
548  huart->gState = HAL_UART_STATE_BUSY;
549 
550  /* Save actual UART configuration */
551  tmpcr1 = READ_REG(huart->Instance->CR1);
552 
553  /* Disable UART */
554  __HAL_UART_DISABLE(huart);
555 
556  /* Enable FIFO mode */
557  SET_BIT(tmpcr1, USART_CR1_FIFOEN);
558  huart->FifoMode = UART_FIFOMODE_ENABLE;
559 
560  /* Restore UART configuration */
561  WRITE_REG(huart->Instance->CR1, tmpcr1);
562 
563  /* Determine the number of data to process during RX/TX ISR execution */
565 
566  huart->gState = HAL_UART_STATE_READY;
567 
568  /* Process Unlocked */
569  __HAL_UNLOCK(huart);
570 
571  return HAL_OK;
572 }
__HAL_UNLOCK(hrtc)
__HAL_LOCK(hrtc)
return HAL_OK
static void UARTEx_SetNbDataToProcess(UART_HandleTypeDef *huart)
Calculate the number of data to process in RX/TX ISR.
USART_TypeDef * Instance
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))
__IO HAL_UART_StateTypeDef gState

◆ HAL_UARTEx_EnableStopMode()

HAL_StatusTypeDef HAL_UARTEx_EnableStopMode ( UART_HandleTypeDef huart)

Enable UART Stop Mode.

Note
The UART is able to wake up the MCU from Stop 1 mode as long as UART clock is HSI or LSE.
Parameters
huartUART handle.
Return values
HALstatus

Definition at line 499 of file stm32l4xx_hal_uart_ex.c.

500 {
501  /* Process Locked */
502  __HAL_LOCK(huart);
503 
504  /* Set UESM bit */
505  SET_BIT(huart->Instance->CR1, USART_CR1_UESM);
506 
507  /* Process Unlocked */
508  __HAL_UNLOCK(huart);
509 
510  return HAL_OK;
511 }
__HAL_UNLOCK(hrtc)
__HAL_LOCK(hrtc)
return HAL_OK
USART_TypeDef * Instance

◆ HAL_UARTEx_SetRxFifoThreshold()

HAL_StatusTypeDef HAL_UARTEx_SetRxFifoThreshold ( UART_HandleTypeDef huart,
uint32_t  Threshold 
)

Set the RXFIFO threshold.

Parameters
huartUART handle.
ThresholdRX FIFO threshold value This parameter can be one of the following values:
  • UART_RXFIFO_THRESHOLD_1_8
  • UART_RXFIFO_THRESHOLD_1_4
  • UART_RXFIFO_THRESHOLD_1_2
  • UART_RXFIFO_THRESHOLD_3_4
  • UART_RXFIFO_THRESHOLD_7_8
  • UART_RXFIFO_THRESHOLD_8_8
Return values
HALstatus

Definition at line 674 of file stm32l4xx_hal_uart_ex.c.

675 {
676  uint32_t tmpcr1;
677 
678  /* Check the parameters */
679  assert_param(IS_UART_FIFO_INSTANCE(huart->Instance));
680  assert_param(IS_UART_RXFIFO_THRESHOLD(Threshold));
681 
682  /* Process Locked */
683  __HAL_LOCK(huart);
684 
685  huart->gState = HAL_UART_STATE_BUSY;
686 
687  /* Save actual UART configuration */
688  tmpcr1 = READ_REG(huart->Instance->CR1);
689 
690  /* Disable UART */
691  __HAL_UART_DISABLE(huart);
692 
693  /* Update RX threshold configuration */
694  MODIFY_REG(huart->Instance->CR3, USART_CR3_RXFTCFG, Threshold);
695 
696  /* Determine the number of data to process during RX/TX ISR execution */
698 
699  /* Restore UART configuration */
700  WRITE_REG(huart->Instance->CR1, tmpcr1);
701 
702  huart->gState = HAL_UART_STATE_READY;
703 
704  /* Process Unlocked */
705  __HAL_UNLOCK(huart);
706 
707  return HAL_OK;
708 }
__HAL_UNLOCK(hrtc)
__HAL_LOCK(hrtc)
return HAL_OK
static void UARTEx_SetNbDataToProcess(UART_HandleTypeDef *huart)
Calculate the number of data to process in RX/TX ISR.
USART_TypeDef * Instance
MODIFY_REG(hrtc->Instance->CR, RTC_CR_WUCKSEL,(uint32_t) WakeUpClock)
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))
__IO HAL_UART_StateTypeDef gState

◆ HAL_UARTEx_SetTxFifoThreshold()

HAL_StatusTypeDef HAL_UARTEx_SetTxFifoThreshold ( UART_HandleTypeDef huart,
uint32_t  Threshold 
)

Set the TXFIFO threshold.

Parameters
huartUART handle.
ThresholdTX FIFO threshold value This parameter can be one of the following values:
  • UART_TXFIFO_THRESHOLD_1_8
  • UART_TXFIFO_THRESHOLD_1_4
  • UART_TXFIFO_THRESHOLD_1_2
  • UART_TXFIFO_THRESHOLD_3_4
  • UART_TXFIFO_THRESHOLD_7_8
  • UART_TXFIFO_THRESHOLD_8_8
Return values
HALstatus

Definition at line 625 of file stm32l4xx_hal_uart_ex.c.

626 {
627  uint32_t tmpcr1;
628 
629  /* Check parameters */
630  assert_param(IS_UART_FIFO_INSTANCE(huart->Instance));
631  assert_param(IS_UART_TXFIFO_THRESHOLD(Threshold));
632 
633  /* Process Locked */
634  __HAL_LOCK(huart);
635 
636  huart->gState = HAL_UART_STATE_BUSY;
637 
638  /* Save actual UART configuration */
639  tmpcr1 = READ_REG(huart->Instance->CR1);
640 
641  /* Disable UART */
642  __HAL_UART_DISABLE(huart);
643 
644  /* Update TX threshold configuration */
645  MODIFY_REG(huart->Instance->CR3, USART_CR3_TXFTCFG, Threshold);
646 
647  /* Determine the number of data to process during RX/TX ISR execution */
649 
650  /* Restore UART configuration */
651  WRITE_REG(huart->Instance->CR1, tmpcr1);
652 
653  huart->gState = HAL_UART_STATE_READY;
654 
655  /* Process Unlocked */
656  __HAL_UNLOCK(huart);
657 
658  return HAL_OK;
659 }
__HAL_UNLOCK(hrtc)
__HAL_LOCK(hrtc)
return HAL_OK
static void UARTEx_SetNbDataToProcess(UART_HandleTypeDef *huart)
Calculate the number of data to process in RX/TX ISR.
USART_TypeDef * Instance
MODIFY_REG(hrtc->Instance->CR, RTC_CR_WUCKSEL,(uint32_t) WakeUpClock)
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))
__IO HAL_UART_StateTypeDef gState

◆ HAL_UARTEx_StopModeWakeUpSourceConfig()

HAL_StatusTypeDef HAL_UARTEx_StopModeWakeUpSourceConfig ( UART_HandleTypeDef huart,
UART_WakeUpTypeDef  WakeUpSelection 
)

Set Wakeup from Stop mode interrupt flag selection.

Note
It is the application responsibility to enable the interrupt used as usart_wkup interrupt source before entering low-power mode.
Parameters
huartUART handle.
WakeUpSelectionAddress match, Start Bit detection or RXNE/RXFNE bit status. This parameter can be one of the following values:
  • UART_WAKEUP_ON_ADDRESS
  • UART_WAKEUP_ON_STARTBIT
  • UART_WAKEUP_ON_READDATA_NONEMPTY
Return values
HALstatus

Definition at line 444 of file stm32l4xx_hal_uart_ex.c.

445 {
446  HAL_StatusTypeDef status = HAL_OK;
447  uint32_t tickstart;
448 
449  /* check the wake-up from stop mode UART instance */
450  assert_param(IS_UART_WAKEUP_FROMSTOP_INSTANCE(huart->Instance));
451  /* check the wake-up selection parameter */
452  assert_param(IS_UART_WAKEUP_SELECTION(WakeUpSelection.WakeUpEvent));
453 
454  /* Process Locked */
455  __HAL_LOCK(huart);
456 
457  huart->gState = HAL_UART_STATE_BUSY;
458 
459  /* Disable the Peripheral */
460  __HAL_UART_DISABLE(huart);
461 
462  /* Set the wake-up selection scheme */
463  MODIFY_REG(huart->Instance->CR3, USART_CR3_WUS, WakeUpSelection.WakeUpEvent);
464 
465  if (WakeUpSelection.WakeUpEvent == UART_WAKEUP_ON_ADDRESS)
466  {
467  UARTEx_Wakeup_AddressConfig(huart, WakeUpSelection);
468  }
469 
470  /* Enable the Peripheral */
471  __HAL_UART_ENABLE(huart);
472 
473  /* Init tickstart for timeout managment*/
474  tickstart = HAL_GetTick();
475 
476  /* Wait until REACK flag is set */
477  if (UART_WaitOnFlagUntilTimeout(huart, USART_ISR_REACK, RESET, tickstart, HAL_UART_TIMEOUT_VALUE) != HAL_OK)
478  {
479  status = HAL_TIMEOUT;
480  }
481  else
482  {
483  /* Initialize the UART State */
484  huart->gState = HAL_UART_STATE_READY;
485  }
486 
487  /* Process Unlocked */
488  __HAL_UNLOCK(huart);
489 
490  return status;
491 }
uint32_t HAL_GetTick(void)
Provide a tick value in millisecond.
__HAL_UNLOCK(hrtc)
static void UARTEx_Wakeup_AddressConfig(UART_HandleTypeDef *huart, UART_WakeUpTypeDef WakeUpSelection)
Initialize the UART wake-up from stop mode parameters when triggered by address detection.
__HAL_LOCK(hrtc)
return HAL_OK
USART_TypeDef * Instance
MODIFY_REG(hrtc->Instance->CR, RTC_CR_WUCKSEL,(uint32_t) WakeUpClock)
HAL_StatusTypeDef UART_WaitOnFlagUntilTimeout(UART_HandleTypeDef *huart, uint32_t Flag, FlagStatus Status, uint32_t Tickstart, uint32_t Timeout)
Handle UART Communication Timeout.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))
__IO HAL_UART_StateTypeDef gState