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

Release Rx, Tx resource back to Pin #748

Closed
lgjonathan opened this issue Mar 11, 2024 · 2 comments
Closed

Release Rx, Tx resource back to Pin #748

lgjonathan opened this issue Mar 11, 2024 · 2 comments

Comments

@lgjonathan
Copy link

Hi,
I have a use case that I need to send a pulse with UART before communicating.
So my approach was to call set_high, set_low and delay to send a pulse.

But once the USART consumes the pin, I couldn't release the pin back to output pin.
From what I see, Serial::new() and Serial::release() is not bidirectional because Tx takes the ownership of the underlying pin.

I was wondering if there's a way to release Tx back to Pin?
(so I can call into_push_pull_output)

Thanks in advance

@burrbull
Copy link
Contributor

burrbull commented Mar 11, 2024

You just need to unwrap Tx pin enum. https://docs.rs/stm32f4xx-hal/latest/stm32f4xx_hal/gpio/alt/usart1/enum.Tx.html#impl-TryFrom%3CTx%3COtype%3E%3E-for-Pin%3C'A',+9,+MODE%3E

let (usart, (txpin, rxpin)) = serial.release();
let txpin: gpio::PA9<Output> = txpin.try_into().unwrap(); // Now it is already in `Output<PushPull>>`

@lgjonathan
Copy link
Author

Works! Much thanks

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

No branches or pull requests

2 participants