]> git.donarmstrong.com Git - qmk_firmware.git/blob - tool/mbed/mbed-sdk/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F3/stm32f3xx_hal_usart_ex.h
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[qmk_firmware.git] / tool / mbed / mbed-sdk / libraries / mbed / targets / cmsis / TARGET_STM / TARGET_STM32F3 / stm32f3xx_hal_usart_ex.h
1 /**
2   ******************************************************************************
3   * @file    stm32f3xx_hal_usart_ex.h
4   * @author  MCD Application Team
5   * @version V1.1.0
6   * @date    12-Sept-2014
7   * @brief   Header file of USART HAL Extended module.
8   ******************************************************************************
9   * @attention
10   *                               
11   * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
12   *
13   * Redistribution and use in source and binary forms, with or without modification,
14   * are permitted provided that the following conditions are met:
15   *   1. Redistributions of source code must retain the above copyright notice,
16   *      this list of conditions and the following disclaimer.
17   *   2. Redistributions in binary form must reproduce the above copyright notice,
18   *      this list of conditions and the following disclaimer in the documentation
19   *      and/or other materials provided with the distribution.
20   *   3. Neither the name of STMicroelectronics nor the names of its contributors
21   *      may be used to endorse or promote products derived from this software
22   *      without specific prior written permission.
23   *
24   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34   *
35   ******************************************************************************  
36   */
37
38 /* Define to prevent recursive inclusion -------------------------------------*/
39 #ifndef __STM32F3xx_HAL_USART_EX_H
40 #define __STM32F3xx_HAL_USART_EX_H
41
42 #ifdef __cplusplus
43  extern "C" {
44 #endif
45
46 /* Includes ------------------------------------------------------------------*/
47 #include "stm32f3xx_hal_def.h"
48
49 /** @addtogroup STM32F3xx_HAL_Driver
50   * @{
51   */
52
53 /** @defgroup USARTEx USART Extended HAL module driver
54   * @{
55   */ 
56
57 /* Exported types ------------------------------------------------------------*/
58 /* Exported constants --------------------------------------------------------*/
59 /** @defgroup USARTEx_Exported_Constants USART Extended Exported Constants
60   * @{
61   */
62   
63 /** @defgroup USARTEx_Word_Length USART Extended Word Length
64   * @{
65   */
66 #if defined(STM32F302xE) || defined(STM32F303xE) || defined(STM32F398xx) || \
67     defined(STM32F334x8)                                                 || \
68     defined(STM32F301x8) || defined(STM32F302x8) || defined(STM32F318xx)
69 #define USART_WORDLENGTH_7B                  ((uint32_t)USART_CR1_M1)
70 #define USART_WORDLENGTH_8B                  ((uint32_t)0x00000000)
71 #define USART_WORDLENGTH_9B                  ((uint32_t)USART_CR1_M0)
72 #define IS_USART_WORD_LENGTH(LENGTH) (((LENGTH) == USART_WORDLENGTH_7B) || \
73                                       ((LENGTH) == USART_WORDLENGTH_8B) || \
74                                       ((LENGTH) == USART_WORDLENGTH_9B))
75 #else
76 #define USART_WORDLENGTH_8B                  ((uint32_t)0x00000000)
77 #define USART_WORDLENGTH_9B                  ((uint32_t)USART_CR1_M)
78 #define IS_USART_WORD_LENGTH(LENGTH) (((LENGTH) == USART_WORDLENGTH_8B) || \
79                                       ((LENGTH) == USART_WORDLENGTH_9B))
80 #endif /* STM32F302xE || STM32F303xE || STM32F398xx || */
81        /* STM32F334x8                               || */
82        /* STM32F301x8 || STM32F302x8 || STM32F318xx    */
83 /**
84   * @}
85   */
86
87
88   
89   
90 /**
91   * @}
92   */  
93   
94 /* Exported macro ------------------------------------------------------------*/
95
96 /** @defgroup USARTEx_Exported_Macros USART Extended Exported Macros
97   * @{
98   */
99   
100   
101 /** @brief  Reports the USART clock source.
102   * @param  __HANDLE__: specifies the USART Handle
103   * @param  __CLOCKSOURCE__ : output variable   
104   * @retval the USART clocking source, written in __CLOCKSOURCE__.
105   */
106 #if defined(STM32F303x8) || defined(STM32F334x8) || defined(STM32F328xx)
107 #define __HAL_USART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
108   do {                                                         \
109     if((__HANDLE__)->Instance == USART1)                       \
110     {                                                          \
111        switch(__HAL_RCC_GET_USART1_SOURCE())                   \
112        {                                                       \
113         case RCC_USART1CLKSOURCE_PCLK1:                        \
114           (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1;         \
115           break;                                               \
116         case RCC_USART1CLKSOURCE_HSI:                          \
117           (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI;           \
118           break;                                               \
119         case RCC_USART1CLKSOURCE_SYSCLK:                       \
120           (__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK;        \
121           break;                                               \
122         case RCC_USART1CLKSOURCE_LSE:                          \
123           (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE;           \
124           break;                                               \
125        }                                                       \
126     }                                                          \
127     else if((__HANDLE__)->Instance == USART2)                  \
128     {                                                          \
129        switch(__HAL_RCC_GET_USART2_SOURCE())                   \
130        {                                                       \
131         case RCC_USART2CLKSOURCE_PCLK1:                        \
132           (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1;         \
133           break;                                               \
134         case RCC_USART2CLKSOURCE_HSI:                          \
135           (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI;           \
136           break;                                               \
137         case RCC_USART2CLKSOURCE_SYSCLK:                       \
138           (__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK;        \
139           break;                                               \
140         case RCC_USART2CLKSOURCE_LSE:                          \
141           (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE;           \
142           break;                                               \
143        }                                                       \
144     }                                                          \
145     else if((__HANDLE__)->Instance == USART3)                  \
146     {                                                          \
147        switch(__HAL_RCC_GET_USART3_SOURCE())                   \
148        {                                                       \
149         case RCC_USART3CLKSOURCE_PCLK1:                        \
150           (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1;         \
151           break;                                               \
152         case RCC_USART3CLKSOURCE_HSI:                          \
153           (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI;           \
154           break;                                               \
155         case RCC_USART3CLKSOURCE_SYSCLK:                       \
156           (__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK;        \
157           break;                                               \
158         case RCC_USART3CLKSOURCE_LSE:                          \
159           (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE;           \
160           break;                                               \
161        }                                                       \
162     }                                                          \
163   } while(0)  
164 #else 
165 #define __HAL_USART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
166   do {                                                         \
167     if((__HANDLE__)->Instance == USART1)                       \
168     {                                                          \
169        switch(__HAL_RCC_GET_USART1_SOURCE())                   \
170        {                                                       \
171         case RCC_USART1CLKSOURCE_PCLK2:                        \
172           (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK2;         \
173           break;                                               \
174         case RCC_USART1CLKSOURCE_HSI:                          \
175           (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI;           \
176           break;                                               \
177         case RCC_USART1CLKSOURCE_SYSCLK:                       \
178           (__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK;        \
179           break;                                               \
180         case RCC_USART1CLKSOURCE_LSE:                          \
181           (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE;           \
182           break;                                               \
183        }                                                       \
184     }                                                          \
185     else if((__HANDLE__)->Instance == USART2)                  \
186     {                                                          \
187        switch(__HAL_RCC_GET_USART2_SOURCE())                   \
188        {                                                       \
189         case RCC_USART2CLKSOURCE_PCLK1:                        \
190           (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1;         \
191           break;                                               \
192         case RCC_USART2CLKSOURCE_HSI:                          \
193           (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI;           \
194           break;                                               \
195         case RCC_USART2CLKSOURCE_SYSCLK:                       \
196           (__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK;        \
197           break;                                               \
198         case RCC_USART2CLKSOURCE_LSE:                          \
199           (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE;           \
200           break;                                               \
201        }                                                       \
202     }                                                          \
203     else if((__HANDLE__)->Instance == USART3)                  \
204     {                                                          \
205        switch(__HAL_RCC_GET_USART3_SOURCE())                   \
206        {                                                       \
207         case RCC_USART3CLKSOURCE_PCLK1:                        \
208           (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1;         \
209           break;                                               \
210         case RCC_USART3CLKSOURCE_HSI:                          \
211           (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI;           \
212           break;                                               \
213         case RCC_USART3CLKSOURCE_SYSCLK:                       \
214           (__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK;        \
215           break;                                               \
216         case RCC_USART3CLKSOURCE_LSE:                          \
217           (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE;           \
218           break;                                               \
219        }                                                       \
220     }                                                          \
221   } while(0)  
222 #endif /* STM32F303x8 || STM32F334x8 || STM32F328xx */
223
224 /** @brief  Computes the USART mask to apply to retrieve the received data
225   *         according to the word length and to the parity bits activation.
226   *         If PCE = 1, the parity bit is not included in the data extracted
227   *         by the reception API().
228   *         This masking operation is not carried out in the case of
229   *         DMA transfers.    
230   * @param  __HANDLE__: specifies the USART Handle
231   * @retval none
232   */  
233 #if defined(STM32F302xE) || defined(STM32F303xE) || defined(STM32F398xx) || \
234     defined(STM32F334x8)                                                 || \
235     defined(STM32F301x8) || defined(STM32F302x8) || defined(STM32F318xx)
236 #define __HAL_USART_MASK_COMPUTATION(__HANDLE__)                      \
237   do {                                                                \
238   if ((__HANDLE__)->Init.WordLength == USART_WORDLENGTH_9B)           \
239   {                                                                   \
240      if ((__HANDLE__)->Init.Parity == USART_PARITY_NONE)              \
241      {                                                                \
242         (__HANDLE__)->Mask = 0x01FF ;                                 \
243      }                                                                \
244      else                                                             \
245      {                                                                \
246         (__HANDLE__)->Mask = 0x00FF ;                                 \
247      }                                                                \
248   }                                                                   \
249   else if ((__HANDLE__)->Init.WordLength == USART_WORDLENGTH_8B)      \
250   {                                                                   \
251      if ((__HANDLE__)->Init.Parity == USART_PARITY_NONE)              \
252      {                                                                \
253         (__HANDLE__)->Mask = 0x00FF ;                                 \
254      }                                                                \
255      else                                                             \
256      {                                                                \
257         (__HANDLE__)->Mask = 0x007F ;                                 \
258      }                                                                \
259   }                                                                   \
260   else if ((__HANDLE__)->Init.WordLength == USART_WORDLENGTH_7B)      \
261   {                                                                   \
262      if ((__HANDLE__)->Init.Parity == USART_PARITY_NONE)              \
263      {                                                                \
264         (__HANDLE__)->Mask = 0x007F ;                                 \
265      }                                                                \
266      else                                                             \
267      {                                                                \
268         (__HANDLE__)->Mask = 0x003F ;                                 \
269      }                                                                \
270   }                                                                   \
271 } while(0) 
272 #else
273 #define __HAL_USART_MASK_COMPUTATION(__HANDLE__)                      \
274   do {                                                                \
275   if ((__HANDLE__)->Init.WordLength == USART_WORDLENGTH_9B)           \
276   {                                                                   \
277      if ((__HANDLE__)->Init.Parity == USART_PARITY_NONE)              \
278      {                                                                \
279         (__HANDLE__)->Mask = 0x01FF ;                                 \
280      }                                                                \
281      else                                                             \
282      {                                                                \
283         (__HANDLE__)->Mask = 0x00FF ;                                 \
284      }                                                                \
285   }                                                                   \
286   else if ((__HANDLE__)->Init.WordLength == USART_WORDLENGTH_8B)      \
287   {                                                                   \
288      if ((__HANDLE__)->Init.Parity == USART_PARITY_NONE)              \
289      {                                                                \
290         (__HANDLE__)->Mask = 0x00FF ;                                 \
291      }                                                                \
292      else                                                             \
293      {                                                                \
294         (__HANDLE__)->Mask = 0x007F ;                                 \
295      }                                                                \
296   }                                                                   \
297 } while(0) 
298 #endif /* STM32F302xE || STM32F303xE || STM32F398xx || */
299        /* STM32F334x8                               || */
300        /* STM32F301x8 || STM32F302x8 || STM32F318xx    */
301 /**
302   * @}
303   */
304
305 /* Exported functions --------------------------------------------------------*/
306 /* Initialization and de-initialization functions  ****************************/
307 /* IO operation functions *****************************************************/
308 /* Peripheral Control functions ***********************************************/
309 /* Peripheral State and Error functions ***************************************/
310
311
312 /**
313   * @}
314   */ 
315
316 /**
317   * @}
318   */ 
319   
320 #ifdef __cplusplus
321 }
322 #endif
323
324 #endif /* __STM32F3xx_HAL_USART_EX_H */
325
326 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/