Merge pull request #2823 from jamesmunns/james/usb-otg-errata
Add critical sections to avoid USB OTG Errata
This commit is contained in:
commit
ca139b9177
1 changed files with 54 additions and 44 deletions
|
@ -672,6 +672,10 @@ impl<'d, T: Instance> Bus<'d, T> {
|
||||||
|
|
||||||
let r = T::regs();
|
let r = T::regs();
|
||||||
|
|
||||||
|
// ERRATA NOTE: Don't interrupt FIFOs being written to. The interrupt
|
||||||
|
// handler COULD interrupt us here and do FIFO operations, so ensure
|
||||||
|
// the interrupt does not occur.
|
||||||
|
critical_section::with(|_| {
|
||||||
// Configure RX fifo size. All endpoints share the same FIFO area.
|
// Configure RX fifo size. All endpoints share the same FIFO area.
|
||||||
let rx_fifo_size_words = RX_FIFO_EXTRA_SIZE_WORDS + ep_fifo_size(&self.ep_out);
|
let rx_fifo_size_words = RX_FIFO_EXTRA_SIZE_WORDS + ep_fifo_size(&self.ep_out);
|
||||||
trace!("configuring rx fifo size={}", rx_fifo_size_words);
|
trace!("configuring rx fifo size={}", rx_fifo_size_words);
|
||||||
|
@ -711,6 +715,8 @@ impl<'d, T: Instance> Bus<'d, T> {
|
||||||
w.set_txfflsh(true);
|
w.set_txfflsh(true);
|
||||||
w.set_txfnum(0x10);
|
w.set_txfnum(0x10);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let x = r.grstctl().read();
|
let x = r.grstctl().read();
|
||||||
if !x.rxfflsh() && !x.txfflsh() {
|
if !x.rxfflsh() && !x.txfflsh() {
|
||||||
|
@ -1208,6 +1214,11 @@ impl<'d, T: Instance> embassy_usb_driver::EndpointIn for Endpoint<'d, T, In> {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ERRATA: Transmit data FIFO is corrupted when a write sequence to the FIFO is interrupted with
|
||||||
|
// accesses to certain OTG_FS registers.
|
||||||
|
//
|
||||||
|
// Prevent the interrupt (which might poke FIFOs) from executing while copying data to FIFOs.
|
||||||
|
critical_section::with(|_| {
|
||||||
// Setup transfer size
|
// Setup transfer size
|
||||||
r.dieptsiz(index).write(|w| {
|
r.dieptsiz(index).write(|w| {
|
||||||
w.set_mcnt(1);
|
w.set_mcnt(1);
|
||||||
|
@ -1215,13 +1226,11 @@ impl<'d, T: Instance> embassy_usb_driver::EndpointIn for Endpoint<'d, T, In> {
|
||||||
w.set_xfrsiz(buf.len() as _);
|
w.set_xfrsiz(buf.len() as _);
|
||||||
});
|
});
|
||||||
|
|
||||||
critical_section::with(|_| {
|
|
||||||
// Enable endpoint
|
// Enable endpoint
|
||||||
r.diepctl(index).modify(|w| {
|
r.diepctl(index).modify(|w| {
|
||||||
w.set_cnak(true);
|
w.set_cnak(true);
|
||||||
w.set_epena(true);
|
w.set_epena(true);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
// Write data to FIFO
|
// Write data to FIFO
|
||||||
for chunk in buf.chunks(4) {
|
for chunk in buf.chunks(4) {
|
||||||
|
@ -1229,6 +1238,7 @@ impl<'d, T: Instance> embassy_usb_driver::EndpointIn for Endpoint<'d, T, In> {
|
||||||
tmp[0..chunk.len()].copy_from_slice(chunk);
|
tmp[0..chunk.len()].copy_from_slice(chunk);
|
||||||
r.fifo(index).write_value(regs::Fifo(u32::from_ne_bytes(tmp)));
|
r.fifo(index).write_value(regs::Fifo(u32::from_ne_bytes(tmp)));
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
trace!("write done ep={:?}", self.info.addr);
|
trace!("write done ep={:?}", self.info.addr);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue