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

SPI master (spim) stops working after .free() #392

Open
eflukx opened this issue Jul 7, 2022 · 1 comment
Open

SPI master (spim) stops working after .free() #392

eflukx opened this issue Jul 7, 2022 · 1 comment

Comments

@eflukx
Copy link

eflukx commented Jul 7, 2022

Hi I'm building a battery-powered sensing device with Rust, based on the nRF52833.

For conserving power, I need to disable the SPI peripheral when not in use. Currently a nice solution for enabling/disabling peripherals is not provided in the nrf-hal (tracking #279), so for the moment I will be juggling the SPI in a wrapping enum encapsulating the enabled and disabled types/modes.

I ran into an unexpected problem though:

  • When initializing the SPI peripheral for the first time all works well!
  • After free()-ing the peripheral instance, the power usage drops as expected (side note: for anyone debugging inexplicable SPI power use, please be aware of: Erratum [195] SPIM: SPIM3 continues to draw current after disable)
  • The free'd parts (spim and spins) can be made into a new spi instance, also good...
  • But, this new resulting SPI instance does not seem to work at all/correctly. write() functions return without error, but nothing happens...

It seems something is not working well when creating the new spim instance from the parts returned by spidev.free()

Freeing and re-creating the SPI instance:

    let (spim, pins) = spidev.free();
    let mut spidev = spim::Spim::new(spim, pins, spim::Frequency::M16, spim::MODE_0, 0);

for completeness, initial initialization is done like this:

    let epd_mosi = port1.p1_06.into_push_pull_output(Level::Low).degrade();
    let epd_sck = port1.p1_07.into_push_pull_output(Level::Low).degrade();

    let mut epd_spi = spim::Spim::new(
        periphs.SPIM2,
        spim::Pins {
            sck: epd_sck,
            miso: None,
            mosi: Some(epd_mosi),
        },
        spim::Frequency::M16,
        spim::MODE_0,
        0,
    );
@jonas-schievink
Copy link
Contributor

Looks like we never reset the enable register in free, that might cause this.

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