stm32f7xx_hal_uart_ex.c
Go to the documentation of this file.
1 
37 /* Includes ------------------------------------------------------------------*/
38 #include "stm32f7xx_hal.h"
39 
49 #ifdef HAL_UART_MODULE_ENABLED
50 
51 /* Private typedef -----------------------------------------------------------*/
52 /* Private define ------------------------------------------------------------*/
53 
54 /* Private macros ------------------------------------------------------------*/
55 /* Private variables ---------------------------------------------------------*/
56 /* Private function prototypes -----------------------------------------------*/
60 #if defined(USART_CR1_UESM)
61 static void UARTEx_Wakeup_AddressConfig(UART_HandleTypeDef *huart, UART_WakeUpTypeDef WakeUpSelection);
62 #endif /* USART_CR1_UESM */
63 
67 /* Exported functions --------------------------------------------------------*/
68 
150 HAL_StatusTypeDef HAL_RS485Ex_Init(UART_HandleTypeDef *huart, uint32_t Polarity, uint32_t AssertionTime,
151  uint32_t DeassertionTime)
152 {
153  uint32_t temp;
154 
155  /* Check the UART handle allocation */
156  if (huart == NULL)
157  {
158  return HAL_ERROR;
159  }
160  /* Check the Driver Enable UART instance */
162 
163  /* Check the Driver Enable polarity */
165 
166  /* Check the Driver Enable assertion time */
167  assert_param(IS_UART_ASSERTIONTIME(AssertionTime));
168 
169  /* Check the Driver Enable deassertion time */
170  assert_param(IS_UART_DEASSERTIONTIME(DeassertionTime));
171 
173  {
174  /* Allocate lock resource and initialize it */
176 
177 #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
178  UART_InitCallbacksToDefault(huart);
179 
180  if (huart->MspInitCallback == NULL)
181  {
182  huart->MspInitCallback = HAL_UART_MspInit;
183  }
184 
185  /* Init the low level hardware */
186  huart->MspInitCallback(huart);
187 #else
188  /* Init the low level hardware : GPIO, CLOCK, CORTEX */
190 #endif /* (USE_HAL_UART_REGISTER_CALLBACKS) */
191  }
192 
194 
195  /* Disable the Peripheral */
197 
198  /* Set the UART Communication parameters */
200  {
201  return HAL_ERROR;
202  }
203 
205  {
207  }
208 
209  /* Enable the Driver Enable mode by setting the DEM bit in the CR3 register */
211 
212  /* Set the Driver Enable polarity */
213  MODIFY_REG(huart->Instance->CR3, USART_CR3_DEP, Polarity);
214 
215  /* Set the Driver Enable assertion and deassertion times */
216  temp = (AssertionTime << UART_CR1_DEAT_ADDRESS_LSB_POS);
217  temp |= (DeassertionTime << UART_CR1_DEDT_ADDRESS_LSB_POS);
219 
220  /* Enable the Peripheral */
222 
223  /* TEACK and/or REACK to check before moving huart->gState and huart->RxState to Ready */
224  return (UART_CheckIdleState(huart));
225 }
226 
255 #if defined(USART_CR3_UCESM)
256 
265 HAL_StatusTypeDef HAL_UARTEx_EnableClockStopMode(UART_HandleTypeDef *huart)
266 {
267  /* Process Locked */
268  __HAL_LOCK(huart);
269 
270  /* Set UCESM bit */
272 
273  /* Process Unlocked */
275 
276  return HAL_OK;
277 }
278 
284 HAL_StatusTypeDef HAL_UARTEx_DisableClockStopMode(UART_HandleTypeDef *huart)
285 {
286  /* Process Locked */
287  __HAL_LOCK(huart);
288 
289  /* Clear UCESM bit */
291 
292  /* Process Unlocked */
294 
295  return HAL_OK;
296 }
297 
298 #endif /* USART_CR3_UCESM */
299 
313 {
314  /* Check the UART handle allocation */
315  if (huart == NULL)
316  {
317  return HAL_ERROR;
318  }
319 
320  /* Check the address length parameter */
322 
324 
325  /* Disable the Peripheral */
327 
328  /* Set the address length */
329  MODIFY_REG(huart->Instance->CR2, USART_CR2_ADDM7, AddressLength);
330 
331  /* Enable the Peripheral */
333 
334  /* TEACK and/or REACK to check before moving huart->gState to Ready */
335  return (UART_CheckIdleState(huart));
336 }
337 
338 #if defined(USART_CR1_UESM)
339 
352 {
353  HAL_StatusTypeDef status = HAL_OK;
354  uint32_t tickstart;
355 
356  /* check the wake-up from stop mode UART instance */
358  /* check the wake-up selection parameter */
360 
361  /* Process Locked */
362  __HAL_LOCK(huart);
363 
365 
366  /* Disable the Peripheral */
368 
369  /* Set the wake-up selection scheme */
370  MODIFY_REG(huart->Instance->CR3, USART_CR3_WUS, WakeUpSelection.WakeUpEvent);
371 
372  if (WakeUpSelection.WakeUpEvent == UART_WAKEUP_ON_ADDRESS)
373  {
374  UARTEx_Wakeup_AddressConfig(huart, WakeUpSelection);
375  }
376 
377  /* Enable the Peripheral */
379 
380  /* Init tickstart for timeout managment*/
381  tickstart = HAL_GetTick();
382 
383  /* Wait until REACK flag is set */
385  {
386  status = HAL_TIMEOUT;
387  }
388  else
389  {
390  /* Initialize the UART State */
392  }
393 
394  /* Process Unlocked */
396 
397  return status;
398 }
399 
407 {
408  /* Process Locked */
409  __HAL_LOCK(huart);
410 
411  /* Set UESM bit */
413 
414  /* Process Unlocked */
416 
417  return HAL_OK;
418 }
419 
426 {
427  /* Process Locked */
428  __HAL_LOCK(huart);
429 
430  /* Clear UESM bit */
432 
433  /* Process Unlocked */
435 
436  return HAL_OK;
437 }
438 
439 #endif /* USART_CR1_UESM */
440 
451 #if defined(USART_CR1_UESM)
452 
459 static void UARTEx_Wakeup_AddressConfig(UART_HandleTypeDef *huart, UART_WakeUpTypeDef WakeUpSelection)
460 {
462 
463  /* Set the USART address length */
465 
466  /* Set the USART address node */
467  MODIFY_REG(huart->Instance->CR2, USART_CR2_ADD, ((uint32_t)WakeUpSelection.Address << UART_CR2_ADDRESS_LSB_POS));
468 }
469 #endif /* USART_CR1_UESM */
470 
475 #endif /* HAL_UART_MODULE_ENABLED */
476 
485 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
assert_param
#define assert_param(expr)
Include module's header file.
Definition: stm32f407/stm32f407g-disc1/Inc/stm32f4xx_hal_conf.h:353
HAL_MultiProcessorEx_AddressLength_Set
HAL_StatusTypeDef HAL_MultiProcessorEx_AddressLength_Set(UART_HandleTypeDef *huart, uint32_t AddressLength)
IS_UART_ADDRESSLENGTH_DETECT
#define IS_UART_ADDRESSLENGTH_DETECT(__ADDRESS__)
Ensure that UART wake-up address length is valid.
Definition: stm32f7xx_hal_uart_ex.h:402
UART_CR1_DEDT_ADDRESS_LSB_POS
#define UART_CR1_DEDT_ADDRESS_LSB_POS
Definition: stm32f7xx_hal_uart.h:625
HAL_StatusTypeDef
HAL_StatusTypeDef
HAL Status structures definition
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h:40
HAL_UARTEx_StopModeWakeUpSourceConfig
HAL_StatusTypeDef HAL_UARTEx_StopModeWakeUpSourceConfig(UART_HandleTypeDef *huart, UART_WakeUpTypeDef WakeUpSelection)
USART_CR1_DEAT
#define USART_CR1_DEAT
Definition: stm32f769xx.h:15277
NULL
#define NULL
Definition: porcupine/demo/c/dr_libs/tests/external/miniaudio/extras/speex_resampler/thirdparty/resample.c:92
USART_CR2_ADD
#define USART_CR2_ADD
Definition: stm32f407xx.h:12552
HAL_UNLOCKED
@ HAL_UNLOCKED
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h:53
UART_WAKEUP_ON_ADDRESS
#define UART_WAKEUP_ON_ADDRESS
Definition: stm32h735/stm32h735g-dk/Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_uart.h:662
huart
UART_HandleTypeDef huart
Definition: pv_stm32f469.c:31
UART_ADVFEATURE_NO_INIT
#define UART_ADVFEATURE_NO_INIT
Definition: stm32f7xx_hal_uart.h:480
UART_AdvFeatureConfig
void UART_AdvFeatureConfig(UART_HandleTypeDef *huart)
HAL_UARTEx_DisableStopMode
HAL_StatusTypeDef HAL_UARTEx_DisableStopMode(UART_HandleTypeDef *huart)
__UART_HandleTypeDef
UART handle Structure definition.
Definition: stm32f4xx_hal_uart.h:141
__HAL_UART_ENABLE
#define __HAL_UART_ENABLE(__HANDLE__)
Enable UART.
Definition: stm32f4xx_hal_uart.h:652
USART_TypeDef::CR1
__IO uint32_t CR1
Definition: stm32f407xx.h:763
USART_CR2_ADDM7
#define USART_CR2_ADDM7
Definition: stm32f769xx.h:15298
HAL_ERROR
@ HAL_ERROR
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h:43
__HAL_UART_DISABLE
#define __HAL_UART_DISABLE(__HANDLE__)
Disable UART.
Definition: stm32f4xx_hal_uart.h:658
CLEAR_BIT
#define CLEAR_BIT(REG, BIT)
Definition: stm32f407/stm32f407g-disc1/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h:214
HAL_GetTick
uint32_t HAL_GetTick(void)
Provides a tick value in millisecond.
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c:323
USART_CR3_DEM
#define USART_CR3_DEM
Definition: stm32f769xx.h:15400
USART_CR3_DEP
#define USART_CR3_DEP
Definition: stm32f769xx.h:15403
UART_CR2_ADDRESS_LSB_POS
#define UART_CR2_ADDRESS_LSB_POS
Definition: stm32f7xx_hal_uart.h:588
HAL_UART_MspInit
void HAL_UART_MspInit(UART_HandleTypeDef *huart)
UART MSP Initialization This function configures the hardware resources used in this example.
Definition: stm32h7xx_hal_msp.c:320
HAL_UARTEx_EnableStopMode
HAL_StatusTypeDef HAL_UARTEx_EnableStopMode(UART_HandleTypeDef *huart)
UART_WakeUpTypeDef::Address
uint8_t Address
Definition: stm32h735/stm32h735g-dk/Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_uart_ex.h:57
USART_CR1_UESM
#define USART_CR1_UESM
Definition: stm32f769xx.h:15223
HAL_OK
@ HAL_OK
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h:42
UART_WakeUpTypeDef::AddressLength
uint16_t AddressLength
Definition: stm32h735/stm32h735g-dk/Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_uart_ex.h:54
IS_UART_DE_POLARITY
#define IS_UART_DE_POLARITY(__POLARITY__)
Ensure that UART driver enable polarity is valid.
Definition: stm32f7xx_hal_uart.h:1388
UART_CheckIdleState
HAL_StatusTypeDef UART_CheckIdleState(UART_HandleTypeDef *huart)
UART_WakeUpTypeDef
UART wake up from stop mode parameters.
Definition: stm32h735/stm32h735g-dk/Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_uart_ex.h:47
__HAL_LOCK
#define __HAL_LOCK(__HANDLE__)
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h:93
USART_ISR_REACK
#define USART_ISR_REACK
Definition: stm32f769xx.h:15530
MODIFY_REG
#define MODIFY_REG(REG, CLEARMASK, SETMASK)
Definition: stm32f407/stm32f407g-disc1/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h:224
RESET
@ RESET
Definition: stm32f407/stm32f407g-disc1/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h:187
__UART_HandleTypeDef::Lock
HAL_LockTypeDef Lock
Definition: stm32f4xx_hal_uart.h:163
IS_UART_DRIVER_ENABLE_INSTANCE
#define IS_UART_DRIVER_ENABLE_INSTANCE(__INSTANCE__)
Definition: stm32f769xx.h:21985
HAL_UART_TIMEOUT_VALUE
#define HAL_UART_TIMEOUT_VALUE
Definition: stm32f7xx_hal_uart.h:641
USART_CR1_DEDT
#define USART_CR1_DEDT
Definition: stm32f769xx.h:15269
USART_TypeDef::CR3
__IO uint32_t CR3
Definition: stm32f407xx.h:765
USART_TypeDef::CR2
__IO uint32_t CR2
Definition: stm32f407xx.h:764
__HAL_UNLOCK
#define __HAL_UNLOCK(__HANDLE__)
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h:105
IS_UART_ASSERTIONTIME
#define IS_UART_ASSERTIONTIME(__TIME__)
Check UART assertion time.
Definition: stm32f7xx_hal_uart.h:1121
__UART_HandleTypeDef::AdvancedInit
UART_AdvFeatureInitTypeDef AdvancedInit
Definition: stm32f7xx_hal_uart.h:191
UART_WakeUpTypeDef::WakeUpEvent
uint32_t WakeUpEvent
Definition: stm32h735/stm32h735g-dk/Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_uart_ex.h:49
__UART_HandleTypeDef::gState
__IO HAL_UART_StateTypeDef gState
Definition: stm32f4xx_hal_uart.h:165
UART_SetConfig
HAL_StatusTypeDef UART_SetConfig(UART_HandleTypeDef *huart)
IS_UART_WAKEUP_SELECTION
#define IS_UART_WAKEUP_SELECTION(__WAKE__)
Ensure that UART wake-up selection is valid.
Definition: stm32h735/stm32h735g-dk/Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_uart.h:1541
HAL_TIMEOUT
@ HAL_TIMEOUT
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h:45
IS_UART_DEASSERTIONTIME
#define IS_UART_DEASSERTIONTIME(__TIME__)
Check UART deassertion time.
Definition: stm32f7xx_hal_uart.h:1127
UART_WaitOnFlagUntilTimeout
HAL_StatusTypeDef UART_WaitOnFlagUntilTimeout(UART_HandleTypeDef *huart, uint32_t Flag, FlagStatus Status, uint32_t Tickstart, uint32_t Timeout)
USART_CR3_UCESM
#define USART_CR3_UCESM
Definition: stm32f769xx.h:15420
HAL_UART_STATE_RESET
@ HAL_UART_STATE_RESET
Definition: stm32f4xx_hal_uart.h:119
UART_CR1_DEAT_ADDRESS_LSB_POS
#define UART_CR1_DEAT_ADDRESS_LSB_POS
Definition: stm32f7xx_hal_uart.h:617
USART_CR3_WUS
#define USART_CR3_WUS
Definition: stm32f769xx.h:15412
HAL_RS485Ex_Init
HAL_StatusTypeDef HAL_RS485Ex_Init(UART_HandleTypeDef *huart, uint32_t Polarity, uint32_t AssertionTime, uint32_t DeassertionTime)
SET_BIT
#define SET_BIT(REG, BIT)
Definition: stm32f407/stm32f407g-disc1/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h:212
IS_UART_WAKEUP_FROMSTOP_INSTANCE
#define IS_UART_WAKEUP_FROMSTOP_INSTANCE(__INSTANCE__)
Definition: stm32f769xx.h:22025
__UART_HandleTypeDef::Instance
USART_TypeDef * Instance
Definition: stm32f4xx_hal_uart.h:143
UART_AdvFeatureInitTypeDef::AdvFeatureInit
uint32_t AdvFeatureInit
Definition: stm32f7xx_hal_uart.h:94
HAL_UART_STATE_BUSY
@ HAL_UART_STATE_BUSY
Definition: stm32f4xx_hal_uart.h:123
stm32f7xx_hal.h
This file contains all the functions prototypes for the HAL module driver.
HAL_UART_STATE_READY
@ HAL_UART_STATE_READY
Definition: stm32f4xx_hal_uart.h:121


picovoice_driver
Author(s):
autogenerated on Fri Apr 1 2022 02:14:53