forked from stm32duino/Arduino_Core_STM32
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathuart.c
806 lines (744 loc) · 20.7 KB
/
uart.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
/**
******************************************************************************
* @file uart.c
* @author WI6LABS
* @version V1.0.0
* @date 01-August-2016
* @brief provide the UART interface
*
******************************************************************************
* @attention
*
* <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STMicroelectronics nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************
*/
/** @addtogroup CMSIS
* @{
*/
/** @addtogroup stm32f4xx_system
* @{
*/
/** @addtogroup STM32F4xx_System_Private_Includes
* @{
*/
#include "hw_config.h"
#include "uart.h"
#include "digital_io.h"
#include "interrupt.h"
#include "variant.h"
#include "PinAF_STM32F1.h"
#ifdef __cplusplus
extern "C" {
#endif
// @brief uart caracteristics
#if defined(STM32F4xx)
#define UART_NUM (10)
#elif defined(STM32F0xx) || defined(STM32F7xx)
#define UART_NUM (8)
#elif defined(STM32F2xx)
#define UART_NUM (6)
#else // STM32F1xx || STM32F3xx || STM32L0xx || STM32L1xx || STM32L4xx
#define UART_NUM (5)
#endif
static UART_HandleTypeDef *uart_handlers[UART_NUM] = {NULL};
static void (*rx_callback[UART_NUM])(serial_t*);
static serial_t *rx_callback_obj[UART_NUM];
static int (*tx_callback[UART_NUM])(serial_t*);
static serial_t *tx_callback_obj[UART_NUM];
static uint8_t rx_buffer[1] = {0};
/**
* @brief Function called to initialize the uart interface
* @param obj : pointer to serial_t structure
* @retval None
*/
void uart_init(serial_t *obj)
{
if(obj == NULL) {
return;
}
UART_HandleTypeDef *huart = &(obj->handle);
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_TypeDef *port;
// Determine the UART to use (UART_1, UART_2, ...)
USART_TypeDef *uart_tx = pinmap_peripheral(obj->pin_tx, PinMap_UART_TX);
USART_TypeDef *uart_rx = pinmap_peripheral(obj->pin_rx, PinMap_UART_RX);
//Pins Rx/Tx must not be NP
if(uart_rx == NP || uart_tx == NP) {
printf("ERROR: at least one UART pin has no peripheral\n");
return;
}
// Get the peripheral name (UART_1, UART_2, ...) from the pin and assign it to the object
obj->uart = pinmap_merge_peripheral(uart_tx, uart_rx);
if(obj->uart == NP) {
printf("ERROR: UART pins mismatch\n");
return;
}
// Enable USART clock
if(obj->uart == USART1) {
__HAL_RCC_USART1_FORCE_RESET();
__HAL_RCC_USART1_RELEASE_RESET();
__HAL_RCC_USART1_CLK_ENABLE();
obj->index = 0;
obj->irq = USART1_IRQn;
} else if(obj->uart == USART2) {
__HAL_RCC_USART2_FORCE_RESET();
__HAL_RCC_USART2_RELEASE_RESET();
__HAL_RCC_USART2_CLK_ENABLE();
obj->index = 1;
obj->irq = USART2_IRQn;
}
#if defined(USART3_BASE)
else if(obj->uart == USART3) {
__HAL_RCC_USART3_FORCE_RESET();
__HAL_RCC_USART3_RELEASE_RESET();
__HAL_RCC_USART3_CLK_ENABLE();
obj->index = 2;
obj->irq = USART3_IRQn;
}
#endif
#if defined(UART4_BASE)
else if(obj->uart == UART4) {
__HAL_RCC_UART4_FORCE_RESET();
__HAL_RCC_UART4_RELEASE_RESET();
__HAL_RCC_UART4_CLK_ENABLE();
obj->index = 3;
obj->irq = UART4_IRQn;
}
#elif defined(USART4_BASE)
else if(obj->uart == USART4) {
__HAL_RCC_USART4_FORCE_RESET();
__HAL_RCC_USART4_RELEASE_RESET();
__HAL_RCC_USART4_CLK_ENABLE();
obj->index = 3;
obj->irq = USART4_IRQn;
}
#endif
#if defined(UART5_BASE)
else if(obj->uart == UART5) {
__HAL_RCC_UART5_FORCE_RESET();
__HAL_RCC_UART5_RELEASE_RESET();
__HAL_RCC_UART5_CLK_ENABLE();
obj->index = 4;
obj->irq = UART5_IRQn;
}
#elif defined(USART5_BASE)
else if(obj->uart == USART5) {
__HAL_RCC_USART5_FORCE_RESET();
__HAL_RCC_USART5_RELEASE_RESET();
__HAL_RCC_USART5_CLK_ENABLE();
obj->index = 4;
obj->irq = USART5_IRQn;
}
#endif
#if defined(USART6_BASE)
else if(obj->uart == USART6) {
__HAL_RCC_USART6_FORCE_RESET();
__HAL_RCC_USART6_RELEASE_RESET();
__HAL_RCC_USART6_CLK_ENABLE();
obj->index = 5;
obj->irq = USART6_IRQn;
}
#endif
#if defined(UART7_BASE)
else if(obj->uart == UART7) {
__HAL_RCC_UART7_FORCE_RESET();
__HAL_RCC_UART7_RELEASE_RESET();
__HAL_RCC_UART7_CLK_ENABLE();
obj->index = 6;
obj->irq = UART7_IRQn;
}
#elif defined(USART7_BASE)
else if(obj->uart == USART7) {
__HAL_RCC_USART7_FORCE_RESET();
__HAL_RCC_USART7_RELEASE_RESET();
__HAL_RCC_USART7_CLK_ENABLE();
obj->index = 6;
obj->irq = USART7_IRQn;
}
#endif
#if defined(UART8_BASE)
else if(obj->uart == UART8) {
__HAL_RCC_UART8_FORCE_RESET();
__HAL_RCC_UART8_RELEASE_RESET();
__HAL_RCC_UART8_CLK_ENABLE();
obj->index = 7;
obj->irq = UART8_IRQn;
}
#elif defined(USART8_BASE)
else if(obj->uart == USART8) {
__HAL_RCC_USART8_FORCE_RESET();
__HAL_RCC_USART8_RELEASE_RESET();
__HAL_RCC_USART8_CLK_ENABLE();
obj->index = 7;
obj->irq = USART8_IRQn;
}
#endif
#if defined(UART9_BASE)
else if(obj->uart == UART9) {
__HAL_RCC_UART9_FORCE_RESET();
__HAL_RCC_UART9_RELEASE_RESET();
__HAL_RCC_UART9_CLK_ENABLE();
obj->index = 8;
obj->irq = UART9_IRQn;
}
#endif
#if defined(UART10_BASE)
else if(obj->uart == UART10) {
__HAL_RCC_UART10_FORCE_RESET();
__HAL_RCC_UART10_RELEASE_RESET();
__HAL_RCC_UART10_CLK_ENABLE();
obj->index = 9;
obj->irq = UART10_IRQn;
}
#endif
//Configure GPIOs
//RX
port = set_GPIO_Port_Clock(STM_PORT(obj->pin_rx));
GPIO_InitStruct.Pin = STM_GPIO_PIN(obj->pin_rx);
GPIO_InitStruct.Mode = STM_PIN_MODE(pinmap_function(obj->pin_rx,PinMap_UART_RX));
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Pull = STM_PIN_PUPD(pinmap_function(obj->pin_rx,PinMap_UART_RX));
#ifdef STM32F1xx
pin_SetF1AFPin(STM_PIN_AFNUM(pinmap_function(obj->pin_rx,PinMap_UART_RX)));
#else
GPIO_InitStruct.Alternate = STM_PIN_AFNUM(pinmap_function(obj->pin_rx,PinMap_UART_RX));
#endif /* STM32F1xx */
HAL_GPIO_Init(port, &GPIO_InitStruct);
//TX
port = set_GPIO_Port_Clock(STM_PORT(obj->pin_tx));
GPIO_InitStruct.Pin = STM_GPIO_PIN(obj->pin_tx);
GPIO_InitStruct.Mode = STM_PIN_MODE(pinmap_function(obj->pin_tx,PinMap_UART_TX));
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Pull = STM_PIN_PUPD(pinmap_function(obj->pin_tx,PinMap_UART_TX));
#ifdef STM32F1xx
pin_SetF1AFPin(STM_PIN_AFNUM(pinmap_function(obj->pin_tx,PinMap_UART_TX)));
#else
GPIO_InitStruct.Alternate = STM_PIN_AFNUM(pinmap_function(obj->pin_tx,PinMap_UART_TX));
#endif /* STM32F1xx */
HAL_GPIO_Init(port, &GPIO_InitStruct);
//Configure uart
uart_handlers[obj->index] = huart;
huart->Instance = (USART_TypeDef *)(obj->uart);
huart->Init.BaudRate = obj->baudrate;
huart->Init.WordLength = obj->databits;
huart->Init.StopBits = obj->stopbits;
huart->Init.Parity = obj->parity;
huart->Init.Mode = UART_MODE_TX_RX;
huart->Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart->Init.OverSampling = UART_OVERSAMPLING_16;
// huart->Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
if(HAL_UART_Init(huart) != HAL_OK) {
return;
}
}
/**
* @brief Function called to deinitialize the uart interface
* @param obj : pointer to serial_t structure
* @retval None
*/
void uart_deinit(serial_t *obj)
{
// Reset UART and disable clock
switch (obj->index) {
case 0:
__HAL_RCC_USART1_FORCE_RESET();
__HAL_RCC_USART1_RELEASE_RESET();
__HAL_RCC_USART1_CLK_DISABLE();
break;
case 1:
__HAL_RCC_USART2_FORCE_RESET();
__HAL_RCC_USART2_RELEASE_RESET();
__HAL_RCC_USART2_CLK_DISABLE();
break;
#if defined(USART3_BASE)
case 2:
__HAL_RCC_USART3_FORCE_RESET();
__HAL_RCC_USART3_RELEASE_RESET();
__HAL_RCC_USART3_CLK_DISABLE();
break;
#endif
#if defined(UART4_BASE)
case 3:
__HAL_RCC_UART4_FORCE_RESET();
__HAL_RCC_UART4_RELEASE_RESET();
__HAL_RCC_UART4_CLK_DISABLE();
break;
#elif defined(USART4_BASE)
case 3:
__HAL_RCC_USART4_FORCE_RESET();
__HAL_RCC_USART4_RELEASE_RESET();
__HAL_RCC_USART4_CLK_DISABLE();
break;
#endif
#if defined(UART5_BASE)
case 4:
__HAL_RCC_UART5_FORCE_RESET();
__HAL_RCC_UART5_RELEASE_RESET();
__HAL_RCC_UART5_CLK_DISABLE();
break;
#elif defined(USART5_BASE)
case 4:
__HAL_RCC_USART5_FORCE_RESET();
__HAL_RCC_USART5_RELEASE_RESET();
__HAL_RCC_USART5_CLK_DISABLE();
break;
#endif
#if defined(USART6_BASE)
case 5:
__HAL_RCC_USART6_FORCE_RESET();
__HAL_RCC_USART6_RELEASE_RESET();
__HAL_RCC_USART6_CLK_DISABLE();
break;
#endif
#if defined(UART7_BASE)
case 6:
__HAL_RCC_UART7_FORCE_RESET();
__HAL_RCC_UART7_RELEASE_RESET();
__HAL_RCC_UART7_CLK_DISABLE();
break;
#elif defined(USART7_BASE)
case 6:
__HAL_RCC_USART7_FORCE_RESET();
__HAL_RCC_USART7_RELEASE_RESET();
__HAL_RCC_USART7_CLK_DISABLE();
break;
#endif
#if defined(UART8_BASE)
case 7:
__HAL_RCC_UART8_FORCE_RESET();
__HAL_RCC_UART8_RELEASE_RESET();
__HAL_RCC_UART8_CLK_DISABLE();
break;
#elif defined(USART8_BASE)
case 7:
__HAL_RCC_USART8_FORCE_RESET();
__HAL_RCC_USART8_RELEASE_RESET();
__HAL_RCC_USART8_CLK_DISABLE();
break;
#endif
#if defined(UART9_BASE)
case 8:
__HAL_RCC_UART9_FORCE_RESET();
__HAL_RCC_UART9_RELEASE_RESET();
__HAL_RCC_UART9_CLK_DISABLE();
break;
#endif
#if defined(UART10_BASE)
case 9:
__HAL_RCC_UART10_FORCE_RESET();
__HAL_RCC_UART10_RELEASE_RESET();
__HAL_RCC_UART10_CLK_DISABLE();
break;
#endif
}
HAL_UART_DeInit(uart_handlers[obj->index]);
}
/**
* @brief write the data on the uart
* @param obj : pointer to serial_t structure
* @param data : byte to write
* @param size : number of data to write
* @retval The number of bytes written
*/
size_t uart_write(serial_t *obj, uint8_t data, uint16_t size)
{
if(HAL_UART_Transmit(uart_handlers[obj->index], &data, size, TX_TIMEOUT) == HAL_OK) {
return size;
} else {
return 0;
}
}
/**
* @brief write the data on the uart: used by printf for debug only (syscalls)
* @param obj : pointer to serial_t structure
* @param data : bytes to write
* @param size : number of data to write
* @retval The number of bytes written
*/
size_t uart_debug_write(uint8_t *data, uint32_t size)
{
uint8_t index = 0;
uint32_t tickstart = HAL_GetTick();
for(index = 0; index < UART_NUM; index++) {
if(uart_handlers[index] != NULL) {
if(DEBUG_UART == uart_handlers[index]->Instance) {
break;
}
}
}
if(index >= UART_NUM) {
return 0;
}
while(HAL_UART_Transmit(uart_handlers[index], data, size, TX_TIMEOUT) != HAL_OK) {
if((HAL_GetTick() - tickstart) >= TX_TIMEOUT) {
return 0;
}
}
return size;
}
/**
* Attempts to determine if the serial peripheral is already in use for RX
*
* @param obj The serial object
* @return Non-zero if the RX transaction is ongoing, 0 otherwise
*/
uint8_t serial_rx_active(serial_t *obj)
{
return ((obj == NULL) ? 1 : (HAL_UART_GetState(uart_handlers[obj->index]) == HAL_UART_STATE_BUSY_RX));
}
/**
* Attempts to determine if the serial peripheral is already in use for TX
*
* @param obj The serial object
* @return Non-zero if the TX transaction is ongoing, 0 otherwise
*/
uint8_t serial_tx_active(serial_t *obj)
{
return ((obj == NULL) ? 1 : (HAL_UART_GetState(uart_handlers[obj->index]) == HAL_UART_STATE_BUSY_TX));
}
/**
* @brief Read receive byte from uart
* @param obj : pointer to serial_t structure
* @retval last character received
*/
int uart_getc(serial_t *obj)
{
if(obj == NULL) {
return -1;
}
if (serial_rx_active(obj)) {
return -1; // transaction ongoing
}
// Restart RX irq
UART_HandleTypeDef *huart = uart_handlers[obj->index];
HAL_UART_Receive_IT(huart, rx_buffer, 1);
return rx_buffer[0];
}
/**
* Begin asynchronous RX transfer (enable interrupt for data collecting)
*
* @param obj : pointer to serial_t structure
* @param callback : function call at the end of reception
* @retval none
*/
void uart_attach_rx_callback(serial_t *obj, void (*callback)(serial_t*))
{
if(obj == NULL) {
return;
}
// Exit if a reception is already on-going
if (serial_rx_active(obj)) {
return;
}
rx_callback[obj->index] = callback;
rx_callback_obj[obj->index] = obj;
HAL_NVIC_SetPriority(obj->irq, 0, 1);
HAL_NVIC_EnableIRQ(obj->irq);
if(HAL_UART_Receive_IT(uart_handlers[obj->index], rx_buffer, 1) != HAL_OK) {
return;
}
}
/**
* Begin asynchronous TX transfer.
*
* @param obj : pointer to serial_t structure
* @param callback : function call at the end of transmission
* @retval none
*/
void uart_attach_tx_callback(serial_t *obj, int (*callback)(serial_t*))
{
if(obj == NULL) {
return;
}
tx_callback[obj->index] = callback;
tx_callback_obj[obj->index] = obj;
// Enable interrupt
HAL_NVIC_SetPriority(obj->irq, 0, 2);
HAL_NVIC_EnableIRQ(obj->irq);
// the following function will enable UART_IT_TXE and error interrupts
if (HAL_UART_Transmit_IT(uart_handlers[obj->index], &obj->tx_buff[obj->tx_tail], 1) != HAL_OK) {
return;
}
}
/**
* @brief Return index of the serial handler
* @param UartHandle pointer on the uart reference
* @retval index
*/
uint8_t uart_index(UART_HandleTypeDef *huart)
{
uint8_t i = 0;
if(huart == NULL) {
return UART_NUM;
}
for(i = 0; i < UART_NUM; i++) {
if(huart == uart_handlers[i]) {
break;
}
}
return i;
}
/**
* @brief Rx Transfer completed callback
* @param UartHandle pointer on the uart reference
* @retval None
*/
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
uint8_t index = uart_index(huart);
if(index < UART_NUM) {
rx_callback[index](rx_callback_obj[index]);
}
}
/**
* @brief Tx Transfer completed callback
* @param UartHandle pointer on the uart reference
* @retval None
*/
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart) {
uint8_t index = uart_index(huart);
serial_t *obj = tx_callback_obj[index];
if(index < UART_NUM) {
if(tx_callback[index](obj) != -1) {
if (HAL_UART_Transmit_IT(uart_handlers[obj->index], &obj->tx_buff[obj->tx_tail], 1) != HAL_OK) {
return;
}
}
}
}
/**
* @brief error callback from UART
* @param UartHandle pointer on the uart reference
* @retval None
*/
void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart)
{
volatile uint32_t tmpval;
#if defined(STM32F1xx) || defined(STM32F2xx) || defined(STM32F4xx) || defined(STM32L1xx)
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_PE) != RESET) {
tmpval = huart->Instance->DR; // Clear PE flag
} else if (__HAL_UART_GET_FLAG(huart, UART_FLAG_FE) != RESET) {
tmpval = huart->Instance->DR; // Clear FE flag
} else if (__HAL_UART_GET_FLAG(huart, UART_FLAG_NE) != RESET) {
tmpval = huart->Instance->DR; // Clear NE flag
} else if (__HAL_UART_GET_FLAG(huart, UART_FLAG_ORE) != RESET) {
tmpval = huart->Instance->DR; // Clear ORE flag
}
#else
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_PE) != RESET) {
tmpval = huart->Instance->RDR; // Clear PE flag
} else if (__HAL_UART_GET_FLAG(huart, UART_FLAG_FE) != RESET) {
tmpval = huart->Instance->RDR; // Clear FE flag
} else if (__HAL_UART_GET_FLAG(huart, UART_FLAG_NE) != RESET) {
tmpval = huart->Instance->RDR; // Clear NE flag
} else if (__HAL_UART_GET_FLAG(huart, UART_FLAG_ORE) != RESET) {
tmpval = huart->Instance->RDR; // Clear ORE flag
}
#endif
UNUSED(tmpval);
}
/**
* @brief USART 1 IRQ handler
* @param None
* @retval None
*/
void USART1_IRQHandler(void)
{
HAL_NVIC_ClearPendingIRQ(USART1_IRQn);
HAL_UART_IRQHandler(uart_handlers[0]);
}
/**
* @brief USART 2 IRQ handler
* @param None
* @retval None
*/
void USART2_IRQHandler(void)
{
HAL_NVIC_ClearPendingIRQ(USART2_IRQn);
HAL_UART_IRQHandler(uart_handlers[1]);
}
/**
* @brief USART 3 IRQ handler
* @param None
* @retval None
*/
#if defined(USART3_BASE)
void USART3_IRQHandler(void)
{
HAL_NVIC_ClearPendingIRQ(USART3_IRQn);
#if defined(STM32F091xC) || defined (STM32F098xx)
if (__HAL_GET_PENDING_IT(HAL_ITLINE_USART3)!= RESET)
{
HAL_UART_IRQHandler(uart_handlers[2]);
}
if (__HAL_GET_PENDING_IT(HAL_ITLINE_USART4)!= RESET)
{
HAL_UART_IRQHandler(uart_handlers[3]);
}
if (__HAL_GET_PENDING_IT(HAL_ITLINE_USART5)!= RESET)
{
HAL_UART_IRQHandler(uart_handlers[4]);
}
if (__HAL_GET_PENDING_IT(HAL_ITLINE_USART6)!= RESET)
{
HAL_UART_IRQHandler(uart_handlers[5]);
}
if (__HAL_GET_PENDING_IT(HAL_ITLINE_USART7)!= RESET)
{
HAL_UART_IRQHandler(uart_handlers[6]);
}
if (__HAL_GET_PENDING_IT(HAL_ITLINE_USART8)!= RESET)
{
HAL_UART_IRQHandler(uart_handlers[7]);
}
#else
if(uart_handlers[2] != NULL) {
HAL_UART_IRQHandler(uart_handlers[2]);
}
#if defined(STM32F0xx)
// USART3_4_IRQn
if(uart_handlers[3] != NULL) {
HAL_UART_IRQHandler(uart_handlers[3]);
}
#if defined(STM32F030xC)
if(uart_handlers[4] != NULL) {
HAL_UART_IRQHandler(uart_handlers[4]);
}
if(uart_handlers[5] != NULL) {
HAL_UART_IRQHandler(uart_handlers[5]);
}
#endif // STM32F030xC
#endif // STM32F0xx
#endif // STM32F091xC || STM32F098xx
}
#endif
/**
* @brief UART 4 IRQ handler
* @param None
* @retval None
*/
#if defined(UART4_BASE)
void UART4_IRQHandler(void)
{
HAL_NVIC_ClearPendingIRQ(UART4_IRQn);
HAL_UART_IRQHandler(uart_handlers[3]);
}
#endif
/**
* @brief USART 4/5 IRQ handler
* @param None
* @retval None
*/
#if defined(STM32L0xx)
#if defined(USART4_BASE) || defined(USART5_BASE)
void USART4_5_IRQHandler(void)
{
HAL_NVIC_ClearPendingIRQ(USART4_IRQn);
if(uart_handlers[3] != NULL) {
HAL_UART_IRQHandler(uart_handlers[3]);
}
if(uart_handlers[4] != NULL) {
HAL_UART_IRQHandler(uart_handlers[4]);
}
}
#endif
#endif
/**
* @brief USART 5 IRQ handler
* @param None
* @retval None
*/
#if defined(UART5_BASE)
void UART5_IRQHandler(void)
{
HAL_NVIC_ClearPendingIRQ(UART5_IRQn);
HAL_UART_IRQHandler(uart_handlers[4]);
}
#endif
/**
* @brief USART 6 IRQ handler
* @param None
* @retval None
*/
#if defined(USART6_BASE) && !defined(STM32F0xx)
void USART6_IRQHandler(void)
{
HAL_NVIC_ClearPendingIRQ(USART6_IRQn);
HAL_UART_IRQHandler(uart_handlers[5]);
}
#endif
/**
* @brief UART 7 IRQ handler
* @param None
* @retval None
*/
#if defined(UART7_BASE)
void UART7_IRQHandler(void)
{
HAL_NVIC_ClearPendingIRQ(UART7_IRQn);
HAL_UART_IRQHandler(uart_handlers[6]);
}
#endif
/**
* @brief UART 8 IRQ handler
* @param None
* @retval None
*/
#if defined(UART8_BASE)
void UART8_IRQHandler(void)
{
HAL_NVIC_ClearPendingIRQ(UART8_IRQn);
HAL_UART_IRQHandler(uart_handlers[7]);
}
#endif
/**
* @brief UART 9 IRQ handler
* @param None
* @retval None
*/
#if defined(UART9_BASE)
void UART9_IRQHandler(void)
{
HAL_NVIC_ClearPendingIRQ(UART9_IRQn);
HAL_UART_IRQHandler(uart_handlers[8]);
}
#endif
/**
* @brief UART 10 IRQ handler
* @param None
* @retval None
*/
#if defined(UART10_BASE)
void UART10_IRQHandler(void)
{
HAL_NVIC_ClearPendingIRQ(UART10_IRQn);
HAL_UART_IRQHandler(uart_handlers[9]);
}
#endif
#ifdef __cplusplus
}
#endif
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/