stm32/gpdma: ensure bndt in bytes doesn't overflow.

This commit is contained in:
Dario Nieuwenhuis 2024-09-23 00:32:17 +02:00
parent 9705f3332b
commit f2f96a731c

View File

@ -216,7 +216,10 @@ impl<'a> Transfer<'a> {
data_size: WordSize,
_options: TransferOptions,
) -> Self {
assert!(mem_len > 0 && mem_len <= 0xFFFF);
// BNDT is specified as bytes, not as number of transfers.
let Ok(bndt) = (mem_len * data_size.bytes()).try_into() else {
panic!("DMA transfers may not be larger than 65535 bytes.");
};
let info = channel.info();
let ch = info.dma.ch(info.num);
@ -226,9 +229,6 @@ impl<'a> Transfer<'a> {
let this = Self { channel };
#[cfg(dmamux)]
super::dmamux::configure_dmamux(&*this.channel, request);
ch.cr().write(|w| w.set_reset(true));
ch.fcr().write(|w| w.0 = 0xFFFF_FFFF); // clear all irqs
ch.llr().write(|_| {}); // no linked list
@ -245,10 +245,7 @@ impl<'a> Transfer<'a> {
});
w.set_reqsel(request);
});
ch.br1().write(|w| {
// BNDT is specified as bytes, not as number of transfers.
w.set_bndt((mem_len * data_size.bytes()) as u16)
});
ch.br1().write(|w| w.set_bndt(bndt));
match dir {
Dir::MemoryToPeripheral => {