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

Re-Init of SDIO Interface does not work #692

Open
Simsys opened this issue Nov 14, 2023 · 0 comments
Open

Re-Init of SDIO Interface does not work #692

Simsys opened this issue Nov 14, 2023 · 0 comments

Comments

@Simsys
Copy link

Simsys commented Nov 14, 2023

I would like to use SD cards in my project, which can also be changed during operation. To do this, it is necessary to reinitialize the SDIO peripherals. Unfortunately, this does not work. Based on the example sd.rs the following code:

#![no_main]
#![no_std]

use panic_rtt_target as _;
use rtt_target::{rprintln, rtt_init_print};

use cortex_m_rt::entry;
use stm32f4xx_hal::{
    pac,
    sdio::{ClockFreq, SdCard, Sdio},
    prelude::*,
};


#[entry]
fn main() -> ! {
    let device = pac::Peripherals::take().unwrap();
    let core = cortex_m::Peripherals::take().unwrap();

    let rcc = device.RCC.constrain();
    let clocks = rcc
        .cfgr
        .use_hse(12.MHz())
        .require_pll48clk()
        .sysclk(168.MHz())
        .hclk(168.MHz())
        .pclk1(42.MHz())
        .pclk2(84.MHz())
        .freeze();

    rtt_init_print!();

    let mut delay = core.SYST.delay(&clocks);

    let gpioc = device.GPIOC.split();
    let gpiod = device.GPIOD.split();

    let d0 = gpioc.pc8.internal_pull_up(true);
    let d1 = gpioc.pc9.internal_pull_up(true);
    let d2 = gpioc.pc10.internal_pull_up(true);
    let d3 = gpioc.pc11.internal_pull_up(true);
    let clk = gpioc.pc12;
    let cmd = gpiod.pd2.internal_pull_up(true);
    let mut sdio: Sdio<SdCard> = Sdio::new(device.SDIO, (clk, cmd, d0, d1, d2, d3), &clocks);

    loop {
        match sdio.init(ClockFreq::F24Mhz) {
            Ok(_) => {
                let nblocks = sdio.card().map(|c| c.block_count()).unwrap_or(0);
                rprintln!("Card detected, nbr of blocks: {:?}", nblocks);
            },
                Err(_err) => rprintln!("Init Error"),
        }
        delay.delay_ms(3000u32);
    }
}

The output is as follows. Replacing the SD card does not change anything.

Card detected: nbr of blocks: 1955840
Init Error
Init Error
Init Error
...
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

1 participant