@@ -86,9 +86,10 @@ static void serial_rx_enable_event(serial_t *obj, int event, uint8_t enable);
86
86
static int serial_is_rx_complete (serial_t * obj );
87
87
88
88
static void serial_check_dma_usage (DMAUsage * dma_usage , int * dma_ch );
89
- static int serial_is_irq_en (serial_t * obj , SerialIrq irq );
90
89
#endif
91
90
91
+ static int serial_is_irq_en (serial_t * obj , SerialIrq irq );
92
+
92
93
bool serial_can_deep_sleep (void );
93
94
94
95
static struct nu_uart_var uart0_var = {
@@ -519,15 +520,17 @@ static void uart_irq(serial_t *obj)
519
520
if (uart_base -> INTSTS & (UART_INTSTS_RDAINT_Msk | UART_INTSTS_RXTOINT_Msk )) {
520
521
// Simulate clear of the interrupt flag. Temporarily disable the interrupt here and to be recovered on next read.
521
522
UART_DISABLE_INT (uart_base , (UART_INTEN_RDAIEN_Msk | UART_INTEN_RXTOIEN_Msk ));
522
- if (obj -> serial .irq_handler ) {
523
+ if (obj -> serial .irq_handler && serial_is_irq_en (obj , RxIrq )) {
524
+ // Call irq_handler() only when RxIrq is enabled
523
525
((uart_irq_handler ) obj -> serial .irq_handler )(obj -> serial .irq_id , RxIrq );
524
526
}
525
527
}
526
528
527
529
if (uart_base -> INTSTS & UART_INTSTS_THREINT_Msk ) {
528
530
// Simulate clear of the interrupt flag. Temporarily disable the interrupt here and to be recovered on next write.
529
531
UART_DISABLE_INT (uart_base , UART_INTEN_THREIEN_Msk );
530
- if (obj -> serial .irq_handler ) {
532
+ if (obj -> serial .irq_handler && serial_is_irq_en (obj , TxIrq )) {
533
+ // Call irq_handler() only when TxIrq is enabled
531
534
((uart_irq_handler ) obj -> serial .irq_handler )(obj -> serial .irq_id , TxIrq );
532
535
}
533
536
}
@@ -1167,6 +1170,8 @@ static void serial_check_dma_usage(DMAUsage *dma_usage, int *dma_ch)
1167
1170
}
1168
1171
}
1169
1172
1173
+ #endif // #if DEVICE_SERIAL_ASYNCH
1174
+
1170
1175
static int serial_is_irq_en (serial_t * obj , SerialIrq irq )
1171
1176
{
1172
1177
int inten_msk = 0 ;
@@ -1183,8 +1188,6 @@ static int serial_is_irq_en(serial_t *obj, SerialIrq irq)
1183
1188
return !! inten_msk ;
1184
1189
}
1185
1190
1186
- #endif // #if DEVICE_SERIAL_ASYNCH
1187
-
1188
1191
bool serial_can_deep_sleep (void )
1189
1192
{
1190
1193
bool sleep_allowed = 1 ;
0 commit comments