Skip to content

Commit 6ffc96b

Browse files
committed
Use LDREXW + CLREX + STREXW read and clear CDC break value
Instead of NVIC_DisableIRQ + NVIC_EnableIRQ, as it’s a bit awkward to check if a particular NVIC IRQ is enabled on ARM. This is similar approach to Serial_::accept.
1 parent 2c1462d commit 6ffc96b

File tree

1 file changed

+12
-11
lines changed
  • hardware/arduino/sam/cores/arduino/USB

1 file changed

+12
-11
lines changed

hardware/arduino/sam/cores/arduino/USB/CDC.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -309,17 +309,18 @@ Serial_::operator bool()
309309
}
310310

311311
int32_t Serial_::readBreak() {
312-
// disable the USB OTG interrupt,
313-
// to avoid clearing a breakValue that might occur
314-
// while reading the current break value
315-
NVIC_DisableIRQ((IRQn_Type) ID_UOTGHS);
316-
317-
int32_t ret = breakValue;
318-
319-
breakValue = -1;
320-
321-
// re-eable the USB OTG interupt
322-
NVIC_EnableIRQ((IRQn_Type) ID_UOTGHS);
312+
// read the breakValue, using exclusive read
313+
int32_t ret = __LDREXW((volatile uint32_t*)&breakValue);
314+
315+
if (ret == -1) {
316+
// no new break value, clear exclusive access record
317+
__CLREX();
318+
} else {
319+
// only set it to -1 (no break),
320+
// if a new value has not been written in the ISR,
321+
// using exclusive write
322+
__STREXW(-1, (volatile uint32_t*)&breakValue);
323+
}
323324

324325
return ret;
325326
}

0 commit comments

Comments
 (0)