cancel
Showing results for 
Search instead for 
Did you mean: 

USB Mass storage class + SPI

TKou
Associate II

I've been working with USB Mass Storage Class to create an SD Card reader with STM32L1 using SPI.

I added the SDCard_SPI library and filled the missing functions in the "usbd_storage_if.c" file.

What I've got is that my project works fine with SD Cards that have the boot sector at the address 0.

But in other cases windows keeps sending commends repeatedly to read sector 0 and returns "please insert disk" error.

Is this a library limitation ? or should I add something to make windows recognize that the boot sector isn't at the address 0?

2 REPLIES 2

It should be able to find an MBR or BPB at Sector Zero. If it is not able to do so your implementation is broken.

Assume the media is formatted properly. Don't reformat it just because it complains. Use media you know is functional.

Validate the sector read/write functionality outside of the MSC context.

Windows has an expectation that your device works properly, and will fail when it does not.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
TKou
Associate II

I've been studying the difference between the SD Cards that function with the application and others that don't. I've found that SD Cards that function have the BPB at sector 0 and have no MBR, And their primary partition is not shifted.

Cards that have an MBR at sector 0, have a primary partition that is shifted. At the first sector of the partition there's the BPB that tells that the media is partitioned with a BPB_HiddSec != 0. In this case working with a STORAGE_LUN_NBR = 1 isn't compliant with what the BPB tells. ( I attached picture a showing more information about my cards)

Trying to change the STORAGE_LUN_NBR >1 and align the addressing to the start sector of the partition is not recommended and will lead to more complications on a lower level.

Another thing is that I found that media without MBR are somehow, somewhere considered broken, but in my case windows still can recognize them and I can still read and write properly to those cards.

The problem is still on ! 0690X00000BxAitQAF.png