-
Notifications
You must be signed in to change notification settings - Fork 777
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/usart: Changing baud rate #3512
base: main
Are you sure you want to change the base?
stm32/usart: Changing baud rate #3512
Conversation
embassy-stm32/src/usart/mod.rs
Outdated
Ok(()) | ||
} | ||
|
||
fn set_usart_baudrate(info: &Info, kernel_clock: Hertz, baudrate: u32) -> Result<(), ConfigError> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you not duplicate this chunk of code? for example making configure()
call here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure I can, but my only concern is that calling configure
would require the developer to pass the Config struct again to avoid overwriting any previous configuration made on Usart instance construction when perhaps all it wants is just to change the baudrate
all this since Config is not copied in Usart instance to reuse its values.
I noticed I can reduce code duplication by moving static DIVS
to the outer scope, and wrap Usart kind
matching and brr
search in two separate functions to be used by both configure
and set_usart_baudrate
if you think this would be better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
configure
does more things, so I meant make configure()
call set_usart_baudrate()
then do the other stuff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, sorry I misunderstood you. But yeah that makes total sense. I just pushed changes addressing this. Calling find_and_set_brr
in both configure
and set_baud_rate
reducing code duplication. Please take a look and let me know what you think.
23b929d
to
8e570da
Compare
8e570da
to
3c1c1d6
Compare
Where does this stop if we accept this change, will there be an set/get for every item in the config? On top of that, you then have to forward many of those methods to the sub structs Imo adding multiple ways to do things can get a bit messy. I saw in the original issue the concern was not overwriting the current config I think there are two better ways to solve this:
There is also a third:
Just some opinion of a user, feel free to ignore :) |
@@ -1010,6 +1015,11 @@ impl<'d, M: Mode> UartRx<'d, M> { | |||
} | |||
Ok(()) | |||
} | |||
|
|||
/// Set baudrate | |||
pub fn set_baudrate(&self, baudrate: u32) -> Result<(), ConfigError> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These impls should also be extended to Buffered*
and RingBuffered*
structs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback, just did that. Please take a look
This change is required to generate a DMX signal. Changing the baudrate using set_config is too slow, the pins go into floaing for ~100µs. |
As discussed in #1289 adding support to changing the baud rate for stm32 usart.