Difference between revisions of "STM32 SD card"

From Stm32World Wiki
Jump to navigation Jump to search
(Created page with "Category:STM32Category:STM32 DevelopmentCategory:STM32 HALCategory:C{{metadesc|STM32 SD Card Interface}} thumb|200px In this article we will b...")
 
 
(25 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
[[Category:STM32]][[Category:STM32 Development]][[Category:STM32 HAL]][[Category:C]]{{metadesc|STM32 SD Card Interface}}
 
[[Category:STM32]][[Category:STM32 Development]][[Category:STM32 HAL]][[Category:C]]{{metadesc|STM32 SD Card Interface}}
[[File:sd1.jpg|thumb|200px]]
+
[[File:sd1.jpg|thumb|200px|Micro-SD Adaptor with jumper leads soldered on]]
 
In this article we will be interfacing a SD-card using [[STM32]].
 
In this article we will be interfacing a SD-card using [[STM32]].
 +
 +
For this purpose we have modified a SD to Micro-SD adaptor by soldering 9 jumper leads on it (see photo on the right).
 
{{clear}}
 
{{clear}}
 +
== SD-Card Pinout ==
 +
 +
The pinout of a SD-card and a MicroSD-card are as follows:
 +
 +
[[File:sd-card-pinout.png|500px]]
 +
 +
It is important to notice that all SD-cards can be interfaced in two different ways:
 +
 +
# [[#SDIO|SDIO]]
 +
# [[#SPI|SPI]]
 +
 +
== DIY SD-card Adaptor ==
 +
 +
A quick way to hook up a SD-card to a [[STM32]] is to use one of those SD to Micro-SD adaptors that come with most Micro-SD's when you buy them.  I made one looking like this:
 +
 +
[[File:Sd4.jpg|350px]]
 +
 +
Combining that with the pinout from the previous section, we can make the following table:
 +
 +
{| class="wikitable"
 +
|-
 +
!Pin
 +
!Color
 +
!SDIO
 +
!SPI
 +
|-
 +
| 1
 +
| White
 +
| CD/Dat3
 +
| CS
 +
|-
 +
| 2
 +
| Grey
 +
| CMD
 +
| DI
 +
|-
 +
| 3
 +
| Purple
 +
| VSS1
 +
| VSS1
 +
|-
 +
| 4
 +
| Blue
 +
| VDD
 +
| VDD
 +
|-
 +
| 5
 +
| Green
 +
| CLK
 +
| SCLK
 +
|-
 +
| 6
 +
| Yellow
 +
| VSS2
 +
| VSS2
 +
|-
 +
| 7
 +
| Orange
 +
| DAT0
 +
| DO
 +
|-
 +
| 8
 +
| Red
 +
| DAT1
 +
|
 +
|-
 +
| 9
 +
| Black
 +
| DAT2
 +
|
 +
|}
 +
 +
As per the SD-card specification in both the case of SPI and SDIO, all signals except the clock should be pulled up.  Our DIY adaptor does not include pull-up resistors, so we will have to rely on the internal ones, which are really quite weak but as long as the leads are not too long it should work ok.
 +
 +
== SPI ==
 +
 +
NOTICE!  While it is supported by most, some SD-cards do not support SPI access.  If this fails for you, try with another card.  Older cards are more likely to work.
 +
 +
== SDIO ==
 +
 +
=== 1-bit ===
 +
 +
=== 4-bit ===
 +
 
== Gallery ==
 
== Gallery ==
 +
 +
The following quick "hack" was soldered together and it works flawlessly.
  
 
<gallery>
 
<gallery>
Line 14: Line 102:
 
</gallery>
 
</gallery>
  
 +
== Miscellaneous Links ==
  
== Miscellaneous Links ==
+
* [https://01001000.xyz/2020-08-09-Tutorial-STM32CubeIDE-SD-card/ SPI SD Card Example]

Latest revision as of 08:32, 22 November 2024

Micro-SD Adaptor with jumper leads soldered on

In this article we will be interfacing a SD-card using STM32.

For this purpose we have modified a SD to Micro-SD adaptor by soldering 9 jumper leads on it (see photo on the right).

SD-Card Pinout

The pinout of a SD-card and a MicroSD-card are as follows:

Sd-card-pinout.png

It is important to notice that all SD-cards can be interfaced in two different ways:

  1. SDIO
  2. SPI

DIY SD-card Adaptor

A quick way to hook up a SD-card to a STM32 is to use one of those SD to Micro-SD adaptors that come with most Micro-SD's when you buy them. I made one looking like this:

Sd4.jpg

Combining that with the pinout from the previous section, we can make the following table:

Pin Color SDIO SPI
1 White CD/Dat3 CS
2 Grey CMD DI
3 Purple VSS1 VSS1
4 Blue VDD VDD
5 Green CLK SCLK
6 Yellow VSS2 VSS2
7 Orange DAT0 DO
8 Red DAT1
9 Black DAT2

As per the SD-card specification in both the case of SPI and SDIO, all signals except the clock should be pulled up. Our DIY adaptor does not include pull-up resistors, so we will have to rely on the internal ones, which are really quite weak but as long as the leads are not too long it should work ok.

SPI

NOTICE! While it is supported by most, some SD-cards do not support SPI access. If this fails for you, try with another card. Older cards are more likely to work.

SDIO

1-bit

4-bit

Gallery

The following quick "hack" was soldered together and it works flawlessly.

Miscellaneous Links