Skip to content

Make the nrf Twim RAM buffer a instance variable instead of stack allocated #4113

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

Merged
merged 2 commits into from
Apr 30, 2025

Conversation

alexmoon
Copy link
Contributor

This prevents the ram buffer from being duplicated in every future that calls a Twim transaction method. In my firmware this ended up saving about 4kb of ram.

I can implement this for the other peripherals that implement copying into ram buffers if this looks good to you.

Copy link
Member

@lulf lulf left a comment

Choose a reason for hiding this comment

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

Looks good to me. It's a bit clunky to size this buffer correctly perhaps, is there a way to simplify that?

@alexmoon
Copy link
Contributor Author

It just needs to be large enough for the largest write operation your firmware sends from flash. I don't think there's any way for embassy-nrf to help with that. We could add a usize to the RAMBufferTooSmall error variant so the error message could say what size buffer was needed? Though that would increase the size of the error enum.

@lulf
Copy link
Member

lulf commented Apr 28, 2025

It just needs to be large enough for the largest write operation your firmware sends from flash. I don't think there's any way for embassy-nrf to help with that. We could add a usize to the RAMBufferTooSmall error variant so the error message could say what size buffer was needed? Though that would increase the size of the error enum.

Yeah, I don't like that option either... But maybe at least some guidance in the rustdoc for the new() on the sizing of the buffer?

Copy link
Member

@lulf lulf left a comment

Choose a reason for hiding this comment

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

Thanks!

@lulf lulf added this pull request to the merge queue Apr 30, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 30, 2025
@lulf lulf added this pull request to the merge queue Apr 30, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 30, 2025
@lulf lulf merged commit 5f0196c into embassy-rs:main Apr 30, 2025
7 checks passed
@alexmoon alexmoon deleted the twim-ram-buffer branch April 30, 2025 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants