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

stm32: impl uart write_all without panic #2665

Closed
wants to merge 1 commit into from

Conversation

andresv
Copy link
Contributor

@andresv andresv commented Mar 6, 2024

Default write_all implementation uses panic: https://github.com/rust-embedded/embedded-hal/blob/master/embedded-io-async/src/lib.rs#L138 and https://github.com/rust-embedded/embedded-hal/blob/master/embedded-io/src/lib.rs#L397.

This version produced 456 bytes smaller binary in my application where embedded-io-async::write_all was used.

Default write_all implementation uses panic: https://github.com/rust-embedded/embedded-hal/blob/master/embedded-io-async/src/lib.rs#L138 and https://github.com/rust-embedded/embedded-hal/blob/master/embedded-io/src/lib.rs#L397
This version produced 456 bytes smaller binary in my application where embedded-io-async::write_all was used.
@Dirbaio
Copy link
Member

Dirbaio commented Mar 6, 2024

write_all calls into uart::write which we know never returns Ok(0) because it's our own code. Therefore it returning Ok(0) is truly a "should never happen" scenario. If it happens it is a bug. It does not make sense to return that to the user, there is nothing they can do about it, there's nothing their code can do to handle it. The only solution is changing the embassy-stm32 code to fix it.

The appropriate way to handle these "should never happen" bugs is a panic.

If the motivation of this change is reducing code size because of the panic bloat, the right fix is enabling panic_immediate_abort. See the FAQ. It completely removes the panic bloat. We shouldn't do code changes that wouldn't stand on their own just to reduce the amount of panics.

@andresv andresv closed this Mar 7, 2024
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.

None yet

2 participants