1 ////////////////////////////////////////////////////////////////////////////////
2 /// @file     hal_uart.c
3 /// @file     hal_uart.c
4 /// @author   AE TEAM
5 /// @brief    THIS FILE PROVIDES ALL THE UART FIRMWARE FUNCTIONS.
6 ////////////////////////////////////////////////////////////////////////////////
7 /// @attention
8 ///
9 /// THE EXISTING FIRMWARE IS ONLY FOR REFERENCE, WHICH IS DESIGNED TO PROVIDE
10 /// CUSTOMERS WITH CODING INFORMATION ABOUT THEIR PRODUCTS SO THEY CAN SAVE
11 /// TIME. THEREFORE, MINDMOTION SHALL NOT BE LIABLE FOR ANY DIRECT, INDIRECT OR
12 /// CONSEQUENTIAL DAMAGES ABOUT ANY CLAIMS ARISING OUT OF THE CONTENT OF SUCH
13 /// HARDWARE AND/OR THE USE OF THE CODING INFORMATION CONTAINED HEREIN IN
14 /// CONNECTION WITH PRODUCTS MADE BY CUSTOMERS.
15 ///
16 /// <H2><CENTER>&COPY; COPYRIGHT MINDMOTION </CENTER></H2>
17 ////////////////////////////////////////////////////////////////////////////////
18 
19 // Define to prevent recursive inclusion
20 #define _HAL_UART_C_
21 
22 // Files includes
23 #include "hal_rcc.h"
24 #include "hal_uart.h"
25 #include "hal_gpio.h"
26 #include "hal_dma.h"
27 ////////////////////////////////////////////////////////////////////////////////
28 /// @addtogroup MM32_Hardware_Abstract_Layer
29 /// @{
30 
31 ////////////////////////////////////////////////////////////////////////////////
32 ///@addtogroup UART_HAL
33 ///@{
34 
35 ////////////////////////////////////////////////////////////////////////////////
36 /// @addtogroup UART_Exported_Functions
37 /// @{
38 
39 ////////////////////////////////////////////////////////////////////////////////
40 /// @brief  Deinitializes the uart peripheral registers to their
41 ///         default reset values.
42 /// @param  uart: Select the UART or the UART peripheral.
43 /// @retval None.
44 ////////////////////////////////////////////////////////////////////////////////
UART_DeInit(UART_TypeDef * uart)45 void UART_DeInit(UART_TypeDef* uart)
46 {
47 
48 
49     if(UART2 == uart) {
50         exRCC_APB1PeriphReset(RCC_APB1ENR_UART2);
51     }
52     if(UART1 == uart) {
53         exRCC_APB2PeriphReset(RCC_APB2ENR_UART1);
54     }
55     if(UART3 == uart) {
56         exRCC_APB1PeriphReset(RCC_APB1ENR_UART3);
57     }
58     if(UART4 == uart) {
59         exRCC_APB1PeriphReset(RCC_APB1ENR_UART4);
60     }
61     if(UART5 == uart) {
62         exRCC_APB1PeriphReset(RCC_APB1ENR_UART5);
63     }
64     if(UART6 == uart) {
65         exRCC_APB2PeriphReset(RCC_APB2ENR_UART6);
66     }
67     if(UART7 == uart) {
68         exRCC_APB1PeriphReset(RCC_APB1ENR_UART7);
69     }
70     if(UART8 == uart) {
71         exRCC_APB1PeriphReset(RCC_APB1ENR_UART8);
72     }
73 }
74 
75 ////////////////////////////////////////////////////////////////////////////////
76 /// @brief  Initializes the uart peripheral according to the specified
77 ///         parameters in the UART_InitStruct .
78 /// @param  uart: Select the UART or the UART peripheral.
79 /// @param  init_struct: pointer to a UART_InitTypeDef structure
80 ///         that contains the configuration information for the
81 ///         specified UART peripheral.
82 /// @retval None.
83 ////////////////////////////////////////////////////////////////////////////////
UART_Init(UART_TypeDef * uart,UART_InitTypeDef * init_struct)84 void UART_Init(UART_TypeDef* uart, UART_InitTypeDef* init_struct)
85 {
86     u32 apbclock = 0x00;
87     // UART CCR Configuration
88     MODIFY_REG(uart->CCR, UART_CCR_CHAR, init_struct->WordLength);
89 
90 
91     MODIFY_REG(uart->CCR, (UART_CCR_SPB0 | UART_CCR_SPB1), init_struct->StopBits);
92 
93     MODIFY_REG(uart->CCR, (UART_CCR_PEN | UART_CCR_PSEL), init_struct->Parity);
94 
95     // UART GCR Configuration
96     MODIFY_REG(uart->GCR, (UART_GCR_TX | UART_GCR_RX), init_struct->Mode);
97     MODIFY_REG(uart->GCR, UART_GCR_AUTOFLOW, init_struct->HWFlowControl);
98 
99     //UART BRR Configuration
100     //Configure the UART Baud Rate
101     if (uart == UART1) {
102 
103         apbclock = RCC_GetPCLK2Freq();
104     }
105     else {
106         apbclock = RCC_GetPCLK1Freq();
107     }
108     // Determine the UART_baud
109     uart->BRR = (apbclock / init_struct->BaudRate) / 16;
110     uart->FRA = (apbclock / init_struct->BaudRate) % 16;
111 }
112 
113 ////////////////////////////////////////////////////////////////////////////////
114 /// @brief  Fills each UART_InitStruct member with its default value.
115 /// @param  init_struct: pointer to a UART_InitTypeDef structure
116 ///         which will be initialized.
117 /// @retval None.
118 ////////////////////////////////////////////////////////////////////////////////
UART_StructInit(UART_InitTypeDef * init_struct)119 void UART_StructInit(UART_InitTypeDef* init_struct)
120 {
121     // UART_InitStruct members default value
122     init_struct->BaudRate       = 9600;
123     init_struct->WordLength     = UART_WordLength_8b;
124     init_struct->StopBits       = UART_StopBits_1;
125     init_struct->Parity         = UART_Parity_No;
126     init_struct->Mode           = UART_GCR_RX | UART_GCR_TX;
127     init_struct->HWFlowControl  = UART_HWFlowControl_None;
128 }
129 
130 ////////////////////////////////////////////////////////////////////////////////
131 /// @brief  Enables or disables the specified UART peripheral.
132 /// @param  uart: Select the UART or the UART peripheral.
133 /// @param  state: new state of the uart peripheral.
134 ///         This parameter can be: ENABLE or DISABLE.
135 /// @retval None.
136 ////////////////////////////////////////////////////////////////////////////////
UART_Cmd(UART_TypeDef * uart,FunctionalState state)137 void UART_Cmd(UART_TypeDef* uart, FunctionalState state)
138 {
139     MODIFY_REG(uart->GCR, UART_GCR_UART, state << UART_GCR_UART_Pos);
140 }
141 
142 ////////////////////////////////////////////////////////////////////////////////
143 /// @brief  Enables or disables the specified UART interrupts.
144 /// @param  uart: Select the UART or the UART peripheral.
145 /// @param  it: specifies the UART interrupt sources to be
146 ///         enabled or disabled.
147 ///         This parameter can be one of the following values:
148 /// @arg    UART_IT_ERR:  Error interrupt(Frame error,)
149 /// @arg    UART_IT_PE:   Parity Error interrupt
150 /// @arg    UART_OVER_ERR:  overrun Error interrupt
151 /// @arg    UART_IT_RXIEN: Receive Data register interrupt
152 /// @arg    UART_IT_TXIEN:  Tansmit Data Register empty interrupt
153 ///
154 /// @param  state: new state of the specified uart interrupts.
155 ///         This parameter can be: ENABLE or DISABLE.
156 /// @retval None.
157 ////////////////////////////////////////////////////////////////////////////////
UART_ITConfig(UART_TypeDef * uart,u16 it,FunctionalState state)158 void UART_ITConfig(UART_TypeDef* uart, u16 it, FunctionalState state)
159 {
160     (state) ? (uart->IER |= it) : (uart->IER &= ~it);
161 }
162 ////////////////////////////////////////////////////////////////////////////////
163 /// @brief  Enables or disables the UART DMA interface.
164 /// @param  uart: Select the UART or the UART peripheral.
165 /// @param  dma_request: specifies the DMA request.
166 ///         This parameter can be any combination of the following values:
167 /// @arg    UART_DMAReq_EN: UART DMA transmit request
168 ///
169 /// @param  state: new state of the DMA Request sources.
170 ///         This parameter can be: ENABLE or DISABLE.
171 /// @retval None.
172 ////////////////////////////////////////////////////////////////////////////////
UART_DMACmd(UART_TypeDef * uart,u16 dma_request,FunctionalState state)173 void UART_DMACmd(UART_TypeDef* uart, u16 dma_request, FunctionalState state)
174 {
175     MODIFY_REG(uart->GCR, UART_GCR_DMA, state << UART_GCR_DMA_Pos);
176 }
177 ////////////////////////////////////////////////////////////////////////////////
178 /// @brief  Transmits single data through the uart peripheral.
179 /// @param  uart: Select the UART or the UART peripheral.
180 /// @param  Data: the data to transmit.
181 /// @retval None.
182 ////////////////////////////////////////////////////////////////////////////////
UART_SendData(UART_TypeDef * uart,u16 value)183 void UART_SendData(UART_TypeDef* uart, u16 value)
184 {
185     // Transmit Data
186     WRITE_REG(uart->TDR, (value & 0xFFU));
187 }
188 
189 ////////////////////////////////////////////////////////////////////////////////
190 /// @brief  Returns the most recent received data by the uart peripheral.
191 /// @param  uart: Select the UART or the UART peripheral.
192 /// @retval  The received data.
193 ////////////////////////////////////////////////////////////////////////////////
UART_ReceiveData(UART_TypeDef * uart)194 u16 UART_ReceiveData(UART_TypeDef* uart)
195 {
196     // Receive Data
197     return (u16)(uart->RDR & 0xFFU);
198 }
199 
200 ////////////////////////////////////////////////////////////////////////////////
201 /// @brief  Checks whether the specified UART flag is set or not.
202 /// @param  uart: Select the UART or the UART peripheral.
203 /// @param  flag: specifies the flag to check.
204 ///         This parameter can be one of the following values:
205 /// @arg    UART_FLAG_TXEMPTY: Transmit data register empty flag
206 /// @arg    UART_FLAG_TXFULL: Transmit data buffer full
207 /// @arg    UART_FLAG_RXAVL: RX Buffer has a byte flag
208 /// @arg    UART_FLAG_TXEPT: tx and shifter are emptys flag
209 /// @retval  The new state of UART_FLAG (SET or RESET).
210 ////////////////////////////////////////////////////////////////////////////////
UART_GetFlagStatus(UART_TypeDef * uart,u16 flag)211 FlagStatus UART_GetFlagStatus(UART_TypeDef* uart, u16 flag)
212 {
213     return (uart->CSR & flag) ? SET : RESET;
214 }
215 
216 
217 
218 ////////////////////////////////////////////////////////////////////////////////
219 /// @brief  Checks whether the specified UART interrupt has occurred or not.
220 /// @param  uart: Select the UART or the UART peripheral.
221 /// @param  it: specifies the UART interrupt source to check.
222 ///         This parameter can be one of the following values:
223 /// @arg    UART_IT_ERR:  Error interrupt(Frame error,)
224 /// @arg    UART_IT_PE:   Parity Error interrupt
225 /// @arg    UART_OVER_ERR:  overrun Error interrupt
226 /// @arg    UART_IT_RXIEN: Receive Data register interrupt
227 /// @arg    UART_IT_TXIEN:  Tansmit Data Register empty interrupt
228 /// @retval  The new state of UART_IT (SET or RESET).
229 ////////////////////////////////////////////////////////////////////////////////
UART_GetITStatus(UART_TypeDef * uart,u16 it)230 ITStatus UART_GetITStatus(UART_TypeDef* uart, u16 it)
231 {
232     return (uart->ISR & it) ? SET : RESET;
233 }
234 
235 ////////////////////////////////////////////////////////////////////////////////
236 /// @brief  Clears the uart interrupt pending bits.
237 /// @param  uart: Select the UART or the UART peripheral.
238 /// @param  it: specifies the interrupt pending bit to clear.
239 ///         This parameter can be one of the following values:
240 /// @arg    UART_IT_ERR:  Error interrupt(Frame error,)
241 /// @arg    UART_IT_PE:   Parity Error interrupt
242 /// @arg    UART_OVER_ERR:  overrun Error interrupt
243 /// @arg    UART_IT_RXIEN: Receive Data register interrupt
244 /// @arg    UART_IT_TXIEN:  Tansmit Data Register empty interrupt
245 /// @retval None.
246 ////////////////////////////////////////////////////////////////////////////////
UART_ClearITPendingBit(UART_TypeDef * uart,u16 it)247 void UART_ClearITPendingBit(UART_TypeDef* uart, u16 it)
248 {
249     //clear UART_IT pendings bit
250     uart->ICR = it;
251 }
252 
253 ////////////////////////////////////////////////////////////////////////////////
254 /// @brief  Selects the UART WakeUp method.
255 /// @param  uart: Select the UART or the UART peripheral.
256 /// @param  mode: specifies the UART wakeup method.
257 /// @retval None.
258 ////////////////////////////////////////////////////////////////////////////////
UART_WakeUpConfig(UART_TypeDef * uart,UART_WakeUp_TypeDef mode)259 void UART_WakeUpConfig(UART_TypeDef* uart, UART_WakeUp_TypeDef mode)
260 {
261     MODIFY_REG(uart->CCR, UART_CCR_WAKE, mode);
262 }
263 
264 ////////////////////////////////////////////////////////////////////////////////
265 /// @brief  Determines if the UART is in mute mode or not.
266 /// @param  uart: Select the UART or the UART peripheral.
267 /// @param  state: new state of the UART mute mode.
268 /// @retval None.
269 ////////////////////////////////////////////////////////////////////////////////
UART_ReceiverWakeUpCmd(UART_TypeDef * uart,FunctionalState state)270 void UART_ReceiverWakeUpCmd(UART_TypeDef* uart, FunctionalState state)
271 {
272     MODIFY_REG(uart->CCR, UART_CCR_RWU, state << UART_CCR_RWU_Pos);
273 }
274 
275 ////////////////////////////////////////////////////////////////////////////////
276 /// @brief  Sets the address of the UART Rx Address.
277 /// @param  uart: Select the UART or the UART peripheral.
278 /// @param  address: Indicates the address of the UART Rx Address.
279 /// @retval None.
280 ////////////////////////////////////////////////////////////////////////////////
UART_SetRXAddress(UART_TypeDef * uart,u8 address)281 void UART_SetRXAddress(UART_TypeDef* uart, u8 address)
282 {
283     MODIFY_REG(uart->RXAR, UART_RXAR_ADDR, address);
284 }
285 
286 ////////////////////////////////////////////////////////////////////////////////
287 /// @brief  Sets the address of the UART Rx MASK.
288 /// @param  uart: Select the UART or the UART peripheral.
289 /// @param  address: Indicates the address of the UART Rx MASK.
290 /// @retval None.
291 ////////////////////////////////////////////////////////////////////////////////
UART_SetRXMASK(UART_TypeDef * uart,u8 address)292 void UART_SetRXMASK(UART_TypeDef* uart, u8 address)
293 {
294     MODIFY_REG(uart->RXMR, UART_RXMR_MASK, address);
295 }
296 
297 ////////////////////////////////////////////////////////////////////////////////
298 /// @brief  ENBALE or DISABLE the UART's 9bit.
299 /// @param  uart: Select the UART or the UART peripheral.
300 /// @param  state: new state of the UART 9 bit.
301 /// @retval None.
302 ////////////////////////////////////////////////////////////////////////////////
UART_Enable9bit(UART_TypeDef * uart,FunctionalState state)303 void UART_Enable9bit(UART_TypeDef* uart, FunctionalState state)
304 {
305     MODIFY_REG(uart->CCR, UART_CCR_B8EN, state << UART_CCR_B8EN_Pos);
306 }
307 
308 ////////////////////////////////////////////////////////////////////////////////
309 /// @brief  Set the UART's 9bit Level.
310 /// @param  uart: Select the UART or the UART peripheral.
311 /// @param  state: new state of the UART 9 bit.
312 /// @retval None.
313 ////////////////////////////////////////////////////////////////////////////////
UART_Set9bitLevel(UART_TypeDef * uart,FunctionalState state)314 void UART_Set9bitLevel(UART_TypeDef* uart, FunctionalState state)
315 {
316     MODIFY_REG(uart->CCR, UART_CCR_B8TXD, state << UART_CCR_B8TXD_Pos);
317 }
318 
319 ////////////////////////////////////////////////////////////////////////////////
320 /// @brief  Set the UART's 9bit Polarity.
321 /// @param  uart: Select the UART or the UART peripheral.
322 /// @param  polarity: new state of the UART 9 bit Polarity.
323 /// @retval None.
324 ////////////////////////////////////////////////////////////////////////////////
UART_Set9bitPolarity(UART_TypeDef * uart,UART_9bit_Polarity_TypeDef polarity)325 void UART_Set9bitPolarity(UART_TypeDef* uart, UART_9bit_Polarity_TypeDef polarity)
326 {
327     MODIFY_REG(uart->CCR, UART_CCR_B8POL, polarity);
328 }
329 
330 ////////////////////////////////////////////////////////////////////////////////
331 /// @brief  Set the UART's 9bit Automatic Toggle.
332 /// @param  uart: Select the UART or the UART peripheral.
333 /// @param  state: new state of the UART 9 bit Automatic Toggle.
334 /// @retval None.
335 ////////////////////////////////////////////////////////////////////////////////
UART_Set9bitAutomaticToggle(UART_TypeDef * uart,FunctionalState state)336 void UART_Set9bitAutomaticToggle(UART_TypeDef* uart, FunctionalState state)
337 {
338     MODIFY_REG(uart->CCR, UART_CCR_B8TOG, state << UART_CCR_B8TOG_Pos);
339 }
340 
341 ////////////////////////////////////////////////////////////////////////////////
342 /// @brief  Enables or disables the UART Half Duplex communication.
343 /// @param  uart: Select the UART or the UART peripheral.
344 /// @param  state: new state of the UART Communication.
345 /// @retval None.
346 ////////////////////////////////////////////////////////////////////////////////
UART_HalfDuplexCmd(UART_TypeDef * uart,FunctionalState state)347 void UART_HalfDuplexCmd(UART_TypeDef* uart, FunctionalState state)
348 {
349     MODIFY_REG(uart->SCR, UART_SCR_HDSEL, state << UART_SCR_HDSEL_Pos);
350 }
351 
352 ////////////////////////////////////////////////////////////////////////////////
353 /// @brief  Sets the specified UART guard time.
354 /// @param  uart: Select the UART or the UART peripheral.
355 /// @param  guard_time: specifies the guard time.
356 /// @retval None.
357 ////////////////////////////////////////////////////////////////////////////////
UART_SetGuardTime(UART_TypeDef * uart,u8 guard_time)358 void UART_SetGuardTime(UART_TypeDef* uart, u8 guard_time)
359 {
360     MODIFY_REG(uart->SCR, UART_SCR_SCFCNT, guard_time << UART_SCR_SCFCNT_Pos);
361     // Clear the UART Guard time
362     // uart->SCR &= SCR_SCFCNT_Mask;
363     // Set the UART guard time
364     // uart->SCR |= (u16)((u16)guard_time << 0x04);
365 }
366 
367 ////////////////////////////////////////////////////////////////////////////////
368 /// @brief  Enables or disables the UART's Smart Card mode.
369 /// @param  uart: Select the UART or the UART peripheral.
370 /// @param  state: new state of the Smart Card mode.
371 /// @retval None.
372 ////////////////////////////////////////////////////////////////////////////////
UART_SmartCardCmd(UART_TypeDef * uart,FunctionalState state)373 void UART_SmartCardCmd(UART_TypeDef* uart, FunctionalState state)
374 {
375     MODIFY_REG(uart->SCR, UART_SCR_SCEN, state << UART_SCR_SCEN_Pos);
376 }
377 
378 ////////////////////////////////////////////////////////////////////////////////
379 /// @brief  Enables or disables NACK transmission.
380 /// @param  uart: Select the UART or the UART peripheral.
381 /// @param  state: new state of the NACK transmission.
382 /// @retval None.
383 ////////////////////////////////////////////////////////////////////////////////
UART_SmartCardNACKCmd(UART_TypeDef * uart,FunctionalState state)384 void UART_SmartCardNACKCmd(UART_TypeDef* uart, FunctionalState state)
385 {
386     MODIFY_REG(uart->SCR, UART_SCR_SCARB, state << UART_SCR_SCARB_Pos);
387 }
388 
389 ////////////////////////////////////////////////////////////////////////////////
390 /// @brief  Transmits break characters.
391 /// @param  uart: Select the UART or the UART peripheral.
392 /// @retval None.
393 ////////////////////////////////////////////////////////////////////////////////
UART_SendBreak(UART_TypeDef * uart)394 void UART_SendBreak(UART_TypeDef* uart)
395 {
396     SET_BIT(uart->CCR, UART_CCR_BRK);
397 }
398 
399 ////////////////////////////////////////////////////////////////////////////////
400 /// @brief  Enable or Disable Auto Baud-Rate Detection
401 /// @param  uart: Select the UART or the UART peripheral.
402 /// @param  state: new state of the UART AutoBaudRate Detection.
403 /// @retval None.
404 ////////////////////////////////////////////////////////////////////////////////
UART_AutoBaudRateCmd(UART_TypeDef * uart,FunctionalState state)405 void UART_AutoBaudRateCmd(UART_TypeDef* uart, FunctionalState state)
406 {
407     state ? SET_BIT(uart->ABRCR, UART_ABRCR_ABREN) : CLEAR_BIT(uart->ABRCR, UART_ABRCR_ABREN) ;
408 }
409 ////////////////////////////////////////////////////////////////////////////////
410 /// @brief  AutoBaudRate.
411 /// @param  uart: Select the UART or the UART peripheral.
412 ///         value: special character.
413 ///         state: ENABLE/DISABLE.
414 /// @retval None.
415 ////////////////////////////////////////////////////////////////////////////////
UART_AutoBaudRateSet(UART_TypeDef * uart,UART_AutoBaud_TypeDef value,FunctionalState state)416 void UART_AutoBaudRateSet(UART_TypeDef* uart, UART_AutoBaud_TypeDef value, FunctionalState state)
417 {
418     CLEAR_BIT(uart->ABRCR, UART_ABRCR_ABREN);
419     //This bit field can only be written when ABREN = 0 or the UART is disabled (UARTEN=0).
420 
421     if ((value == ABRMODE_FALLING_TO_RISINGEDGE1BIT) || (value == ABRMODE_STARTBIT) || (value == ABRMODE_VALUE0XFF)) {
422         //UART measures the duration of the start bit (falling edge) to first rising edge
423         //FORMER edge = 0  LATTER edge= 1, from fist falling edge to rising edge = one bit
424         //___   _               _______
425         //   |_|1 x x x x x x x|        = Bxxxx xxx1  F to U = 1 start bit
426         //
427         MODIFY_REG(uart->ABRCR, UART_ABRCR_LATTER | UART_ABRCR_FORMER | UART_ABRCR_BITCNT, \
428                    UART_ABRCR_LATTER | UART_ABRCR_BITCNT_MODE0 );
429     }
430     else if((value == ABRMODE_FALLING_TO_RISINGEDGE2BIT) || (value == Data_FE))  {
431         //UART measures the duration of the start bit (falling edge) to first rising edge
432         //FORMER edge = 0  LATTER edge= 1, from fist falling edge to rising edge = two bit
433         //___     _             _______
434         //   |_ _|1 x x x x x x|        = Bxxxx xx10  F to U = 2
435         //
436         MODIFY_REG(uart->ABRCR, UART_ABRCR_LATTER | UART_ABRCR_FORMER | UART_ABRCR_BITCNT, \
437                    UART_ABRCR_LATTER | UART_ABRCR_BITCNT_MODE1);
438     }
439     else if((value == ABRMODE_FALLING_TO_RISINGEDGE4BIT) || (value == Data_F8)) {
440         //UART measures the duration of the start bit (falling edge) to first rising edge
441         //FORMER edge = 0  LATTER edge= 1, from fist falling edge to rising edge = four bit
442         //___         _         _______
443         //   |_ _ _ _|1 x x x x|        = Bxxxx 1000  F to U = 4
444         //
445         MODIFY_REG(uart->ABRCR, UART_ABRCR_LATTER | UART_ABRCR_FORMER | UART_ABRCR_BITCNT, \
446                    UART_ABRCR_LATTER | UART_ABRCR_BITCNT_MODE2);
447     }
448     else if((value == ABRMODE_FALLING_TO_RISINGEDGE8BIT) || (value == ABRMODE_VALUE0X80))  {
449         //UART measures the duration of the start bit (falling edge) to first rising edge
450         //FORMER edge = 0  LATTER edge= 1, from fist falling edge to rising edge = eight bit
451         //___                 _ ______
452         //   |_ _ _ _ _ _ _ _|1         = B1000 0000  F to U = 8
453         //
454         MODIFY_REG(uart->ABRCR, UART_ABRCR_LATTER | UART_ABRCR_FORMER | UART_ABRCR_BITCNT, \
455                    UART_ABRCR_LATTER | UART_ABRCR_BITCNT_MODE3);
456     }
457     else if((value == ABRMODE_FALLING_TO_FALLINGEDGE2BIT) || (value == ABRMODE_VALUE0X55)) {
458         //UART measures the duration of the start bit (falling edge) to next falling edge
459         //FORMER edge = 0  LATTER edge= 0, from fist falling edge to next falling edge = two bit
460         //___   _               ______
461         //   |_|1|_|x x x x x x|        = Bxxxx xx01  F to F = 2 0x55 and Falling to Falling
462         //
463         MODIFY_REG(uart->ABRCR, UART_ABRCR_LATTER | UART_ABRCR_FORMER | UART_ABRCR_BITCNT, \
464                    UART_ABRCR_BITCNT_MODE1);
465     }
466     else if((value == ABRMODE_FALLING_TO_FALLINGEDGE4BIT) || (value == ABRMODE_VALUE0XF7))  {
467         //UART measures the duration of the start bit (falling edge) to next falling edge
468         //FORMER edge = 0  LATTER edge= 0, from fist falling edge to next falling edge = four bit
469         //___   _ _ _           ______
470         //   |_|1 1 1|_|x x x x|        = Bxxxx 0111  F to F = 4
471         //
472         MODIFY_REG(uart->ABRCR, UART_ABRCR_LATTER | UART_ABRCR_FORMER | UART_ABRCR_BITCNT, \
473                    UART_ABRCR_BITCNT_MODE2);
474     }
475     else if((value == ABRMODE_FALLING_TO_FALLINGEDGE8BIT) || (value == ABRMODE_VALUE0x7F)) {
476         //UART measures the duration of the start bit (falling edge) to next falling edge
477         //FORMER edge = 0  LATTER edge= 0, from fist falling edge to next falling edge = eight bit
478         //___   _ _ _ _ _ _ _   ______
479         //   |_|1 1 1 1 1 1 1|_|        = B0111 1111  F to F = 8 0x7F
480         //
481         MODIFY_REG(uart->ABRCR, UART_ABRCR_LATTER | UART_ABRCR_FORMER | UART_ABRCR_BITCNT, \
482                    UART_ABRCR_BITCNT_MODE3);
483     }
484 
485     else {
486         //UART measures the duration of the start bit (falling edge) to next falling edge
487         //FORMER edge = 0  LATTER edge= 0, from fist falling edge to next falling edge = eight bit
488         //___   _ _ _ _ _ _ _   ______
489         //   |_|1 1 1 1 1 1 1|_|        = B0111 1111  F to F = 8 0x7F
490         //
491         MODIFY_REG(uart->ABRCR, UART_ABRCR_LATTER | UART_ABRCR_FORMER | UART_ABRCR_BITCNT, \
492                    UART_ABRCR_BITCNT_MODE3);
493     }
494     if(state == ENABLE) {
495         SET_BIT(uart->ABRCR, UART_ABRCR_ABREN);
496     }
497 }
498 /// @}
499 
500 /// @}
501 
502 /// @}
503