You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

622 lines
22 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f0xx_hal_uart_ex.c
  4. * @author MCD Application Team
  5. * @brief Extended UART HAL module driver.
  6. * This file provides firmware functions to manage the following extended
  7. * functionalities of the Universal Asynchronous Receiver Transmitter Peripheral (UART).
  8. * + Initialization and de-initialization functions
  9. * + Peripheral Control functions
  10. *
  11. *
  12. @verbatim
  13. ==============================================================================
  14. ##### UART peripheral extended features #####
  15. ==============================================================================
  16. (#) Declare a UART_HandleTypeDef handle structure.
  17. (#) For the UART RS485 Driver Enable mode, initialize the UART registers
  18. by calling the HAL_RS485Ex_Init() API.
  19. @endverbatim
  20. ******************************************************************************
  21. * @attention
  22. *
  23. * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
  24. *
  25. * Redistribution and use in source and binary forms, with or without modification,
  26. * are permitted provided that the following conditions are met:
  27. * 1. Redistributions of source code must retain the above copyright notice,
  28. * this list of conditions and the following disclaimer.
  29. * 2. Redistributions in binary form must reproduce the above copyright notice,
  30. * this list of conditions and the following disclaimer in the documentation
  31. * and/or other materials provided with the distribution.
  32. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  33. * may be used to endorse or promote products derived from this software
  34. * without specific prior written permission.
  35. *
  36. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  37. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  38. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  39. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  40. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  41. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  42. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  43. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  45. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  46. *
  47. ******************************************************************************
  48. */
  49. /* Includes ------------------------------------------------------------------*/
  50. #include "stm32f0xx_hal.h"
  51. /** @addtogroup STM32F0xx_HAL_Driver
  52. * @{
  53. */
  54. /** @defgroup UARTEx UARTEx
  55. * @brief UART Extended HAL module driver
  56. * @{
  57. */
  58. #ifdef HAL_UART_MODULE_ENABLED
  59. /* Private typedef -----------------------------------------------------------*/
  60. /* Private define ------------------------------------------------------------*/
  61. /* Private macros ------------------------------------------------------------*/
  62. /* Private variables ---------------------------------------------------------*/
  63. /* Private function prototypes -----------------------------------------------*/
  64. /** @defgroup UARTEx_Private_Functions UARTEx Private Functions
  65. * @{
  66. */
  67. #if !defined(STM32F030x6) && !defined(STM32F030x8)&& !defined(STM32F070xB)&& !defined(STM32F070x6)&& !defined(STM32F030xC)
  68. static void UARTEx_Wakeup_AddressConfig(UART_HandleTypeDef *huart, UART_WakeUpTypeDef WakeUpSelection);
  69. #endif /* !defined(STM32F030x6) && !defined(STM32F030x8)&& !defined(STM32F070xB)&& !defined(STM32F070x6)&& !defined(STM32F030xC) */
  70. /**
  71. * @}
  72. */
  73. /* Exported functions ---------------------------------------------------------*/
  74. /** @defgroup UARTEx_Exported_Functions UARTEx Exported Functions
  75. * @{
  76. */
  77. /** @defgroup UARTEx_Exported_Functions_Group1 Extended Initialization and de-initialization functions
  78. * @brief Extended Initialization and Configuration Functions
  79. *
  80. @verbatim
  81. ===============================================================================
  82. ##### Initialization and Configuration functions #####
  83. ==============================================================================
  84. [..]
  85. This subsection provides a set of functions allowing to initialize the USARTx or the UARTy
  86. in asynchronous mode.
  87. (+) For the asynchronous mode the parameters below can be configured:
  88. (++) Baud Rate
  89. (++) Word Length (Fixed to 8-bits only for LIN mode)
  90. (++) Stop Bit
  91. (++) Parity
  92. (++) Hardware flow control
  93. (++) Receiver/transmitter modes
  94. (++) Over Sampling Method
  95. (++) One-Bit Sampling Method
  96. (+) For the asynchronous mode, the following advanced features can be configured as well:
  97. (++) TX and/or RX pin level inversion
  98. (++) data logical level inversion
  99. (++) RX and TX pins swap
  100. (++) RX overrun detection disabling
  101. (++) DMA disabling on RX error
  102. (++) MSB first on communication line
  103. (++) auto Baud rate detection
  104. [..]
  105. The HAL_LIN_Init() and HAL_RS485Ex_Init() APIs follows respectively the LIN and
  106. the UART RS485 mode configuration procedures (details for the procedures are
  107. available in reference manual).
  108. @endverbatim
  109. * @{
  110. */
  111. /*
  112. Additional Table: If the parity is enabled, then the MSB bit of the data written
  113. in the data register is transmitted but is changed by the parity bit.
  114. According to device capability (support or not of 7-bit word length),
  115. frame length is either defined by the M bit (8-bits or 9-bits)
  116. or by the M1 and M0 bits (7-bit, 8-bit or 9-bit).
  117. Possible UART frame formats are as listed in the following table:
  118. Table 1. UART frame format.
  119. +-----------------------------------------------------------------------+
  120. | M bit | PCE bit | UART frame |
  121. |-------------------|-----------|---------------------------------------|
  122. | 0 | 0 | | SB | 8-bit data | STB | |
  123. |-------------------|-----------|---------------------------------------|
  124. | 0 | 1 | | SB | 7-bit data | PB | STB | |
  125. |-------------------|-----------|---------------------------------------|
  126. | 1 | 0 | | SB | 9-bit data | STB | |
  127. |-------------------|-----------|---------------------------------------|
  128. | 1 | 1 | | SB | 8-bit data | PB | STB | |
  129. +-----------------------------------------------------------------------+
  130. | M1 bit | M0 bit | PCE bit | UART frame |
  131. |---------|---------|-----------|---------------------------------------|
  132. | 0 | 0 | 0 | | SB | 8 bit data | STB | |
  133. |---------|---------|-----------|---------------------------------------|
  134. | 0 | 0 | 1 | | SB | 7 bit data | PB | STB | |
  135. |---------|---------|-----------|---------------------------------------|
  136. | 0 | 1 | 0 | | SB | 9 bit data | STB | |
  137. |---------|---------|-----------|---------------------------------------|
  138. | 0 | 1 | 1 | | SB | 8 bit data | PB | STB | |
  139. |---------|---------|-----------|---------------------------------------|
  140. | 1 | 0 | 0 | | SB | 7 bit data | STB | |
  141. |---------|---------|-----------|---------------------------------------|
  142. | 1 | 0 | 1 | | SB | 6 bit data | PB | STB | |
  143. +-----------------------------------------------------------------------+
  144. */
  145. /**
  146. * @brief Initialize the RS485 Driver enable feature according to the specified
  147. * parameters in the UART_InitTypeDef and creates the associated handle.
  148. * @param huart UART handle.
  149. * @param Polarity select the driver enable polarity.
  150. * This parameter can be one of the following values:
  151. * @arg @ref UART_DE_POLARITY_HIGH DE signal is active high
  152. * @arg @ref UART_DE_POLARITY_LOW DE signal is active low
  153. * @param AssertionTime Driver Enable assertion time:
  154. * 5-bit value defining the time between the activation of the DE (Driver Enable)
  155. * signal and the beginning of the start bit. It is expressed in sample time
  156. * units (1/8 or 1/16 bit time, depending on the oversampling rate)
  157. * @param DeassertionTime Driver Enable deassertion time:
  158. * 5-bit value defining the time between the end of the last stop bit, in a
  159. * transmitted message, and the de-activation of the DE (Driver Enable) signal.
  160. * It is expressed in sample time units (1/8 or 1/16 bit time, depending on the
  161. * oversampling rate).
  162. * @retval HAL status
  163. */
  164. HAL_StatusTypeDef HAL_RS485Ex_Init(UART_HandleTypeDef *huart, uint32_t Polarity, uint32_t AssertionTime, uint32_t DeassertionTime)
  165. {
  166. uint32_t temp = 0x0U;
  167. /* Check the UART handle allocation */
  168. if(huart == NULL)
  169. {
  170. return HAL_ERROR;
  171. }
  172. /* Check the Driver Enable UART instance */
  173. assert_param(IS_UART_DRIVER_ENABLE_INSTANCE(huart->Instance));
  174. /* Check the Driver Enable polarity */
  175. assert_param(IS_UART_DE_POLARITY(Polarity));
  176. /* Check the Driver Enable assertion time */
  177. assert_param(IS_UART_ASSERTIONTIME(AssertionTime));
  178. /* Check the Driver Enable deassertion time */
  179. assert_param(IS_UART_DEASSERTIONTIME(DeassertionTime));
  180. if(huart->gState == HAL_UART_STATE_RESET)
  181. {
  182. /* Allocate lock resource and initialize it */
  183. huart->Lock = HAL_UNLOCKED;
  184. /* Init the low level hardware : GPIO, CLOCK, CORTEX */
  185. HAL_UART_MspInit(huart);
  186. }
  187. huart->gState = HAL_UART_STATE_BUSY;
  188. /* Disable the Peripheral */
  189. __HAL_UART_DISABLE(huart);
  190. /* Set the UART Communication parameters */
  191. if (UART_SetConfig(huart) == HAL_ERROR)
  192. {
  193. return HAL_ERROR;
  194. }
  195. if(huart->AdvancedInit.AdvFeatureInit != UART_ADVFEATURE_NO_INIT)
  196. {
  197. UART_AdvFeatureConfig(huart);
  198. }
  199. /* Enable the Driver Enable mode by setting the DEM bit in the CR3 register */
  200. SET_BIT(huart->Instance->CR3, USART_CR3_DEM);
  201. /* Set the Driver Enable polarity */
  202. MODIFY_REG(huart->Instance->CR3, USART_CR3_DEP, Polarity);
  203. /* Set the Driver Enable assertion and deassertion times */
  204. temp = (AssertionTime << UART_CR1_DEAT_ADDRESS_LSB_POS);
  205. temp |= (DeassertionTime << UART_CR1_DEDT_ADDRESS_LSB_POS);
  206. MODIFY_REG(huart->Instance->CR1, (USART_CR1_DEDT|USART_CR1_DEAT), temp);
  207. /* Enable the Peripheral */
  208. __HAL_UART_ENABLE(huart);
  209. /* TEACK and/or REACK to check before moving huart->gState and huart->RxState to Ready */
  210. return (UART_CheckIdleState(huart));
  211. }
  212. #if !defined(STM32F030x6) && !defined(STM32F030x8)&& !defined(STM32F070xB)&& !defined(STM32F070x6)&& !defined(STM32F030xC)
  213. /**
  214. * @brief Initialize the LIN mode according to the specified
  215. * parameters in the UART_InitTypeDef and creates the associated handle .
  216. * @param huart UART handle.
  217. * @param BreakDetectLength specifies the LIN break detection length.
  218. * This parameter can be one of the following values:
  219. * @arg @ref UART_LINBREAKDETECTLENGTH_10B 10-bit break detection
  220. * @arg @ref UART_LINBREAKDETECTLENGTH_11B 11-bit break detection
  221. * @retval HAL status
  222. */
  223. HAL_StatusTypeDef HAL_LIN_Init(UART_HandleTypeDef *huart, uint32_t BreakDetectLength)
  224. {
  225. /* Check the UART handle allocation */
  226. if(huart == NULL)
  227. {
  228. return HAL_ERROR;
  229. }
  230. /* Check the LIN UART instance */
  231. assert_param(IS_UART_LIN_INSTANCE(huart->Instance));
  232. /* Check the Break detection length parameter */
  233. assert_param(IS_UART_LIN_BREAK_DETECT_LENGTH(BreakDetectLength));
  234. /* LIN mode limited to 16-bit oversampling only */
  235. if(huart->Init.OverSampling == UART_OVERSAMPLING_8)
  236. {
  237. return HAL_ERROR;
  238. }
  239. /* LIN mode limited to 8-bit data length */
  240. if(huart->Init.WordLength != UART_WORDLENGTH_8B)
  241. {
  242. return HAL_ERROR;
  243. }
  244. if(huart->gState == HAL_UART_STATE_RESET)
  245. {
  246. /* Allocate lock resource and initialize it */
  247. huart->Lock = HAL_UNLOCKED;
  248. /* Init the low level hardware : GPIO, CLOCK */
  249. HAL_UART_MspInit(huart);
  250. }
  251. huart->gState = HAL_UART_STATE_BUSY;
  252. /* Disable the Peripheral */
  253. __HAL_UART_DISABLE(huart);
  254. /* Set the UART Communication parameters */
  255. if (UART_SetConfig(huart) == HAL_ERROR)
  256. {
  257. return HAL_ERROR;
  258. }
  259. if (huart->AdvancedInit.AdvFeatureInit != UART_ADVFEATURE_NO_INIT)
  260. {
  261. UART_AdvFeatureConfig(huart);
  262. }
  263. /* In LIN mode, the following bits must be kept cleared:
  264. - LINEN and CLKEN bits in the USART_CR2 register,
  265. - SCEN and IREN bits in the USART_CR3 register.*/
  266. CLEAR_BIT(huart->Instance->CR2, USART_CR2_CLKEN);
  267. CLEAR_BIT(huart->Instance->CR3, (USART_CR3_HDSEL | USART_CR3_IREN | USART_CR3_SCEN));
  268. /* Enable the LIN mode by setting the LINEN bit in the CR2 register */
  269. SET_BIT(huart->Instance->CR2, USART_CR2_LINEN);
  270. /* Set the USART LIN Break detection length. */
  271. MODIFY_REG(huart->Instance->CR2, USART_CR2_LBDL, BreakDetectLength);
  272. /* Enable the Peripheral */
  273. __HAL_UART_ENABLE(huart);
  274. /* TEACK and/or REACK to check before moving huart->gState and huart->RxState to Ready */
  275. return (UART_CheckIdleState(huart));
  276. }
  277. #endif /* !defined(STM32F030x6) && !defined(STM32F030x8)&& !defined(STM32F070xB)&& !defined(STM32F070x6)&& !defined(STM32F030xC) */
  278. /**
  279. * @}
  280. */
  281. /** @defgroup UARTEx_Exported_Functions_Group2 Extended IO operation function
  282. * @brief Extended UART Interrupt handling function
  283. *
  284. @verbatim
  285. ===============================================================================
  286. ##### IO operation function #####
  287. ===============================================================================
  288. [..]
  289. This subsection provides function to handle Wake up interrupt call-back.
  290. (#) Callback provided in No_Blocking mode:
  291. (++) HAL_UARTEx_WakeupCallback()
  292. @endverbatim
  293. * @{
  294. */
  295. #if !defined(STM32F030x6) && !defined(STM32F030x8)&& !defined(STM32F070xB)&& !defined(STM32F070x6)&& !defined(STM32F030xC)
  296. /**
  297. * @brief UART wakeup from Stop mode callback.
  298. * @param huart UART handle.
  299. * @retval None
  300. */
  301. __weak void HAL_UARTEx_WakeupCallback(UART_HandleTypeDef *huart)
  302. {
  303. /* Prevent unused argument(s) compilation warning */
  304. UNUSED(huart);
  305. /* NOTE : This function should not be modified, when the callback is needed,
  306. the HAL_UARTEx_WakeupCallback can be implemented in the user file.
  307. */
  308. }
  309. #endif /*!defined(STM32F030x6) && !defined(STM32F030x8)&& !defined(STM32F070xB)&& !defined(STM32F070x6)&& !defined(STM32F030xC)*/
  310. /**
  311. * @}
  312. */
  313. /** @defgroup UARTEx_Exported_Functions_Group3 Extended Peripheral Control functions
  314. * @brief Extended Peripheral Control functions
  315. *
  316. @verbatim
  317. ===============================================================================
  318. ##### Peripheral Control functions #####
  319. ===============================================================================
  320. [..]
  321. This subsection provides extended functions allowing to control the UART.
  322. (+) HAL_UARTEx_StopModeWakeUpSourceConfig() API sets Wakeup from Stop mode interrupt flag selection
  323. (+) HAL_UARTEx_EnableStopMode() API allows the UART to wake up the MCU from Stop mode as
  324. long as UART clock is HSI or LSE
  325. (+) HAL_UARTEx_DisableStopMode() API disables the above feature
  326. (+) HAL_MultiProcessorEx_AddressLength_Set() API optionally sets the UART node address
  327. detection length to more than 4 bits for multiprocessor address mark wake up.
  328. (+) HAL_LIN_SendBreak() API transmits the break characters
  329. @endverbatim
  330. * @{
  331. */
  332. #if !defined(STM32F030x6) && !defined(STM32F030x8)&& !defined(STM32F070xB)&& !defined(STM32F070x6)&& !defined(STM32F030xC)
  333. /**
  334. * @brief Set Wakeup from Stop mode interrupt flag selection.
  335. * @param huart UART handle.
  336. * @param WakeUpSelection address match, Start Bit detection or RXNE bit status.
  337. * This parameter can be one of the following values:
  338. * @arg @ref UART_WAKEUP_ON_ADDRESS
  339. * @arg @ref UART_WAKEUP_ON_STARTBIT
  340. * @arg @ref UART_WAKEUP_ON_READDATA_NONEMPTY
  341. * @retval HAL status
  342. */
  343. HAL_StatusTypeDef HAL_UARTEx_StopModeWakeUpSourceConfig(UART_HandleTypeDef *huart, UART_WakeUpTypeDef WakeUpSelection)
  344. {
  345. HAL_StatusTypeDef status = HAL_OK;
  346. uint32_t tickstart = 0U;
  347. /* check the wake-up from stop mode UART instance */
  348. assert_param(IS_UART_WAKEUP_FROMSTOP_INSTANCE(huart->Instance));
  349. /* check the wake-up selection parameter */
  350. assert_param(IS_UART_WAKEUP_SELECTION(WakeUpSelection.WakeUpEvent));
  351. /* Process Locked */
  352. __HAL_LOCK(huart);
  353. huart->gState = HAL_UART_STATE_BUSY;
  354. /* Disable the Peripheral */
  355. __HAL_UART_DISABLE(huart);
  356. /* Set the wake-up selection scheme */
  357. MODIFY_REG(huart->Instance->CR3, USART_CR3_WUS, WakeUpSelection.WakeUpEvent);
  358. if (WakeUpSelection.WakeUpEvent == UART_WAKEUP_ON_ADDRESS)
  359. {
  360. UARTEx_Wakeup_AddressConfig(huart, WakeUpSelection);
  361. }
  362. /* Enable the Peripheral */
  363. __HAL_UART_ENABLE(huart);
  364. /* Init tickstart for timeout managment*/
  365. tickstart = HAL_GetTick();
  366. /* Wait until REACK flag is set */
  367. if(UART_WaitOnFlagUntilTimeout(huart, USART_ISR_REACK, RESET, tickstart, HAL_UART_TIMEOUT_VALUE) != HAL_OK)
  368. {
  369. status = HAL_TIMEOUT;
  370. }
  371. else
  372. {
  373. /* Initialize the UART State */
  374. huart->gState = HAL_UART_STATE_READY;
  375. }
  376. /* Process Unlocked */
  377. __HAL_UNLOCK(huart);
  378. return status;
  379. }
  380. /**
  381. * @brief Enable UART Stop Mode.
  382. * @note The UART is able to wake up the MCU from Stop 1 mode as long as UART clock is HSI or LSE.
  383. * @param huart UART handle.
  384. * @retval HAL status
  385. */
  386. HAL_StatusTypeDef HAL_UARTEx_EnableStopMode(UART_HandleTypeDef *huart)
  387. {
  388. /* Check parameter */
  389. assert_param(IS_UART_WAKEUP_FROMSTOP_INSTANCE(huart->Instance));
  390. /* Process Locked */
  391. __HAL_LOCK(huart);
  392. huart->gState = HAL_UART_STATE_BUSY;
  393. /* Set UESM bit */
  394. SET_BIT(huart->Instance->CR1, USART_CR1_UESM);
  395. huart->gState = HAL_UART_STATE_READY;
  396. /* Process Unlocked */
  397. __HAL_UNLOCK(huart);
  398. return HAL_OK;
  399. }
  400. /**
  401. * @brief Disable UART Stop Mode.
  402. * @param huart UART handle.
  403. * @retval HAL status
  404. */
  405. HAL_StatusTypeDef HAL_UARTEx_DisableStopMode(UART_HandleTypeDef *huart)
  406. {
  407. /* Check parameter */
  408. assert_param(IS_UART_WAKEUP_FROMSTOP_INSTANCE(huart->Instance));
  409. /* Process Locked */
  410. __HAL_LOCK(huart);
  411. huart->gState = HAL_UART_STATE_BUSY;
  412. /* Clear UESM bit */
  413. CLEAR_BIT(huart->Instance->CR1, USART_CR1_UESM);
  414. huart->gState = HAL_UART_STATE_READY;
  415. /* Process Unlocked */
  416. __HAL_UNLOCK(huart);
  417. return HAL_OK;
  418. }
  419. #endif /* !defined(STM32F030x6) && !defined(STM32F030x8)&& !defined(STM32F070xB)&& !defined(STM32F070x6)&& !defined(STM32F030xC) */
  420. /**
  421. * @brief By default in multiprocessor mode, when the wake up method is set
  422. * to address mark, the UART handles only 4-bit long addresses detection;
  423. * this API allows to enable longer addresses detection (6-, 7- or 8-bit
  424. * long).
  425. * @note Addresses detection lengths are: 6-bit address detection in 7-bit data mode,
  426. * 7-bit address detection in 8-bit data mode, 8-bit address detection in 9-bit data mode.
  427. * @param huart UART handle.
  428. * @param AddressLength this parameter can be one of the following values:
  429. * @arg @ref UART_ADDRESS_DETECT_4B 4-bit long address
  430. * @arg @ref UART_ADDRESS_DETECT_7B 6-, 7- or 8-bit long address
  431. * @retval HAL status
  432. */
  433. HAL_StatusTypeDef HAL_MultiProcessorEx_AddressLength_Set(UART_HandleTypeDef *huart, uint32_t AddressLength)
  434. {
  435. /* Check the UART handle allocation */
  436. if(huart == NULL)
  437. {
  438. return HAL_ERROR;
  439. }
  440. /* Check the address length parameter */
  441. assert_param(IS_UART_ADDRESSLENGTH_DETECT(AddressLength));
  442. huart->gState = HAL_UART_STATE_BUSY;
  443. /* Disable the Peripheral */
  444. __HAL_UART_DISABLE(huart);
  445. /* Set the address length */
  446. MODIFY_REG(huart->Instance->CR2, USART_CR2_ADDM7, AddressLength);
  447. /* Enable the Peripheral */
  448. __HAL_UART_ENABLE(huart);
  449. /* TEACK and/or REACK to check before moving huart->gState to Ready */
  450. return (UART_CheckIdleState(huart));
  451. }
  452. #if !defined(STM32F030x6) && !defined(STM32F030x8)&& !defined(STM32F070xB)&& !defined(STM32F070x6)&& !defined(STM32F030xC)
  453. /**
  454. * @brief Transmit break characters.
  455. * @param huart UART handle.
  456. * @retval HAL status
  457. */
  458. HAL_StatusTypeDef HAL_LIN_SendBreak(UART_HandleTypeDef *huart)
  459. {
  460. /* Check the parameters */
  461. assert_param(IS_UART_LIN_INSTANCE(huart->Instance));
  462. /* Process Locked */
  463. __HAL_LOCK(huart);
  464. huart->gState = HAL_UART_STATE_BUSY;
  465. /* Send break characters */
  466. huart->Instance->RQR |= UART_SENDBREAK_REQUEST;
  467. huart->gState = HAL_UART_STATE_READY;
  468. /* Process Unlocked */
  469. __HAL_UNLOCK(huart);
  470. return HAL_OK;
  471. }
  472. #endif /* !defined(STM32F030x6) && !defined(STM32F030x8)&& !defined(STM32F070xB)&& !defined(STM32F070x6)&& !defined(STM32F030xC) */
  473. /**
  474. * @}
  475. */
  476. /**
  477. * @}
  478. */
  479. /** @addtogroup UARTEx_Private_Functions
  480. * @{
  481. */
  482. #if !defined(STM32F030x6) && !defined(STM32F030x8)&& !defined(STM32F070xB)&& !defined(STM32F070x6)&& !defined(STM32F030xC)
  483. /**
  484. * @brief Initialize the UART wake-up from stop mode parameters when triggered by address detection.
  485. * @param huart UART handle.
  486. * @param WakeUpSelection UART wake up from stop mode parameters.
  487. * @retval None
  488. */
  489. static void UARTEx_Wakeup_AddressConfig(UART_HandleTypeDef *huart, UART_WakeUpTypeDef WakeUpSelection)
  490. {
  491. /* Check parmeters */
  492. assert_param(IS_UART_WAKEUP_FROMSTOP_INSTANCE(huart->Instance));
  493. assert_param(IS_UART_ADDRESSLENGTH_DETECT(WakeUpSelection.AddressLength));
  494. /* Set the USART address length */
  495. MODIFY_REG(huart->Instance->CR2, USART_CR2_ADDM7, WakeUpSelection.AddressLength);
  496. /* Set the USART address node */
  497. MODIFY_REG(huart->Instance->CR2, USART_CR2_ADD, ((uint32_t)WakeUpSelection.Address << UART_CR2_ADDRESS_LSB_POS));
  498. }
  499. #endif /* !defined(STM32F030x6) && !defined(STM32F030x8)&& !defined(STM32F070xB)&& !defined(STM32F070x6)&& !defined(STM32F030xC) */
  500. /**
  501. * @}
  502. */
  503. #endif /* HAL_UART_MODULE_ENABLED */
  504. /**
  505. * @}
  506. */
  507. /**
  508. * @}
  509. */
  510. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/