stm32f0xx_hal_uart_ex.c 23 KB

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