Skip to content
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

Add NoDma I2C master async bus implementation #333

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tullom
Copy link
Contributor

@tullom tullom commented Feb 28, 2025

Closes #327

Some kicking off questions:

  • The reason I need to make a new_async_nodma() fn instead of hijacking new_async() is because new_async() requires a dma_ch object that impls Peripheral and impls an interrupt with MasterDma. I tried creating structs to impl all that but I hit a wall.
  • I added documentation saying NOT to use this and to prefer new_async(), except in the cases of the Flexcomm not having DMA support. Is this enough or do you think this should be gated behind some sort of feature flag to reduce the possibility of misuse?

EDIT:
I was able to create a NoDma structure. I had to minimally modify the DMA api, specifically reserve_channel() now returns an option that will return None if NoDma is used. Needed to slightly modify the UART driver and hashcrypt driver as well to return errors if NoDma is used since it doesn't make sense if NoDma is used.

@tullom tullom added the enhancement New feature or request label Feb 28, 2025
@tullom tullom self-assigned this Feb 28, 2025
@tullom tullom requested a review from sukomath February 28, 2025 00:08
/// which can lead to bus timeouts if a byte is not handled fast enough.
///
/// use flexcomm fc with Pins scl, sda as an I2C Master bus, configuring to speed and pull
pub fn new_async_nodma<T: Instance>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of implementing this for all the instances, can we also only implement this for the I2C instance corresponding to FC15?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? User can decide to not use DMA on any instance, right? Should we make the choice for them? I'm not convinced, IMO.

In any case, we shouldn't add a new method here. Just patch new_async() to take an Option<impl Peripheral...> or something like that. Could you give that a go?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So my issue with patching new_async() is that that would be a breaking change to our I2C driver. If we are ok with that, I can do it (and would prefer it if we aren't going the FC15 only route)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI @jerrysxie @felipebalbi
I was able to create a NoDma structure. I had to minimally modify the DMA api, specifically reserve_channel() now returns an option that will return None if NoDma is used. Needed to slightly modify the UART driver and hashcrypt driver as well to return errors if NoDma is used since it doesn't make sense if NoDma is used.

Tested all touched drivers via examples on hardware and it works flawlessly.

/// which can lead to bus timeouts if a byte is not handled fast enough.
///
/// use flexcomm fc with Pins scl, sda as an I2C Master bus, configuring to speed and pull
pub fn new_async_nodma<T: Instance>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? User can decide to not use DMA on any instance, right? Should we make the choice for them? I'm not convinced, IMO.

In any case, we shouldn't add a new method here. Just patch new_async() to take an Option<impl Peripheral...> or something like that. Could you give that a go?

@tullom tullom force-pushed the i2c-master-async-nodma branch 4 times, most recently from 65a1e3d to 76988a3 Compare March 5, 2025 19:17
@tullom tullom force-pushed the i2c-master-async-nodma branch from 76988a3 to a9ffcd8 Compare March 5, 2025 22:59
@tullom
Copy link
Contributor Author

tullom commented Mar 6, 2025

FYI @jerrysxie @felipebalbi
I was able to create a NoDma structure. I had to minimally modify the DMA api, specifically reserve_channel() now returns an option that will return None if NoDma is used. Needed to slightly modify the UART driver and hashcrypt driver as well (is surface using these APIs? I can go and send out PRs to fix if needed) to return errors if NoDma is used since it doesn't make sense if NoDma is used.

Tested all touched drivers via examples on hardware and it works flawlessly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement NoDma for I2C Master
4 participants