STM32L4xx_HAL_Driver  1.14.0
Initialization and de-initialization functions

Extended Initialization and Configuration Functions. More...

Functions

HAL_StatusTypeDef HAL_RS485Ex_Init (UART_HandleTypeDef *huart, uint32_t Polarity, uint32_t AssertionTime, uint32_t DeassertionTime)
 Initialize the RS485 Driver enable feature according to the specified parameters in the UART_InitTypeDef and creates the associated handle. More...
 

Detailed Description

Extended Initialization and Configuration Functions.

===============================================================================
            ##### Initialization and Configuration functions #####
 ===============================================================================
    [..]
    This subsection provides a set of functions allowing to initialize the USARTx or the UARTy
    in asynchronous mode.
      (+) For the asynchronous mode the parameters below can be configured:
        (++) Baud Rate
        (++) Word Length
        (++) Stop Bit
        (++) Parity: If the parity is enabled, then the MSB bit of the data written
             in the data register is transmitted but is changed by the parity bit.
        (++) Hardware flow control
        (++) Receiver/transmitter modes
        (++) Over Sampling Method
        (++) One-Bit Sampling Method
      (+) For the asynchronous mode, the following advanced features can be configured as well:
        (++) TX and/or RX pin level inversion
        (++) data logical level inversion
        (++) RX and TX pins swap
        (++) RX overrun detection disabling
        (++) DMA disabling on RX error
        (++) MSB first on communication line
        (++) auto Baud rate detection
    [..]
    The HAL_RS485Ex_Init() API follows the UART RS485 mode configuration
     procedures (details for the procedures are available in reference manual).

Depending on the frame length defined by the M1 and M0 bits (7-bit, 8-bit or 9-bit), the possible UART formats are listed in the following table.

Table 1. UART frame format. +--------------------------------------------------------------------—+ | M1 bit | M0 bit | PCE bit | UART frame | |------—|------—|--------—|------------------------------------—| | 0 | 0 | 0 | | SB | 8 bit data | STB | | |------—|------—|--------—|------------------------------------—| | 0 | 0 | 1 | | SB | 7 bit data | PB | STB | | |------—|------—|--------—|------------------------------------—| | 0 | 1 | 0 | | SB | 9 bit data | STB | | |------—|------—|--------—|------------------------------------—| | 0 | 1 | 1 | | SB | 8 bit data | PB | STB | | |------—|------—|--------—|------------------------------------—| | 1 | 0 | 0 | | SB | 7 bit data | STB | | |------—|------—|--------—|------------------------------------—| | 1 | 0 | 1 | | SB | 6 bit data | PB | STB | | +--------------------------------------------------------------------—+

Function Documentation

◆ HAL_RS485Ex_Init()

HAL_StatusTypeDef HAL_RS485Ex_Init ( UART_HandleTypeDef huart,
uint32_t  Polarity,
uint32_t  AssertionTime,
uint32_t  DeassertionTime 
)

Initialize the RS485 Driver enable feature according to the specified parameters in the UART_InitTypeDef and creates the associated handle.

Parameters
huartUART handle.
PolaritySelect the driver enable polarity. This parameter can be one of the following values:
  • UART_DE_POLARITY_HIGH DE signal is active high
  • UART_DE_POLARITY_LOW DE signal is active low
AssertionTimeDriver Enable assertion time: 5-bit value defining the time between the activation of the DE (Driver Enable) signal and the beginning of the start bit. It is expressed in sample time units (1/8 or 1/16 bit time, depending on the oversampling rate)
DeassertionTimeDriver Enable deassertion time: 5-bit value defining the time between the end of the last stop bit, in a transmitted message, and the de-activation of the DE (Driver Enable) signal. It is expressed in sample time units (1/8 or 1/16 bit time, depending on the oversampling rate).
Return values
HALstatus

Definition at line 170 of file stm32l4xx_hal_uart_ex.c.

172 {
173  uint32_t temp;
174 
175  /* Check the UART handle allocation */
176  if (huart == NULL)
177  {
178  return HAL_ERROR;
179  }
180  /* Check the Driver Enable UART instance */
181  assert_param(IS_UART_DRIVER_ENABLE_INSTANCE(huart->Instance));
182 
183  /* Check the Driver Enable polarity */
184  assert_param(IS_UART_DE_POLARITY(Polarity));
185 
186  /* Check the Driver Enable assertion time */
187  assert_param(IS_UART_ASSERTIONTIME(AssertionTime));
188 
189  /* Check the Driver Enable deassertion time */
190  assert_param(IS_UART_DEASSERTIONTIME(DeassertionTime));
191 
192  if (huart->gState == HAL_UART_STATE_RESET)
193  {
194  /* Allocate lock resource and initialize it */
195  huart->Lock = HAL_UNLOCKED;
196 
197 #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
199 
200  if (huart->MspInitCallback == NULL)
201  {
203  }
204 
205  /* Init the low level hardware */
206  huart->MspInitCallback(huart);
207 #else
208  /* Init the low level hardware : GPIO, CLOCK, CORTEX */
209  HAL_UART_MspInit(huart);
210 #endif /* (USE_HAL_UART_REGISTER_CALLBACKS) */
211  }
212 
213  huart->gState = HAL_UART_STATE_BUSY;
214 
215  /* Disable the Peripheral */
216  __HAL_UART_DISABLE(huart);
217 
218  /* Set the UART Communication parameters */
219  if (UART_SetConfig(huart) == HAL_ERROR)
220  {
221  return HAL_ERROR;
222  }
223 
224  if (huart->AdvancedInit.AdvFeatureInit != UART_ADVFEATURE_NO_INIT)
225  {
226  UART_AdvFeatureConfig(huart);
227  }
228 
229  /* Enable the Driver Enable mode by setting the DEM bit in the CR3 register */
230  SET_BIT(huart->Instance->CR3, USART_CR3_DEM);
231 
232  /* Set the Driver Enable polarity */
233  MODIFY_REG(huart->Instance->CR3, USART_CR3_DEP, Polarity);
234 
235  /* Set the Driver Enable assertion and deassertion times */
236  temp = (AssertionTime << UART_CR1_DEAT_ADDRESS_LSB_POS);
237  temp |= (DeassertionTime << UART_CR1_DEDT_ADDRESS_LSB_POS);
238  MODIFY_REG(huart->Instance->CR1, (USART_CR1_DEDT | USART_CR1_DEAT), temp);
239 
240  /* Enable the Peripheral */
241  __HAL_UART_ENABLE(huart);
242 
243  /* TEACK and/or REACK to check before moving huart->gState and huart->RxState to Ready */
244  return (UART_CheckIdleState(huart));
245 }
HAL_StatusTypeDef UART_CheckIdleState(UART_HandleTypeDef *huart)
Check the UART Idle State.
void UART_AdvFeatureConfig(UART_HandleTypeDef *huart)
Configure the UART peripheral advanced features.
void HAL_UART_MspInit(UART_HandleTypeDef *huart)
Initialize the UART MSP.
USART_TypeDef * Instance
UART_AdvFeatureInitTypeDef AdvancedInit
void(* MspInitCallback)(struct __UART_HandleTypeDef *huart)
void UART_InitCallbacksToDefault(UART_HandleTypeDef *huart)
Initialize the callbacks to their default values.
MODIFY_REG(hrtc->Instance->CR, RTC_CR_WUCKSEL,(uint32_t) WakeUpClock)
HAL_StatusTypeDef UART_SetConfig(UART_HandleTypeDef *huart)
Configure the UART peripheral.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))
__IO HAL_UART_StateTypeDef gState