Skip to content

Commit 610a937

Browse files
sandeepmistrycmaglie
authored andcommitted
Only re-enable IRQ if PRIMASK was 0 before disabling IRQ
1 parent 261c375 commit 610a937

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

cores/arduino/USB/CDC.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,9 @@ void Serial_::accept(void)
166166
uint8_t buffer[CDC_SERIAL_BUFFER_SIZE];
167167
uint32_t len = usb.recv(CDC_ENDPOINT_OUT, &buffer, CDC_SERIAL_BUFFER_SIZE);
168168

169-
noInterrupts();
169+
uint8_t enableInterrupts = ((__get_PRIMASK() & 0x1) == 0);
170+
__disable_irq();
171+
170172
ring_buffer *ringBuffer = &cdc_rx_buffer;
171173
uint32_t i = ringBuffer->head;
172174

@@ -183,7 +185,9 @@ void Serial_::accept(void)
183185
ringBuffer->full = true;
184186
}
185187
ringBuffer->head = i;
186-
interrupts();
188+
if (enableInterrupts) {
189+
__enable_irq();
190+
}
187191
}
188192

189193
int Serial_::available(void)

0 commit comments

Comments
 (0)