-
Notifications
You must be signed in to change notification settings - Fork 928
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
Fix stm32 uart set_config #2105
Conversation
reconfigure::<T>(config) | ||
reconfigure::<T>(config)?; | ||
|
||
T::regs().cr1().modify(|w| { |
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 put this reg write in reconfigure
instead of pasting it 3 time?
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.
reconfigure
is universally used for all uart flavors. For example when buffered uart is created it calls configure
and then sets other registers that are needed for this driver:
embassy/embassy-stm32/src/usart/buffered.rs
Lines 233 to 241 in ca27590
configure(r, &config, T::frequency(), T::KIND, true, true)?; | |
r.cr1().modify(|w| { | |
#[cfg(lpuart_v2)] | |
w.set_fifoen(true); | |
w.set_rxneie(true); | |
w.set_idleie(true); | |
}); |
So putting it to confgure
is not a good place. I'll check if I can refactor it a little to remove copy-pasting.
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.
I cleaned it up a little by removing redundant w.set_fifoen(true);
which is set in configure
anyway.
There isn't a good place where to put those copy pasted lines without introducing more complexity.
configure
configures all the basic stuff which is used in all uart flavours and then extra configuration is done in buffered.rs
which is needed for this specific impl.
I would keep it as is without adding extra stuff to basic configuration.
Although I was thinking that maybe we can remove those self.set_config
functions altogether and only rely on SetConfig
trait as in here.
Then all the configuration related stuff is neatly together and there is less chance that somebody forgets to update something. However then again SetConfig
trait must be imported by the user which is inconvenient.
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.
oh okay! I had missed that, sounds good then! thanks :)
In reconfigure() cr1 register is initialised with write (not modify) which means rxneie and idleneie are disabled after reconfiguration.
ca27590
to
7f72dbd
Compare
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.
thank you!
CR1
UE
must be false when setting word length and parity bits.type ConfigError = ConfigError
instead oftype ConfigError = ()
fn configure()
which uses write to setCR1
. This disablesRXNEIE
andIDLEIE
inCR1
and those must be re-enabled again. Otherwise receive does not work anymore.TODO (done)
fifoen
, which one is correct?embassy/embassy-stm32/src/usart/mod.rs
Lines 998 to 999 in ca27590
vs
embassy/embassy-stm32/src/usart/buffered.rs
Lines 236 to 237 in ca27590
Edit:
usart_v4
is correct.TEST
Tested with stm32g081 by reconfiguring baudrate, parity and stop bits.