[Rust] Error Opening SD Card Volume: "Invalid MBR Signature"

Hello.

I’m writing simple programs for the PicoCalc using Rust. I’m trying to read the SD card with the following code [1], but it keeps failing with the following error [2]. I’m using the embedded-sdmmc crate.

Additionally, the card size is incorrect. The SD card that came with the kit reads as 32GB when connected to my laptop, but it’s only recognized as 8GB when I try to access it through the Rust program. I have already tried formatting the card (FAT32, MBR) and partitioning it with the official script from the ClockworkPi repo [3].

Any help would be appreciated. Thanks.

[1] Failing Code : clockworkpi-picocalc-rust/p2_spi_sdcard/src/main.rs at main · A-I-nstein/clockworkpi-picocalc-rust · GitHub

[2] Error:

Card Size: 8169455616
Could not open volume: FormatError("Invalid MBR signature")

[3] ClockworkPi SD Card Script: PicoCalc/wiki/How-to-Create-an-Official-PicoCalc-SD-Card.md at master · clockworkpi/PicoCalc · GitHub

Take a look at the “sdcard” branch at my repo. It only supports reading right now; I am still actively developing this. The initialisation code seems solid so far.

The interesting part about SD Cards is that you are inserting different hardware with each card and they are all not created equally even if they are following the same specifications.

PicoCalc Text Starter (on GitHub)

I have been using that SD card image during development of my FAT32 driver and I know the structure of that image at byte level. Please let me know how I can help.

Where in the embedded-sdmmc crate is it throwing that error?

Thanks. It’s on line 142. when I try to open the volume.

volume_mgr.open_volume(VolumeIdx(0))

I’m new to embedded development and I’ve been trying to get this to work for a few days now. Still having the same issues.

I’ve checked your repo and ensured that the pins are right. The only difference is the speed. I believe you’re using 25MHz. I’m initialising the card with 200kHz and then increasing it to 16MHz. I’ve also tried directly initialising with higher speed instead of starting slower. That doesn’t work as well.

Please let me know if you need any other details.

I am not sure why it is having a problem.

In the crate that you are using, you get this error if the signature for the MBR is not correct:

Which is the same check I do:

I stumbled upon someone else using this crate on a RP2040, perhaps how they initialize the SPI port might help:

Thanks. Looks like they are using a mutex wrap on the Spi and a critical section to increase to speed. Let me try that.

Okay. Unfortunately even the mutex and the critical section did not help. I think there could still be something wrong with how the SD Card is formatted and partitioned.

What do you think is the best way to format it? I’ve tried the windows formatter, the official tool from the SD Association and also the clockworkpi official linux script.

I reformatted the SD card that came with my PicoCalc with mkfs.fat on Debian (because I never bothered to implement support for long file names in zeptoforth), and haven’t had any problems with it. Note that I did not regenerate the partition table, so I am still using the stock partition table that came with the SD card from ClockworkPi.

My guess is that there is data corruption in the communication between the SD card and your board. In the case of zeptoforth, I send/receive dummy bytes in many places when communicating with the SD card, and previously had communication problems without the right number of dummy bytes.

Could be. And a few people I spoke to said that they’ve only used this crate with microSD cards and not full sized once. I should probably test that as well.