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

Disabling Tx, Rx pins during Sleep #230

Open
sreyhani opened this issue Oct 28, 2023 · 3 comments
Open

Disabling Tx, Rx pins during Sleep #230

sreyhani opened this issue Oct 28, 2023 · 3 comments

Comments

@sreyhani
Copy link

I have a STM32L071CBTx which is connected to another board wia Uart. I want to put my mcu in sleep mode when the other board power is off. but tx pin takes heavy current from mcu in sleep mode. so I need to change it to Floating Input before stop mode and revert it after wakeup. but I don't have access to tx pin after initiating serial. is there a way to do this or another way to disable Uart temporarily?

@dbrgn
Copy link
Contributor

dbrgn commented Oct 30, 2023

Hmm, the LPUART1/2/3/4 peripheral can be released with Serial#release(): https://docs.rs/stm32l0xx-hal/latest/stm32l0xx_hal/serial/struct.Serial.html However, I think the RX and TX pins can't be released.

Maybe the release() method should be extended to return (LPUARTx, TX, RX) instead. Then you could destroy the Serial struct, reconfigure your pin, and after wakeup, reconfigure again and re-create the Serial instance.

(PRs welcome, if you can get it to work!)

@sreyhani
Copy link
Author

sreyhani commented Nov 1, 2023

Hmm, the LPUART1/2/3/4 peripheral can be released with Serial#release(): https://docs.rs/stm32l0xx-hal/latest/stm32l0xx_hal/serial/struct.Serial.html However, I think the RX and TX pins can't be released.

Maybe the release() method should be extended to return (LPUARTx, TX, RX) instead. Then you could destroy the Serial struct, reconfigure your pin, and after wakeup, reconfigure again and re-create the Serial instance.

(PRs welcome, if you can get it to work!)

it already has a split() method which gives back (Tx, Rx) but you can't call pin mode functions like into_floating_input() on TxPin , RxPin. USART constructor converts pins to TxPin and loses Pin functionalites after initiating serial

@sreyhani
Copy link
Author

sreyhani commented Nov 1, 2023

btw, i made it work with this ugly workaround. manually changing otyper register without altering pin AlternateFunction mode. no need to reconstruct serial

this could cause problems if you don't have the ownership of serial when you are calling these.

/// Changes TxPin Pin Mode From Open-Drain to Push-Pull
fn enable_tx(pin_number: u8) {
    unsafe {
        (*GPIOA::ptr())
            .otyper
            .modify(|r, w| w.bits(r.bits() & !(0b1 << pin_number) | (0_u32 << pin_number)));
    }
}

/// Changes TxPin Pin Mode From Push-Pull to Open-Drain
fn disable_tx(pin_number: u8) {
    unsafe {
        (*GPIOA::ptr())
            .otyper
            .modify(|r, w| w.bits(r.bits() & !(0b1 << pin_number) | (1_u32 << pin_number)));
    }
}

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