-
Notifications
You must be signed in to change notification settings - Fork 173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error handling for DMA max transfer size set to 0 #201
Comments
I believe this should be fixed by #168? Could you take a look and confirm? |
Ah I understand, apologies for the noise. I think this could be a good candidate for |
Thank you. I like pub enum Dma {
Disabled,
Channel1(NonZeroUsize),
Channel2(NonZeroUsize),
Auto(NonZeroUsize),
} Then we change impl Dma {
pub const fn max_transfer_size(&self) -> usize {
let max_transfer_size: usize = match self {
Dma::Disabled => TRANS_LEN,
- Dma::Channel1(size) | Dma::Channel2(size) | Dma::Auto(size) => *size,
+ Dma::Channel1(size) | Dma::Channel2(size) | Dma::Auto(size) => (*size).get(),
};
if max_transfer_size % 4 != 0 {
panic!("The max transfer size must be a multiple of 4")
} else if max_transfer_size > 4096 {
4096
} else {
max_transfer_size
}
}
} Looks good? I will create a PR. |
Looks good! Please create the PR :) |
* Use `NonZeroUsize` to specify DMA transfer size * panic when size 0 is given * Update spi.rs
SpiDriver
with a DMA max transfer size of 0 leads to panic.The creation of the driver succeeds. But the panic occurs when the driver tries to process data in chunks by calling
chunks
orchunks_mut
.Setting the transfer size to 0 doesn't make sense. But mistakes happen. Wouldn't it be better if it panics earlier in max_tansfer_size with a message?
Maybe something like this?
Or assign a default value?
The text was updated successfully, but these errors were encountered: