Only copy through RAM when needed

This commit is contained in:
alexmoon 2022-03-28 10:46:26 -04:00 committed by Dario Nieuwenhuis
parent d7b1f8ca57
commit 46bafecb2a

View File

@ -20,6 +20,7 @@ pub use embassy_usb;
use crate::interrupt::Interrupt; use crate::interrupt::Interrupt;
use crate::pac; use crate::pac;
use crate::util::slice_in_ram;
const NEW_AW: AtomicWaker = AtomicWaker::new(); const NEW_AW: AtomicWaker = AtomicWaker::new();
static BUS_WAKER: AtomicWaker = NEW_AW; static BUS_WAKER: AtomicWaker = NEW_AW;
@ -408,10 +409,15 @@ unsafe fn write_dma<T: Instance>(i: usize, buf: &[u8]) -> Result<(), WriteError>
return Err(WriteError::BufferOverflow); return Err(WriteError::BufferOverflow);
} }
// EasyDMA can't read FLASH, so we copy through RAM
let mut ram_buf: MaybeUninit<[u8; 64]> = MaybeUninit::uninit(); let mut ram_buf: MaybeUninit<[u8; 64]> = MaybeUninit::uninit();
let ptr = ram_buf.as_mut_ptr() as *mut u8; let ptr = if !slice_in_ram(buf) {
core::ptr::copy_nonoverlapping(buf.as_ptr(), ptr, buf.len()); // EasyDMA can't read FLASH, so we copy through RAM
let ptr = ram_buf.as_mut_ptr() as *mut u8;
core::ptr::copy_nonoverlapping(buf.as_ptr(), ptr, buf.len());
ptr
} else {
buf.as_ptr()
};
let epin = [ let epin = [
&regs.epin0, &regs.epin0,