cancel
Showing results for 
Search instead for 
Did you mean: 

SPI2 On STM32F44RE not working with SD Card

bibble235
Associate III

Hi,

Have this working on STM32F302R8 but cannot seem to get my SD Card working on an STM32F446RE. Using hal 0.23.0 with stm32F446 and embedded-sdmm 0.9.0);

    let sd_mosi = gpiob.pb15.into_alternate::<5>();
    let sd_miso = gpiob.pb14.into_alternate::<5>();
    let sd_sck = gpiob.pb13.into_alternate::<5>();

    let mut sd_spi = Spi::new(
        dp.SPI2,
        (Some(sd_sck), Some(sd_miso), Some(sd_mosi)),
        Mode {
            polarity: Polarity::IdleLow,
            phase: Phase::CaptureOnFirstTransition,
        },
        400.kHz(),
        &mut rcc,
    );

    let sd_spi_dev = ExclusiveDevice::new_no_delay(sd_spi, sd_cs).unwrap();
    rprintln!("Reading file...");
    let num_bytes = sdcard.num_bytes().unwrap();
    rprintln!("SD Card Size: {} bytes", num_bytes);

Which gives

[2026-03-01T05:30:04.085Z, +020837ms] panicked at both_test/src/main.rs:184:40:
[2026-03-01T05:30:04.085Z, +020837ms] called `Result::unwrap()` on an `Err` value: CardNotFound

Very new to all this but certain of wiring. The SD Adaptor has an Ams117 chip but I have tried in 3.3V 5V, tried lower speeds, set CS high, etc with no joy. Added 4.7k pullup to CS.

I can move it back to F302R8 and it works straight away.

Thanks all

1 ACCEPTED SOLUTION

Accepted Solutions
bibble235
Associate III

Completely all my fault, probably been at it too long. When you set high and the Logic Analyzer says no, check the wiring. In fairness I am dyslexic but also a massive wally. Upside pinout Arrrrghhh. Still refreshed on my Logic Analyzer skills hahaha.

View solution in original post

3 REPLIES 3
Andrew Neil
Super User

Have you tried using any other SPI on the chip?

Have you looked at the SPI lines using an oscilloscope and/or logic analyser?

 

What programming language are you using - is that Rust ?

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

Tested with an ILI9341 on SPI1 and all good but no joy with SDMMC. Learning to use my scope and should get it out but figured working on my ESP32 and STM32F302R8 meant it probably was not the boards (I have 3 with ASM117, and built in one on the ILI module)

Currently working through STM32CubeMx through WSL as I no longer run Linux. Long time since I left C behind for Rust but nice seeing an old friend.

Thanks for replying and will feedback for others

bibble235
Associate III

Completely all my fault, probably been at it too long. When you set high and the Logic Analyzer says no, check the wiring. In fairness I am dyslexic but also a massive wally. Upside pinout Arrrrghhh. Still refreshed on my Logic Analyzer skills hahaha.