@@ -81,9 +81,10 @@ static void serial_rx_enable_event(serial_t *obj, int event, uint8_t enable);
81
81
static int serial_is_rx_complete (serial_t * obj );
82
82
83
83
static void serial_check_dma_usage (DMAUsage * dma_usage , int * dma_ch );
84
- static int serial_is_irq_en (serial_t * obj , SerialIrq irq );
85
84
#endif
86
85
86
+ static int serial_is_irq_en (serial_t * obj , SerialIrq irq );
87
+
87
88
bool serial_can_deep_sleep (void );
88
89
89
90
static struct nu_uart_var uart0_var = {
@@ -459,15 +460,17 @@ static void uart_irq(serial_t *obj)
459
460
if (uart_base -> INTSTS & (UART_INTSTS_RDAINT_Msk | UART_INTSTS_RXTOINT_Msk )) {
460
461
// Simulate clear of the interrupt flag. Temporarily disable the interrupt here and to be recovered on next read.
461
462
UART_DISABLE_INT (uart_base , (UART_INTEN_RDAIEN_Msk | UART_INTEN_RXTOIEN_Msk ));
462
- if (obj -> serial .irq_handler ) {
463
+ if (obj -> serial .irq_handler && serial_is_irq_en (obj , RxIrq )) {
464
+ // Call irq_handler() only when RxIrq is enabled
463
465
((uart_irq_handler ) obj -> serial .irq_handler )(obj -> serial .irq_id , RxIrq );
464
466
}
465
467
}
466
468
467
469
if (uart_base -> INTSTS & UART_INTSTS_THREINT_Msk ) {
468
470
// Simulate clear of the interrupt flag. Temporarily disable the interrupt here and to be recovered on next write.
469
471
UART_DISABLE_INT (uart_base , UART_INTEN_THREIEN_Msk );
470
- if (obj -> serial .irq_handler ) {
472
+ if (obj -> serial .irq_handler && serial_is_irq_en (obj , TxIrq )) {
473
+ // Call irq_handler() only when TxIrq is enabled
471
474
((uart_irq_handler ) obj -> serial .irq_handler )(obj -> serial .irq_id , TxIrq );
472
475
}
473
476
}
@@ -1094,6 +1097,8 @@ static void serial_check_dma_usage(DMAUsage *dma_usage, int *dma_ch)
1094
1097
}
1095
1098
}
1096
1099
1100
+ #endif // #if DEVICE_SERIAL_ASYNCH
1101
+
1097
1102
static int serial_is_irq_en (serial_t * obj , SerialIrq irq )
1098
1103
{
1099
1104
int inten_msk = 0 ;
@@ -1110,8 +1115,6 @@ static int serial_is_irq_en(serial_t *obj, SerialIrq irq)
1110
1115
return !! inten_msk ;
1111
1116
}
1112
1117
1113
- #endif // #if DEVICE_SERIAL_ASYNCH
1114
-
1115
1118
bool serial_can_deep_sleep (void )
1116
1119
{
1117
1120
bool sleep_allowed = 1 ;
0 commit comments